Skip to content

Commit 6a817ec

Browse files
committed
Fix content type double registration.
1 parent 9c3ae6f commit 6a817ec

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/SenseNet.Client.Tests/UnitTests/RepositoryTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ namespace SenseNet.Client.Tests.UnitTests
2121
[TestClass]
2222
public class RepositoryTests : TestBase
2323
{
24+
#region Test classes
25+
public class File : Content
26+
{
27+
public File(IRestCaller restCaller, ILogger<Content> logger) : base(restCaller, logger) { }
28+
}
29+
#endregion
30+
2431
private const string ExampleUrl = "https://example.com";
2532

2633
[TestMethod]
@@ -1085,6 +1092,26 @@ public async Task Repository_T_RegisterContentTypes_DifferentTypeSameName()
10851092
Assert.IsNotNull(services.GetService<DifferentNamespace.MyContent>());
10861093
}
10871094

1095+
[TestMethod]
1096+
public async Task Repository_T_RegisterGlobalContentType_OverrideExisting()
1097+
{
1098+
// ACTION
1099+
var repositories = GetRepositoryCollection(services =>
1100+
{
1101+
services.RegisterGlobalContentType(typeof(DownloadTests.File));
1102+
1103+
// override the registration above
1104+
services.RegisterGlobalContentType(typeof(File));
1105+
});
1106+
1107+
// ASSERT
1108+
var repository = await repositories.GetRepositoryAsync(CancellationToken.None)
1109+
.ConfigureAwait(false);
1110+
repository.GlobalContentTypes.ContentTypes.TryGetValue("File", out var contentType);
1111+
Assert.IsNotNull(contentType);
1112+
Assert.AreEqual(typeof(File), contentType);
1113+
}
1114+
10881115
/* =================================================================== CREATE REGISTERED CONTENT */
10891116

10901117
[TestMethod]

src/SenseNet.Client/RepositoryExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static IServiceCollection RegisterGlobalContentType(this IServiceCollecti
108108
services.AddTransient(contentType, contentType);
109109
services.Configure<RegisteredContentTypes>(contentTypes =>
110110
{
111-
contentTypes.ContentTypes.Add(contentTypeName ?? contentType.Name, contentType);
111+
contentTypes.Add(contentType, contentTypeName);
112112
});
113113
return services;
114114
}
@@ -124,7 +124,7 @@ public static IServiceCollection RegisterGlobalContentType<T>(this IServiceColle
124124
services.AddTransient<T, T>();
125125
services.Configure<RegisteredContentTypes>(contentTypes =>
126126
{
127-
contentTypes.ContentTypes.Add(contentTypeName ?? typeof(T).Name, typeof(T));
127+
contentTypes.Add<T>(contentTypeName);
128128
});
129129
return services;
130130
}

0 commit comments

Comments
 (0)