public static bool Check <T>
        (
            CollectionPageData <T> expectedData,
            CollectionPageViewModel <T> actualViewModel,
            Func <T, T, bool> equal
        )
            where T : class, IEntity
        {
            var areEqual =
                false == actualViewModel.IsBusy &&
                expectedData.HasBackPages == actualViewModel.HasBackPages &&
                expectedData.HasForwardPages == actualViewModel.HasForwardPages &&
                expectedData.IsPaging == actualViewModel.IsPaging &&
                expectedData.PagingText == actualViewModel.PagingText;

            if (!areEqual)
            {
                return(false);
            }
            for (var i = 0; i < expectedData.Items.Count; i++)
            {
                if (!equal(expectedData.Items[i], actualViewModel.Items[i]))
                {
                    areEqual = false;
                    break;
                }
            }

            return(areEqual);
        }
Ejemplo n.º 2
0
 public static bool Check <T>
 (
     CollectionPageData <T> expected,
     ICollectionPageData <T> actual,
     Func <T, T, bool> equal
 )
 {
     return(CheckInternal(expected, actual as CollectionPageData <T>, equal));
 }
        public void NotPaging()
        {
            var items = new List <Uom>().ToImmutableList();
            var links = new PageLinksFormatter().GetLinks(Url, new Page <Uom>("", 40, 0, 50, new List <Uom>()));
            var data  = new CollectionPageData <Uom>(items, links);

            data.Links.TryGetValue(RelTypes.self, out var value);

            Assert.IsFalse(data.IsPaging);
            Assert.AreEqual(1, data.Links.Count);
            Assert.NotNull(value);
            Assert.AreEqual($"{Url}?searchText=&skip=0&take=50", value);
        }
Ejemplo n.º 4
0
        private static bool CheckInternal <T>
        (
            CollectionPageData <T> expected,
            CollectionPageData <T> actual,
            Func <T, T, bool> equal
        )
        {
            var areEqual =
                expected.HasBackPages == actual.HasBackPages &&
                expected.HasForwardPages == actual.HasForwardPages &&
                expected.IsPaging == actual.IsPaging &&
                expected.PagingText == actual.PagingText &&
                expected.Items.Count == actual.Items.Count &&
                expected.Links.Count == actual.Links.Count;

            if (!areEqual)
            {
                return(false);
            }
            foreach (var link in expected.Links)
            {
                actual.Links.TryGetValue(link.Key, out var url);
                if (link.Value != url)
                {
                    areEqual = false;
                    break;
                }
            }

            if (!areEqual)
            {
                return(false);
            }
            for (var i = 0; i < expected.Items.Count; i++)
            {
                if (!equal(expected.Items[i], actual.Items[i]))
                {
                    areEqual = false;
                    break;
                }
            }
            return(areEqual);
        }
        public void OnFirstPage()
        {
            var items = new List <Uom>().ToImmutableList();
            var links = new PageLinksFormatter().GetLinks(Url, new Page <Uom>("", 200, 0, 50, new List <Uom>()));
            var expectedPagingText = PagingTextCalculator.Calculate(0, 50, 200);
            var data = new CollectionPageData <Uom>(items, links);

            Assert.IsTrue(data.IsPaging);
            Assert.AreEqual(4, data.Links.Count);

            data.Links.TryGetValue(RelTypes.self, out var selfUrl);
            data.Links.TryGetValue(RelTypes.first, out var firstUrl);
            data.Links.TryGetValue(RelTypes.next, out var nextUrl);
            data.Links.TryGetValue(RelTypes.last, out var lastUrl);
            Assert.AreEqual($"{Url}?searchText=&skip=0&take=50", selfUrl);
            Assert.AreEqual($"{Url}?searchText=&skip=0&take=50", firstUrl);
            Assert.AreEqual($"{Url}?searchText=&skip=50&take=50", nextUrl);
            Assert.AreEqual($"{Url}?searchText=&skip=150&take=50", lastUrl);

            Assert.AreEqual(expectedPagingText, data.PagingText);
        }