From 64b6c8a47e3fba9bebce67f0a9365539e642f650 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:04:55 +0200 Subject: [PATCH] V15: Adding unit tests for `INavigationQueryService.TryGetRootKeys()` (#17374) * Changing to Guid.NewGuid() * Adding unit tests for TryGetRootKeys --- .../ContentNavigationServiceBaseTests.cs | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentNavigationServiceBaseTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentNavigationServiceBaseTests.cs index 86b52e2618..f8d2274200 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentNavigationServiceBaseTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentNavigationServiceBaseTests.cs @@ -123,6 +123,59 @@ public class ContentNavigationServiceBaseTests }); } + [Test] + public void Cannot_Get_Root_Items_When_Empty_Tree() + { + // Arrange + var emptyNavigationService = new TestContentNavigationService( + Mock.Of(), + Mock.Of()); + + // Act + emptyNavigationService.TryGetRootKeys(out IEnumerable rootKeys); + List rootsList = rootKeys.ToList(); + + // Assert + Assert.IsEmpty(rootsList); + } + + [Test] + public void Can_Get_Single_Root_Item() + { + // Act + var result = _navigationService.TryGetRootKeys(out IEnumerable rootKeys); + List rootsList = rootKeys.ToList(); + + // Assert + Assert.Multiple(() => + { + Assert.IsTrue(result); + Assert.IsNotEmpty(rootsList); + Assert.AreEqual(1, rootsList.Count); + Assert.IsTrue(rootsList.Contains(Root)); + }); + } + + [Test] + public void Can_Get_Root_Item_In_Correct_Order() + { + // Arrange + Guid anotherRoot = Guid.NewGuid(); + _navigationService.Add(anotherRoot); + + // Act + var result = _navigationService.TryGetRootKeys(out IEnumerable rootKeys); + List rootsList = rootKeys.ToList(); + + // Assert + Assert.Multiple(() => + { + Assert.IsTrue(result); + Assert.AreEqual(2, rootsList.Count); + CollectionAssert.AreEqual(new[] { Root, anotherRoot }, rootsList); // Root and Another root in order + }); + } + [Test] public void Cannot_Get_Children_From_Non_Existing_Content_Key() { @@ -374,7 +427,7 @@ public class ContentNavigationServiceBaseTests public void Can_Get_Siblings_Of_Existing_Content_Key_At_Content_Root() { // Arrange - Guid anotherRoot = new Guid("716380B9-DAA9-4930-A461-95EF39EBAB41"); + Guid anotherRoot = Guid.NewGuid(); _navigationService.Add(anotherRoot); // Act