public void DefaultItemsPerPage_ReturnsOrderedSource()
        {
            var orderedSource = new OrderedSource<string>(new[] { "hello", "world" }.AsQueryable().OrderBy(s => s));
            var orderedPageSource = new OrderedPageSourceModel<string, PageRequestModel>(5, 1, orderedSource, new PageRequestModel());

            var newPageSource = orderedPageSource.DefaultItemsPerPage(18);
            Assert.AreSame(orderedPageSource.Source, newPageSource.Source);
            Assert.AreSame(orderedPageSource.Request, newPageSource.Request);
            Assert.AreEqual(orderedPageSource.GetMaxItemsPerPage(), newPageSource.GetMaxItemsPerPage());
            Assert.AreEqual(18, newPageSource.GetDefaultItemsPerPage());
            Assert.IsInstanceOf(typeof(OrderedPageSourceModel<string, PageRequestModel>), newPageSource);

            var newNewPageSource = ((IOrderedPageSourceModel<string, PageRequestModel>)orderedPageSource).DefaultItemsPerPage(36);
            Assert.AreSame(orderedPageSource.Source, newNewPageSource.Source);
            Assert.AreSame(orderedPageSource.Request, newNewPageSource.Request);
            Assert.AreEqual(orderedPageSource.GetMaxItemsPerPage(), newNewPageSource.GetMaxItemsPerPage());
            Assert.AreEqual(36, newNewPageSource.GetDefaultItemsPerPage());
            Assert.IsInstanceOf(typeof(OrderedPageSourceModel<string, PageRequestModel>), newNewPageSource);
        }
예제 #2
0
        public void DefaultItemsPerPage_ReturnsOrderedSource()
        {
            var orderedSource     = new OrderedSource <string>(new[] { "hello", "world" }.AsQueryable().OrderBy(s => s));
            var orderedPageSource = new OrderedPageSourceModel <string, PageRequestModel>(5, 1, orderedSource, new PageRequestModel());

            var newPageSource = orderedPageSource.DefaultItemsPerPage(18);

            Assert.AreSame(orderedPageSource.Source, newPageSource.Source);
            Assert.AreSame(orderedPageSource.Request, newPageSource.Request);
            Assert.AreEqual(orderedPageSource.GetMaxItemsPerPage(), newPageSource.GetMaxItemsPerPage());
            Assert.AreEqual(18, newPageSource.GetDefaultItemsPerPage());
            Assert.IsInstanceOf(typeof(OrderedPageSourceModel <string, PageRequestModel>), newPageSource);

            var newNewPageSource = ((IOrderedPageSourceModel <string, PageRequestModel>)orderedPageSource).DefaultItemsPerPage(36);

            Assert.AreSame(orderedPageSource.Source, newNewPageSource.Source);
            Assert.AreSame(orderedPageSource.Request, newNewPageSource.Request);
            Assert.AreEqual(orderedPageSource.GetMaxItemsPerPage(), newNewPageSource.GetMaxItemsPerPage());
            Assert.AreEqual(36, newNewPageSource.GetDefaultItemsPerPage());
            Assert.IsInstanceOf(typeof(OrderedPageSourceModel <string, PageRequestModel>), newNewPageSource);
        }
예제 #3
0
        public void ThenByDescending_ReturnsOrderedSourceThenByDescending()
        {
            var thenBy        = new Mock <IOrderedSource <string> >();
            var orderedSource = new Mock <IOrderedSource <string> >(MockBehavior.Strict);
            Expression <Func <String, int> > keySelector = s => s.Length;

            orderedSource.Setup(s => s.ThenByDescending(keySelector)).Returns(thenBy.Object).Verifiable("The source was not ordered then by descending by the key selector.");

            var m1 = new OrderedPageSourceModel <string, PageRequestModel>(8, 7, orderedSource.Object, new PageRequestModel());
            var m2 = m1.ThenByDescending(keySelector);

            orderedSource.Verify();
            Assert.AreEqual(m1.GetMaxItemsPerPage(), m2.GetMaxItemsPerPage());
            Assert.AreEqual(m1.GetDefaultItemsPerPage(), m2.GetDefaultItemsPerPage());
            Assert.AreSame(thenBy.Object, m2.Source);
            Assert.AreSame(m1.Request, m2.Request);
        }
        public void ThenBy_ReturnsOrderedSourceThenBy()
        {
            var thenBy = new Mock<IOrderedSource<string>>();
            var orderedSource = new Mock<IOrderedSource<string>>(MockBehavior.Strict);
            Expression<Func<String, int>> keySelector = s => s.Length;

            orderedSource.Setup(s => s.ThenBy(keySelector)).Returns(thenBy.Object).Verifiable("The source was not ordered then by by the key selector.");

            var m1 = new OrderedPageSourceModel<string, PageRequestModel>(8, 7, orderedSource.Object, new PageRequestModel());
            var m2 = m1.ThenBy(keySelector);
            orderedSource.Verify();
            Assert.AreEqual(m1.GetMaxItemsPerPage(), m2.GetMaxItemsPerPage());
            Assert.AreEqual(m1.GetDefaultItemsPerPage(), m2.GetDefaultItemsPerPage());
            Assert.AreSame(thenBy.Object, m2.Source);
            Assert.AreSame(m1.Request, m2.Request);
        }