@@ -37,7 +37,7 @@ public async Task Content_T_SaveFirst_Dynamic_AddProperty()
3737 {
3838 services . AddSingleton ( restCaller ) ;
3939 } ) ;
40- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
40+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
4141 . ConfigureAwait ( false ) ;
4242
4343 // ACT
@@ -84,7 +84,7 @@ public async Task Content_T_SaveFirst_Custom_SetProperty()
8484 services . RegisterGlobalContentType < TestContent_A > ( ) ;
8585 services . AddSingleton ( restCaller ) ;
8686 } ) ;
87- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
87+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
8888 . ConfigureAwait ( false ) ;
8989
9090 // ACT
@@ -131,7 +131,7 @@ public async Task Content_T_SaveFirst_Custom_AddAndSetProperty()
131131 services . RegisterGlobalContentType < TestContent_A > ( ) ;
132132 services . AddSingleton ( restCaller ) ;
133133 } ) ;
134- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
134+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
135135 . ConfigureAwait ( false ) ;
136136
137137 // ACT
@@ -233,7 +233,7 @@ private async Task<IDictionary<string, object>> UpdateBaseTypeTest(Action<dynami
233233 {
234234 services . AddSingleton ( restCaller ) ;
235235 } ) ;
236- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
236+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
237237 . ConfigureAwait ( false ) ;
238238
239239 // ACT-1: Load
@@ -341,7 +341,7 @@ private async Task<IDictionary<string, object>> UpdateStronglyTypedTest<T>(Actio
341341 services . RegisterGlobalContentType < T > ( ) ;
342342 services . AddSingleton ( restCaller ) ;
343343 } ) ;
344- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
344+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
345345 . ConfigureAwait ( false ) ;
346346
347347 // ACT-1: Load
@@ -467,7 +467,7 @@ public async Task Content_T_StronglyTyped_UpdateCustomProperties()
467467 services . RegisterGlobalContentType < TestContent_CustomProperties > ( ) ;
468468 services . AddSingleton ( restCaller ) ;
469469 } ) ;
470- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
470+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
471471 . ConfigureAwait ( false ) ;
472472
473473 // ACT-1 Load
@@ -532,7 +532,7 @@ public async Task Content_T_StronglyTyped_UpdateCustomProperties_OnlyChanged()
532532 services . RegisterGlobalContentType < TestContent_CustomProperties > ( ) ;
533533 services . AddSingleton ( restCaller ) ;
534534 } ) ;
535- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
535+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
536536 . ConfigureAwait ( false ) ;
537537
538538 // ACT-1 Load
@@ -613,7 +613,7 @@ public async Task Content_T_StronglyTyped_References_SaveFirst()
613613 services . RegisterGlobalContentType < TestContent_References > ( ) ;
614614 services . AddSingleton ( restCaller ) ;
615615 } ) ;
616- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
616+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
617617 . ConfigureAwait ( false ) ;
618618
619619 var contents = new Content [ 7 ] ;
@@ -712,7 +712,7 @@ public async Task Content_T_StronglyTyped_References_Update()
712712 services . RegisterGlobalContentType < TestContent_References > ( ) ;
713713 services . AddSingleton ( restCaller ) ;
714714 } ) ;
715- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
715+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
716716 . ConfigureAwait ( false ) ;
717717
718718 var contents = new Content [ 7 ] ;
@@ -799,7 +799,7 @@ public async Task Content_T_StronglyTyped_References_Update_Null()
799799 services . RegisterGlobalContentType < TestContent_References > ( ) ;
800800 services . AddSingleton ( restCaller ) ;
801801 } ) ;
802- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
802+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
803803 . ConfigureAwait ( false ) ;
804804
805805 var contents = new Content [ 7 ] ;
@@ -862,6 +862,91 @@ public async Task Content_T_StronglyTyped_References_Update_Null()
862862 "\" References_WellKnownArray\" :null," +
863863 "\" References_WellKnownList\" :[400006,\" /Root/Refs2/ReferredContent-7\" ]}" , JsonHelper . Serialize ( data ) ) ;
864864 }
865+ [ TestMethod ]
866+ public async Task Content_T_StronglyTyped_References_Update_NullToNull ( )
867+ {
868+ var restCaller = CreateRestCallerFor ( @"{
869+ ""d"": {
870+ ""Id"": 899612,
871+ ""Reference_Content"": null,
872+ ""References_ContentArray"": null,
873+ ""References_ContentEnumerable"": null,
874+ ""References_ContentList"": null,
875+ ""Reference_WellKnown"": null,
876+ ""References_WellKnownArray"": null,
877+ ""References_WellKnownEnumerable"": null,
878+ ""References_WellKnownList"": null,
879+ }
880+ }
881+ " ) ;
882+
883+ var repositories = GetRepositoryCollection ( services =>
884+ {
885+ services . RegisterGlobalContentType < ReferredContent > ( ) ;
886+ services . RegisterGlobalContentType < TestContent_References > ( ) ;
887+ services . AddSingleton ( restCaller ) ;
888+ } ) ;
889+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
890+ . ConfigureAwait ( false ) ;
891+
892+ var contents = new Content [ 7 ] ;
893+ for ( int i = 0 ; i < contents . Length ; i ++ )
894+ {
895+ contents [ i ] = new Content ( null , null )
896+ {
897+ Id = i % 2 == 0 ? 300001 + i : 0 ,
898+ Name = $ "Content-{ i + 1 } ",
899+ Path = $ "/Root/Refs2/Content-{ i + 1 } ",
900+ ParentId = 100000 ,
901+ ParentPath = "/Root/Refs2" ,
902+ Repository = repository ,
903+ Server = repository . Server
904+ } ;
905+ }
906+ var referredContents = new ReferredContent [ 7 ] ;
907+ for ( int i = 0 ; i < contents . Length ; i ++ )
908+ {
909+ referredContents [ i ] = new ReferredContent ( null , null )
910+ {
911+ Id = i % 2 == 1 ? 400001 + i : 0 ,
912+ Name = $ "ReferredContent-{ i + 1 } ",
913+ Path = $ "/Root/Refs2/ReferredContent-{ i + 1 } ",
914+ ParentId = 100000 ,
915+ ParentPath = "/Root/Refs2" ,
916+ Repository = repository ,
917+ Server = repository . Server
918+ } ;
919+ }
920+ var request = new LoadContentRequest { ContentId = 999543 , Select = new [ ] { "Id" , "Name" , "Path" , "Type" , "Index" } } ;
921+ dynamic content = await repository . LoadContentAsync < TestContent_References > ( request , CancellationToken . None ) ;
922+
923+ // ACT
924+ content . Reference_Content = null ;
925+ content . References_ContentEnumerable = new [ ] { contents [ 3 ] , null } ;
926+ content . References_WellKnownArray = new ReferredContent ? [ ] { null , null } ;
927+ content . References_WellKnownList = new List < ReferredContent > { referredContents [ 5 ] , referredContents [ 6 ] } ;
928+ await content . SaveAsync ( ) . ConfigureAwait ( false ) ;
929+
930+ // ASSERT
931+ var calls = restCaller . ReceivedCalls ( ) . ToArray ( ) ;
932+ Assert . IsNotNull ( calls ) ;
933+ Assert . AreEqual ( 3 , calls . Length ) ;
934+ Assert . AreEqual ( "GetResponseStringAsync" , calls [ 2 ] . GetMethodInfo ( ) . Name ) ;
935+ var arguments = calls [ 2 ] . GetArguments ( ) ;
936+ Assert . IsTrue ( arguments [ 0 ] . ToString ( ) . Contains ( "content(899612)" ) ) ;
937+ Assert . AreEqual ( HttpMethod . Patch , arguments [ 1 ] ) ;
938+ var json = ( string ) arguments [ 2 ] ! ;
939+ json = json . Substring ( "models=[" . Length ) . TrimEnd ( ']' ) ;
940+ JObject data = JsonHelper . Deserialize ( json ) ;
941+ var fields = data . ToObject < Dictionary < string , object > > ( ) ;
942+
943+ var names = string . Join ( ", " , fields . Keys . OrderBy ( x => x ) ) ;
944+ Assert . AreEqual ( "Name, References_ContentEnumerable, References_WellKnownList" , names ) ;
945+ Assert . IsNotNull ( data ) ;
946+ Assert . AreEqual ( "{\" Name\" :null," +
947+ "\" References_ContentEnumerable\" :[\" /Root/Refs2/Content-4\" ]," +
948+ "\" References_WellKnownList\" :[400006,\" /Root/Refs2/ReferredContent-7\" ]}" , JsonHelper . Serialize ( data ) ) ;
949+ }
865950
866951 [ TestMethod ]
867952 public async Task Content_T_StronglyTyped_References_Error_Content ( )
@@ -959,7 +1044,7 @@ private async Task TestStronglyTypedReferencesError(string fieldName, Action<Tes
9591044 services . RegisterGlobalContentType < TestContent_References > ( ) ;
9601045 services . AddSingleton ( restCaller ) ;
9611046 } ) ;
962- var repository = await repositories . GetRepositoryAsync ( "local" , CancellationToken . None )
1047+ var repository = await repositories . GetRepositoryAsync ( FakeServer , CancellationToken . None )
9631048 . ConfigureAwait ( false ) ;
9641049
9651050 var request = new LoadContentRequest { ContentId = 999999 } ;
0 commit comments