@@ -264,6 +264,74 @@ ContentNodeKit CreateKit(int id, int parentId, int sortOrder)
264264 yield return CreateKit ( 12 , 4 , 2 ) ;
265265 }
266266
267+ private IEnumerable < ContentNodeKit > GetVariantWithDraftKits ( )
268+ {
269+ var paths = new Dictionary < int , string > { { - 1 , "-1" } } ;
270+
271+ Dictionary < string , CultureVariation > GetCultureInfos ( int id , DateTime now )
272+ {
273+ var en = new [ ] { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 } ;
274+ var fr = new [ ] { 1 , 3 , 4 , 6 , 7 , 9 , 10 , 12 } ;
275+
276+ var infos = new Dictionary < string , CultureVariation > ( ) ;
277+ if ( en . Contains ( id ) )
278+ infos [ "en-US" ] = new CultureVariation { Name = "N" + id + "-" + "en-US" , Date = now , IsDraft = false } ;
279+ if ( fr . Contains ( id ) )
280+ infos [ "fr-FR" ] = new CultureVariation { Name = "N" + id + "-" + "fr-FR" , Date = now , IsDraft = false } ;
281+ return infos ;
282+ }
283+
284+ ContentNodeKit CreateKit ( int id , int parentId , int sortOrder )
285+ {
286+ if ( ! paths . TryGetValue ( parentId , out var parentPath ) )
287+ throw new Exception ( "Unknown parent." ) ;
288+
289+ var path = paths [ id ] = parentPath + "," + id ;
290+ var level = path . Count ( x => x == ',' ) ;
291+ var now = DateTime . Now ;
292+
293+ ContentData CreateContentData ( bool published ) => new ContentData
294+ {
295+ Name = "N" + id ,
296+ Published = published ,
297+ TemplateId = 0 ,
298+ VersionId = 1 ,
299+ VersionDate = now ,
300+ WriterId = 0 ,
301+ Properties = new Dictionary < string , PropertyData [ ] > ( ) ,
302+ CultureInfos = GetCultureInfos ( id , now )
303+ } ;
304+
305+ var withDraft = id % 2 == 0 ;
306+ var withPublished = ! withDraft ;
307+
308+ return new ContentNodeKit
309+ {
310+ ContentTypeId = _contentTypeVariant . Id ,
311+ Node = new ContentNode ( id , Guid . NewGuid ( ) , level , path , sortOrder , parentId , DateTime . Now , 0 ) ,
312+ DraftData = withDraft ? CreateContentData ( false ) : null ,
313+ PublishedData = withPublished ? CreateContentData ( true ) : null
314+ } ;
315+ }
316+
317+ yield return CreateKit ( 1 , - 1 , 1 ) ;
318+ yield return CreateKit ( 2 , - 1 , 2 ) ;
319+ yield return CreateKit ( 3 , - 1 , 3 ) ;
320+
321+ yield return CreateKit ( 4 , 1 , 1 ) ;
322+ yield return CreateKit ( 5 , 1 , 2 ) ;
323+ yield return CreateKit ( 6 , 1 , 3 ) ;
324+
325+ yield return CreateKit ( 7 , 2 , 3 ) ;
326+ yield return CreateKit ( 8 , 2 , 2 ) ;
327+ yield return CreateKit ( 9 , 2 , 1 ) ;
328+
329+ yield return CreateKit ( 10 , 3 , 1 ) ;
330+
331+ yield return CreateKit ( 11 , 4 , 1 ) ;
332+ yield return CreateKit ( 12 , 4 , 2 ) ;
333+ }
334+
267335 [ Test ]
268336 public void EmptyTest ( )
269337 {
@@ -747,6 +815,25 @@ public void UpdateTest()
747815 AssertDocuments ( documents , "N9" , "N8" , "N7" ) ;
748816 }
749817
818+ [ Test ]
819+ public void AtRootTest ( )
820+ {
821+ Init ( GetVariantWithDraftKits ( ) ) ;
822+
823+ var snapshot = _snapshotService . CreatePublishedSnapshot ( previewToken : null ) ;
824+ _snapshotAccessor . PublishedSnapshot = snapshot ;
825+
826+ _variationAccesor . VariationContext = new VariationContext ( "en-US" ) ;
827+
828+ // N2 is draft only
829+
830+ var documents = snapshot . Content . GetAtRoot ( ) . ToArray ( ) ;
831+ AssertDocuments ( documents , "N1-en-US" , /*"N2-en-US",*/ "N3-en-US" ) ;
832+
833+ documents = snapshot . Content . GetAtRoot ( true ) . ToArray ( ) ;
834+ AssertDocuments ( documents , "N1-en-US" , "N2-en-US" , "N3-en-US" ) ;
835+ }
836+
750837 private void AssertDocuments ( IPublishedContent [ ] documents , params string [ ] names )
751838 {
752839 Assert . AreEqual ( names . Length , documents . Length ) ;
0 commit comments