public void SutOrderByEditionDescendingAndAuthorDescendingAndTitleAscending()
        {
            var context =
                new TestAppContext(new[]
            {
                new Sorting <Book> {
                    Column = c => c.EditionYear, Ascending = false
                },
                new Sorting <Book> {
                    Column = c => c.AuthorName, Ascending = false
                },
                new Sorting <Book> {
                    Column = c => c.Title, Ascending = true
                }
            });
            IBooksOrderer orderer = new BooksOrderer(context);
            var           books   = GetBooks();
            var           result  = orderer.Order(books);

            Assert.IsNotNull(result);
            Assert.AreEqual("Internet & World Wide Web: How to Program", result.ElementAt(0).Title);
            Assert.AreEqual("Java How to Program", result.ElementAt(1).Title);
            Assert.AreEqual("Head First Design Patterns", result.ElementAt(2).Title);
            Assert.AreEqual("Patterns of Enterprise Application Architecture", result.ElementAt(3).Title);
        }
        public void SutNotOrderIfSortingIsEmpty()
        {
            var context =
                new TestAppContext(new Sorting <Book> [0]);
            IBooksOrderer orderer = new BooksOrderer(context);
            var           books   = GetBooks();
            var           result  = orderer.Order(books);

            Assert.IsFalse(result.Any());
        }
        public void SutNotOrderIfSortingIsNull()
        {
            var context =
                new TestAppContext(null);
            IBooksOrderer orderer = new BooksOrderer(context);
            var           books   = GetBooks();

            try
            {
                var result = orderer.Order(books);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(OrdenationException));
            }
        }
Ejemplo n.º 4
0
        public void SutPostBooks()
        {
            var context = new TestAppContext(new[] { new Sorting <Book> {
                                                         Column = c => c.Title, Ascending = true
                                                     } });
            var service               = new BooksOrderer(context);
            var controller            = new BookController(context, service);
            IEnumerable <Book> result = controller.Order(new[]
            {
                new Book
                {
                    Title       = "Java How to Program",
                    AuthorName  = "Deitel & Deitel",
                    EditionYear = 2007
                },
                new Book
                {
                    Title       = "Patterns of Enterprise Application Architecture",
                    AuthorName  = "Martin Fowler",
                    EditionYear = 2002
                },
                new Book
                {
                    Title       = "Head First Design Patterns",
                    AuthorName  = "Elisabeth Freeman",
                    EditionYear = 2004
                },
                new Book
                {
                    Title       = "Internet & World Wide Web: How to Program",
                    AuthorName  = "Deitel & Deitel",
                    EditionYear = 2007
                }
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Count());
        }