File tree Expand file tree Collapse file tree
SenseNet.Client.Tests/UnitTests Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ]
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments