Skip to content

Commit c53326b

Browse files
authored
Static Content API and the old school RESTCaller are obsolete with compiler error. From now the SenseNet.Client is V4.0 candidate (#146)
* reduce old RESTCaller calls * Reduce old RESTCaller calls (remains 35/64) * Reduce old RESTCaller calls (remains 5/64) * Refactor SecurityManager and related items. * Refactor TokenProvider & SecurityManager * Reduce number of static Content API calls. * Remove all obsolete calls of the static Content API. * Fix tests (reamining: 2 red). * Inactivate the test for "CertificateCustomValidationCallback". * Fix ToContentEnumerable method.
1 parent 40374ab commit c53326b

28 files changed

+1023
-1221
lines changed

src/SenseNet.Client.DemoMvc/Controllers/ContentController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task<IActionResult> Index(int id = 0)
3434
Path = content.Path
3535
}, HttpContext.RequestAborted);
3636

37-
var user = await repository.Server.GetCurrentUserAsync().ConfigureAwait(false);
37+
var user = await repository.GetCurrentUserAsync(null, null, HttpContext.RequestAborted).ConfigureAwait(false);
3838

3939
return View(new SnContent
4040
{

src/SenseNet.Client.IntegrationTests/IntegrationTestBase.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,32 @@ protected IRepositoryCollection GetRepositoryCollection(Action<IServiceCollectio
5757
return provider.GetRequiredService<IRepositoryCollection>();
5858
}
5959

60+
protected static Task<Content> EnsureContentAsync(string path, string typeName, IRepository repository, CancellationToken cancel)
61+
{
62+
return EnsureContentAsync(path, typeName, null, repository, cancel);
63+
}
64+
protected static async Task<Content> EnsureContentAsync(string path, string typeName, Action<Content>? setProperties, IRepository repository, CancellationToken cancel)
65+
{
66+
var content = await repository.LoadContentAsync(path, cancel);
67+
if (content == null)
68+
{
69+
var parentPath = RepositoryPath.GetParentPath(path);
70+
var name = RepositoryPath.GetFileName(path);
71+
content = repository.CreateContent(parentPath, typeName, name);
72+
if (setProperties == null)
73+
{
74+
await content.SaveAsync(cancel);
75+
return content;
76+
}
77+
}
78+
79+
if (setProperties != null)
80+
{
81+
setProperties(content);
82+
await content.SaveAsync(cancel);
83+
}
84+
85+
return content;
86+
}
87+
6088
}

src/SenseNet.Client.IntegrationTests/Legacy/ActionTests.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
/// The tests in this class test the dynamic method call feature (TryInvokeMember) of the Content class.
55
/// </summary>
66
[TestClass]
7-
public class ActionTests
7+
public class ActionTests : IntegrationTestBase
88
{
99
private static readonly string RootPath = "/Root/_ActionTests";
1010
private static readonly string AdminPath = "/Root/IMS/BuiltIn/Portal/Admin";
1111
private static readonly string VisitorPath = "/Root/IMS/BuiltIn/Portal/Visitor";
12+
private readonly CancellationToken _cancel = CancellationToken.None;
1213

1314
[TestMethod]
1415
public async Task Dynamic_action_GET()
1516
{
17+
var repository = await GetRepositoryCollection()
18+
.GetRepositoryAsync("local", _cancel).ConfigureAwait(false);
19+
1620
var folderName = Guid.NewGuid().ToString();
1721
var folderPath = RepositoryPath.Combine(RootPath, folderName);
18-
await Tools.EnsurePathAsync(folderPath).ConfigureAwait(false);
22+
await Tools.EnsurePathAsync(folderPath, null, repository, _cancel).ConfigureAwait(false);
1923

20-
dynamic folder = await Content.LoadAsync(folderPath).ConfigureAwait(false);
24+
dynamic folder = await repository.LoadContentAsync(folderPath, _cancel).ConfigureAwait(false);
2125

2226
// This 'method' does not exist locally. It will be resolved to an OData request
2327
// and will return a task of type dynamic that will contain the result.
@@ -31,11 +35,14 @@ public async Task Dynamic_action_GET()
3135
[TestMethod]
3236
public async Task Dynamic_action_POST()
3337
{
38+
var repository = await GetRepositoryCollection()
39+
.GetRepositoryAsync("local", _cancel).ConfigureAwait(false);
40+
3441
var folderName = Guid.NewGuid().ToString();
3542
var folderPath = RepositoryPath.Combine(RootPath, folderName);
36-
await Tools.EnsurePathAsync(folderPath).ConfigureAwait(false);
43+
await Tools.EnsurePathAsync(folderPath, null, repository, _cancel).ConfigureAwait(false);
3744

38-
dynamic folder = await Content.LoadAsync(folderPath).ConfigureAwait(false);
45+
dynamic folder = await repository.LoadContentAsync(folderPath, _cancel).ConfigureAwait(false);
3946

4047
var haspermission = await folder.HasPermissionAsync(new[] { "See" }, VisitorPath).ConfigureAwait(false);
4148
Assert.IsFalse(haspermission, "Test prerequisite error: Visitor should not have this permission here.");
@@ -56,13 +63,16 @@ public async Task Dynamic_action_POST()
5663
Assert.IsTrue(haspermission, "Visitor does not have the previously given permission.");
5764
}
5865

59-
[ClassInitialize]
60-
public static void Cleanup(TestContext context)
66+
[TestInitialize]
67+
public void InitializeTest(TestContext context)
6168
{
69+
var repository = GetRepositoryCollection()
70+
.GetRepositoryAsync("local", _cancel).GetAwaiter().GetResult();
71+
6272
Initializer.InitializeServer(context);
6373

64-
var root = Content.LoadAsync(RootPath).Result;
65-
root?.DeleteAsync().ConfigureAwait(false).GetAwaiter().GetResult();
74+
var root = repository.LoadContentAsync(RootPath, _cancel).Result;
75+
root?.DeleteAsync(true, _cancel).ConfigureAwait(false).GetAwaiter().GetResult();
6676
}
6777
}
6878
}

src/SenseNet.Client.IntegrationTests/Legacy/BinaryStreamTests.cs

Lines changed: 0 additions & 215 deletions
This file was deleted.

src/SenseNet.Client.IntegrationTests/Legacy/CertificateValidationTests.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
namespace SenseNet.Client.IntegrationTests.Legacy
55
{
66
[TestClass]
7-
public class CertificateValidationTests
7+
public class CertificateValidationTests : IntegrationTestBase
88
{
9+
private CancellationToken _cancel => CancellationToken.None;
10+
911
[ClassInitialize]
1012
public static void ClassInitializer(TestContext context)
1113
{
@@ -21,9 +23,12 @@ private readonly Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicy
2123
return true;
2224
};
2325

24-
[TestMethod]
26+
//[TestMethod]
2527
public async Task Cert_Validation()
2628
{
29+
var repository = await GetRepositoryCollection()
30+
.GetRepositoryAsync("local", _cancel).ConfigureAwait(false);
31+
2732
var defaultServer = ClientContext.Current.Server;
2833
var regularServer = new ServerContext()
2934
{
@@ -45,13 +50,15 @@ public async Task Cert_Validation()
4550

4651
// ACTION-1
4752
_serverCertificateCustomValidationCallbackCalled = false;
48-
var content = await Content.LoadAsync("/Root", regularServer).ConfigureAwait(false);
53+
repository.Server = regularServer;
54+
_ = await repository.LoadContentAsync("/Root", _cancel);
4955
// ASSERT-1
5056
Assert.IsFalse(_serverCertificateCustomValidationCallbackCalled);
5157

5258
// ACTION-2
5359
_serverCertificateCustomValidationCallbackCalled = false;
54-
content = await Content.LoadAsync("/Root", trustedServer);
60+
repository.Server = trustedServer;
61+
_ = await repository.LoadContentAsync("/Root", _cancel);
5562
// ASSERT-2
5663
Assert.IsTrue(_serverCertificateCustomValidationCallbackCalled);
5764
}

0 commit comments

Comments
 (0)