Skip to content

Commit

Permalink
Create new File, Image, User content types (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcll authored Sep 29, 2023
1 parent e55d442 commit 011d740
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 5 deletions.
61 changes: 58 additions & 3 deletions src/SenseNet.Client.Tests/UnitTests/RepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"": ""[email protected]"",
""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<User>("/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("[email protected]", 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()
{
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/SenseNet.Client/ContentTypes/File.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.Logging;

// ReSharper disable once CheckNamespace
namespace SenseNet.Client
{
/// <summary>
/// Represents a file in the sensenet repository.
/// </summary>
public class File : Content
{
public File(IRestCaller restCaller, ILogger<File> logger) : base(restCaller, logger)
{
}
}
}
20 changes: 20 additions & 0 deletions src/SenseNet.Client/ContentTypes/Image.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.Logging;
using System;

// ReSharper disable once CheckNamespace
namespace SenseNet.Client
{
/// <summary>
/// Represents an image in the sensenet repository.
/// </summary>
public class Image : File
{
public int Width { get; set; }
public int Height { get; set; }
public DateTime DateTaken { get; set; }

public Image(IRestCaller restCaller, ILogger<Image> logger) : base(restCaller, logger)
{
}
}
}
42 changes: 42 additions & 0 deletions src/SenseNet.Client/ContentTypes/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.Extensions.Logging;
using System;

// ReSharper disable once CheckNamespace
namespace SenseNet.Client
{
/// <summary>
/// Represents a user in the sensenet repository.
/// </summary>
public class User : Content
{
public User(IRestCaller restCaller, ILogger<Content> 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; }
}
}
4 changes: 2 additions & 2 deletions src/SenseNet.Client/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/SenseNet.Client/RepositoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public static IServiceCollection AddSenseNetClient(this IServiceCollection servi
.AddTransient<IRestCaller, DefaultRestCaller>()
.AddTransient<IRepository, Repository>()
.AddTransient<Content, Content>()
.RegisterGlobalContentType<File>()
.RegisterGlobalContentType<Image>()
.RegisterGlobalContentType<User>()
.AddSenseNetRetrier()
.AddLogging()
.Configure<ServerContextOptions>(_ => { });
Expand Down

0 comments on commit 011d740

Please sign in to comment.