diff --git a/src/SenseNet.Client.Tests/UnitTests/RepositoryTests.cs b/src/SenseNet.Client.Tests/UnitTests/RepositoryTests.cs index f9fd4d5..85a32d0 100644 --- a/src/SenseNet.Client.Tests/UnitTests/RepositoryTests.cs +++ b/src/SenseNet.Client.Tests/UnitTests/RepositoryTests.cs @@ -988,6 +988,61 @@ public async Task Repository_T_RegisterGlobalContentType_TypeAndDifferentName() Assert.AreEqual(typeof(MyContent), contentType); } + [TestMethod] + public async Task Repository_T_RegisterGlobalContentType_BuiltIn_User() + { + // ALIGN + var restCaller = CreateRestCallerFor(@" +{ + ""d"": { + ""Id"": 1, + ""Path"": ""/Root/IMS/BuiltIn/Admin"", + ""Name"": ""Admin"", + ""Type"": ""User"", + ""LoginName"": ""admin"", + ""Email"": ""admin@example.com"", + ""BirthDate"": ""2000-02-03T00:00:00Z"", + ""Avatar"": { + ""Url"": ""/Root/Content/images/avatar.png"" + }, + ""ImageRef"": { + ""Id"": 123, + ""Path"": ""/Root/Content/images/avatar.png"", + ""Type"": ""Image"", + ""Name"": ""avatar.png"", + ""DateTaken"": ""2010-10-01T00:00:00Z"", + ""Width"": 456, + ""Height"": 789 + } + } +}"); + + var repositories = GetRepositoryCollection(services => + { + services.AddSingleton(restCaller); + }); + + var repository = await repositories.GetRepositoryAsync(FakeServer, CancellationToken.None) + .ConfigureAwait(false); + + // ACT + var user = await repository.LoadContentAsync("/testcontentpath", CancellationToken.None); + + // ASSERT + Assert.IsNotNull(user); + Assert.AreEqual(typeof(User), user.GetType()); + Assert.AreEqual("Admin", user.Name); + Assert.AreEqual("admin", user.LoginName); + Assert.AreEqual("admin@example.com", user.Email); + Assert.AreEqual(new DateTime(2000, 02, 03, 0, 0, 0, DateTimeKind.Utc), user.BirthDate); + + Assert.AreEqual(typeof(Image), user.ImageRef.GetType()); + Assert.AreEqual(123, user.ImageRef.Id); + Assert.AreEqual(456, user.ImageRef.Width); + Assert.AreEqual(789, user.ImageRef.Height); + Assert.AreEqual("/Root/Content/images/avatar.png", user.Avatar.Url); + } + [TestMethod] public async Task Repository_T_RegisterContentTypes() { @@ -1014,7 +1069,7 @@ public async Task Repository_T_RegisterContentTypes() var repositoryAcc = new ObjectAccessor(repository); var services = (IServiceProvider)repositoryAcc.GetField("_services"); Assert.AreEqual(ExampleUrl, repository.Server.Url); - Assert.AreEqual(0, repository.GlobalContentTypes.ContentTypes.Count); + Assert.AreEqual(3, repository.GlobalContentTypes.ContentTypes.Count); var contentTypeRegistrations = repository.Server.RegisteredContentTypes.ContentTypes .OrderBy(x => x.Value.Name) .ToArray(); @@ -1067,7 +1122,7 @@ public async Task Repository_T_RegisterContentTypes_DifferentTypeSameName() // ASSERT // check repo1 Assert.AreEqual(ExampleUrl, repository1.Server.Url); - Assert.AreEqual(0, repository1.GlobalContentTypes.ContentTypes.Count); + Assert.AreEqual(3, repository1.GlobalContentTypes.ContentTypes.Count); var contentTypeRegistrations1 = repository1.Server.RegisteredContentTypes.ContentTypes .OrderBy(x => x.Value.Name) .ToArray(); @@ -1077,7 +1132,7 @@ public async Task Repository_T_RegisterContentTypes_DifferentTypeSameName() // check repo2 Assert.AreEqual(exampleUrl2, repository2.Server.Url); - Assert.AreEqual(0, repository2.GlobalContentTypes.ContentTypes.Count); + Assert.AreEqual(3, repository2.GlobalContentTypes.ContentTypes.Count); var contentTypeRegistrations2 = repository2.Server.RegisteredContentTypes.ContentTypes .OrderBy(x => x.Value.Name) .ToArray(); diff --git a/src/SenseNet.Client/ContentTypes/File.cs b/src/SenseNet.Client/ContentTypes/File.cs new file mode 100644 index 0000000..472f1af --- /dev/null +++ b/src/SenseNet.Client/ContentTypes/File.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.Logging; + +// ReSharper disable once CheckNamespace +namespace SenseNet.Client +{ + /// + /// Represents a file in the sensenet repository. + /// + public class File : Content + { + public File(IRestCaller restCaller, ILogger logger) : base(restCaller, logger) + { + } + } +} \ No newline at end of file diff --git a/src/SenseNet.Client/ContentTypes/Image.cs b/src/SenseNet.Client/ContentTypes/Image.cs new file mode 100644 index 0000000..5ae494b --- /dev/null +++ b/src/SenseNet.Client/ContentTypes/Image.cs @@ -0,0 +1,20 @@ +using Microsoft.Extensions.Logging; +using System; + +// ReSharper disable once CheckNamespace +namespace SenseNet.Client +{ + /// + /// Represents an image in the sensenet repository. + /// + public class Image : File + { + public int Width { get; set; } + public int Height { get; set; } + public DateTime DateTaken { get; set; } + + public Image(IRestCaller restCaller, ILogger logger) : base(restCaller, logger) + { + } + } +} \ No newline at end of file diff --git a/src/SenseNet.Client/ContentTypes/User.cs b/src/SenseNet.Client/ContentTypes/User.cs new file mode 100644 index 0000000..9711ef9 --- /dev/null +++ b/src/SenseNet.Client/ContentTypes/User.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Logging; +using System; + +// ReSharper disable once CheckNamespace +namespace SenseNet.Client +{ + /// + /// Represents a user in the sensenet repository. + /// + public class User : Content + { + public User(IRestCaller restCaller, ILogger logger) : base(restCaller, logger) + { + } + + public string LoginName { get; set; } + public string DisplayName { get; set; } + public string JobTitle { get; set; } + public bool Enabled { get; set; } + public string Domain { get; set; } + public string Email { get; set; } + public string FullName { get; set; } + public Image ImageRef { get; set; } + public Avatar Avatar { get; set; } + public DateTime LastSync { get; set; } + public User Manager { get; set; } + public string Department { get; set; } + public string Languages { get; set; } + public string Phone { get; set; } + public DateTime BirthDate { get; set; } + public string TwitterAccount { get; set; } + public string FacebookURL { get; set; } + public string LinkedInURL { get; set; } + public string ProfilePath { get; set; } + public bool MultiFactorEnabled { get; set; } + } + + public class Avatar + { + public string Url { get; set; } + } +} \ No newline at end of file diff --git a/src/SenseNet.Client/Importer.cs b/src/SenseNet.Client/Importer.cs index 44827d2..c1b1c93 100644 --- a/src/SenseNet.Client/Importer.cs +++ b/src/SenseNet.Client/Importer.cs @@ -155,7 +155,7 @@ private async Task ImportInternal() if (string.IsNullOrEmpty(_sourcePath)) throw new InvalidOperationException("Empty source path."); - var isFile = File.Exists(_sourcePath); + var isFile = System.IO.File.Exists(_sourcePath); var isDirectory = Directory.Exists(_sourcePath); if (!isFile && !isDirectory) @@ -232,7 +232,7 @@ private async Task ImportDocumentAsync(string sourcePath, string targetPath) var parent = await Content.LoadAsync(targetPath).ConfigureAwait(false); Content file; - using (var fileStream = File.OpenRead(sourcePath)) + using (var fileStream = System.IO.File.OpenRead(sourcePath)) { // TODO: implement multiple target servers file = await Content.UploadAsync(parent.Id, name, fileStream, _options.FileTypeName).ConfigureAwait(false); diff --git a/src/SenseNet.Client/RepositoryExtensions.cs b/src/SenseNet.Client/RepositoryExtensions.cs index 829b236..1ef4902 100644 --- a/src/SenseNet.Client/RepositoryExtensions.cs +++ b/src/SenseNet.Client/RepositoryExtensions.cs @@ -45,6 +45,9 @@ public static IServiceCollection AddSenseNetClient(this IServiceCollection servi .AddTransient() .AddTransient() .AddTransient() + .RegisterGlobalContentType() + .RegisterGlobalContentType() + .RegisterGlobalContentType() .AddSenseNetRetrier() .AddLogging() .Configure(_ => { });