Fixes: Consistency for Nullable reference types in LINQ extensions methods #12692 (#12703)

* Ensure Name and Children can never return null.

* Name should be empty not null

* Ensure Name and Children type queries never return null

Co-authored-by: Sebastiaan Janssen <sebastiaan@umbraco.com>
This commit is contained in:
Dan Booth
2022-10-19 09:32:09 +01:00
committed by GitHub
parent 27e129a6b4
commit df19d4fc6d
8 changed files with 57 additions and 53 deletions

View File

@@ -719,25 +719,25 @@ public class PublishedSnapshotServiceCollectionTests : PublishedSnapshotServiceT
AssertDocuments(documents);
documents = snapshot.Content.GetById(1).Children(VariationContextAccessor, "*").ToArray();
AssertDocuments(documents, "N4-fr-FR", null, "N6-fr-FR");
AssertDocuments(documents, "N4-fr-FR", string.Empty, "N6-fr-FR");
AssertDocuments("en-US", documents, "N4-en-US", "N5-en-US", "N6-en-US");
documents = snapshot.Content.GetById(1).Children(VariationContextAccessor, "en-US").ToArray();
AssertDocuments(documents, "N4-fr-FR", null, "N6-fr-FR");
AssertDocuments(documents, "N4-fr-FR", string.Empty, "N6-fr-FR");
AssertDocuments("en-US", documents, "N4-en-US", "N5-en-US", "N6-en-US");
documents = snapshot.Content.GetById(1).ChildrenForAllCultures.ToArray();
AssertDocuments(documents, "N4-fr-FR", null, "N6-fr-FR");
AssertDocuments(documents, "N4-fr-FR", string.Empty, "N6-fr-FR");
AssertDocuments("en-US", documents, "N4-en-US", "N5-en-US", "N6-en-US");
documents = snapshot.Content.GetAtRoot("*").ToArray();
AssertDocuments(documents, "N1-fr-FR", null, "N3-fr-FR");
AssertDocuments(documents, "N1-fr-FR", string.Empty, "N3-fr-FR");
documents = snapshot.Content.GetById(1).DescendantsOrSelf(VariationContextAccessor).ToArray();
AssertDocuments(documents, "N1-fr-FR", "N4-fr-FR", "N12-fr-FR", "N6-fr-FR");
documents = snapshot.Content.GetById(1).DescendantsOrSelf(VariationContextAccessor, "*").ToArray();
AssertDocuments(documents, "N1-fr-FR", "N4-fr-FR", null /*11*/, "N12-fr-FR", null /*5*/, "N6-fr-FR");
AssertDocuments(documents, "N1-fr-FR", "N4-fr-FR", string.Empty /*11*/, "N12-fr-FR", string.Empty /*5*/, "N6-fr-FR");
}
[Test]

View File

@@ -120,7 +120,7 @@ public class PublishedSnapshotServiceContentTests : PublishedSnapshotServiceTest
Assert.AreEqual("val-fr1", publishedContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop", "fr-FR"));
Assert.AreEqual("val-uk1", publishedContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop", "en-UK"));
Assert.IsNull(publishedContent.Name(VariationContextAccessor)); // no invariant name for varying content
Assert.AreEqual(publishedContent.Name(VariationContextAccessor), string.Empty); // no invariant name for varying content
Assert.AreEqual("name-fr1", publishedContent.Name(VariationContextAccessor, "fr-FR"));
Assert.AreEqual("name-uk1", publishedContent.Name(VariationContextAccessor, "en-UK"));
@@ -129,7 +129,7 @@ public class PublishedSnapshotServiceContentTests : PublishedSnapshotServiceTest
Assert.AreEqual("val-fr2", draftContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop", "fr-FR"));
Assert.AreEqual("val-uk2", draftContent.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop", "en-UK"));
Assert.IsNull(draftContent.Name(VariationContextAccessor)); // no invariant name for varying content
Assert.AreEqual(draftContent.Name(VariationContextAccessor), string.Empty); // no invariant name for varying content
Assert.AreEqual("name-fr2", draftContent.Name(VariationContextAccessor, "fr-FR"));
Assert.AreEqual("name-uk2", draftContent.Name(VariationContextAccessor, "en-UK"));