Exemplo n.º 1
0
        public void GetPurchasesBetweenTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);

            dataService.AddBookDetails(new BookDetails(new Book("Something Fishy", "Wodehouse", 1957), new decimal(12.99), new decimal(0.05), 12, "Something Fishy is a novel by P. G. Wodehouse, first published in the United Kingdom on 18 January 1957 by Herbert Jenkins, London and in the United States on 28 January 1957 by Simon & Schuster, Inc., New York, under the title The Butler Did It."));
            dataService.AddBookDetails(new BookDetails(new Book("Pet Sematary", "King", 1983), new decimal(32.99), new decimal(0.05), 18, "Pet Sematary is a 1983 horror novel by American writer Stephen King. The novel was nominated for a World Fantasy Award for Best Novel in 1986, and adapted into two films: one in 1989 and another in 2019. In November 2013, PS Publishing released Pet Sematary in a limited 30th-anniversary edition."));
            dataService.AddBookDetails(new BookDetails(new Book("Harry Potter and the Half-Blook Prince", "Rowling", 2005), new decimal(25.99), new decimal(0.05), 54, "Harry Potter and the Half-Blood Prince is a fantasy novel written by British author J.K. Rowling and the sixth and penultimate novel in the Harry Potter series."));
            dataService.AddBookDetails(new BookDetails(new Book("Marley & Me", "Grogan", 2005), new decimal(15.99), new decimal(0.05), 35, "Marley & Me: Life and Love with the World's Worst Dog is an autobiographical book by journalist John Grogan, published in 2005, about the 13 years he and his family spent with their yellow Labrador Retriever, Marley."));
            dataService.AddBookDetails(new BookDetails(new Book("Feast", "Masterton", 1988), new decimal(30.99), new decimal(0.05), 23, "The little town of Allen's Corner in rural Connecticut hid a secret. A terrible, unimaginable secret. A secret that only the children knew. It fed on their youth, ate away at their innocence, and consumed their very souls with a twisted hunger that could never be revealed - nor ever satisfied."));

            dataService.BuyBook(new Publisher("Publisher1", "111111111"), dataService.GetBookDetails(0), 112);
            dataService.BuyBook(new Publisher("Publisher2", "222222222"), dataService.GetBookDetails(1), 113);
            dataService.BuyBook(new Publisher("Publisher3", "333333333"), dataService.GetBookDetails(2), 114);
            dataService.BuyBook(new Publisher("Publisher4", "444444444"), dataService.GetBookDetails(3), 115);
            dataService.BuyBook(new Publisher("Publisher5", "555555555"), dataService.GetBookDetails(4), 116);
            DateTime startDate = new DateTime(2015, 1, 1, 0, 0, 0);
            DateTime endDate   = new DateTime(2018, 1, 1, 0, 0, 0);

            for (int i = 0; i < dataService.GetAllPurchases().Count(); i++)
            {
                if (dataService.GetPurchase(i).PurchaseTime >= startDate && dataService.GetPurchase(i).PurchaseTime <= endDate)
                {
                    Assert.IsTrue(dataService.GetPurchasesBetween(startDate, endDate).Contains(dataService.GetPurchase(i)));
                }
                else
                {
                    Assert.IsFalse(dataService.GetPurchasesBetween(startDate, endDate).Contains(dataService.GetPurchase(i)));
                }
            }
        }
Exemplo n.º 2
0
        public void GetAllBookDetailsTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);

            dataService.AddBookDetails(new BookDetails(new Book("Something Fishy", "Wodehouse", 1957), new decimal(12.99), new decimal(0.05), 12, "Something Fishy is a novel by P. G. Wodehouse, first published in the United Kingdom on 18 January 1957 by Herbert Jenkins, London and in the United States on 28 January 1957 by Simon & Schuster, Inc., New York, under the title The Butler Did It."));
            dataService.AddBookDetails(new BookDetails(new Book("Pet Sematary", "King", 1983), new decimal(32.99), new decimal(0.05), 18, "Pet Sematary is a 1983 horror novel by American writer Stephen King. The novel was nominated for a World Fantasy Award for Best Novel in 1986, and adapted into two films: one in 1989 and another in 2019. In November 2013, PS Publishing released Pet Sematary in a limited 30th-anniversary edition."));
            dataService.AddBookDetails(new BookDetails(new Book("Harry Potter and the Half-Blook Prince", "Rowling", 2005), new decimal(25.99), new decimal(0.05), 54, "Harry Potter and the Half-Blood Prince is a fantasy novel written by British author J.K. Rowling and the sixth and penultimate novel in the Harry Potter series."));
            dataService.AddBookDetails(new BookDetails(new Book("Marley & Me", "Grogan", 2005), new decimal(15.99), new decimal(0.05), 35, "Marley & Me: Life and Love with the World's Worst Dog is an autobiographical book by journalist John Grogan, published in 2005, about the 13 years he and his family spent with their yellow Labrador Retriever, Marley."));
            dataService.AddBookDetails(new BookDetails(new Book("Feast", "Masterton", 1988), new decimal(30.99), new decimal(0.05), 23, "The little town of Allen's Corner in rural Connecticut hid a secret. A terrible, unimaginable secret. A secret that only the children knew. It fed on their youth, ate away at their innocence, and consumed their very souls with a twisted hunger that could never be revealed - nor ever satisfied."));

            Assert.AreEqual(5, dataService.GetAllBookDetails().Count());
            Assert.IsInstanceOfType(dataService.GetAllBookDetails(), typeof(IEnumerable <BookDetails>));
        }
Exemplo n.º 3
0
        public void GetBookDetailsTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);
            Book           book           = new Book("Something Fishy", "Wodehouse", 1957);
            BookDetails    bookDetails    = new BookDetails(book, new decimal(12.99), new decimal(0.05), 12, "Something Fishy is a novel by P. G. Wodehouse, first published in the United Kingdom on 18 January 1957 by Herbert Jenkins, London and in the United States on 28 January 1957 by Simon & Schuster, Inc., New York, under the title The Butler Did It.");

            dataService.AddBookDetails(bookDetails);

            Assert.AreEqual(dataService.GetAllBookDetails().First(), dataService.GetBookDetails(0));
        }
Exemplo n.º 4
0
        public void AddBookDetailsTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);
            Book           book           = new Book("Bk name", "Bk author", 2010);
            BookDetails    bookDetails    = new BookDetails(book, new decimal(24.99), new decimal(0.05), 33, "Book that contains words");

            Assert.AreEqual(dataService.GetAllBookDetails().Count(), 0);
            dataService.AddBookDetails(bookDetails);
            Assert.AreEqual(dataService.GetAllBookDetails().Count(), 1);
        }
Exemplo n.º 5
0
        public void GetNumberOfBooksByKeyTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);
            Book           book           = new Book("Bk name", "Bk author", 2010);
            BookDetails    bookDetails    = new BookDetails(book, new decimal(24.99), new decimal(0.05), 33, "Book that contains words");

            dataService.AddBookDetails(bookDetails);

            Assert.AreEqual(dataService.GetBookDetails(0).Count, dataService.GetNumberOfBooks(dataService.GetBookDetails(0).Book));
        }
Exemplo n.º 6
0
        public void GetPurchaseTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);
            Book           book           = new Book("Something Fishy", "Wodehouse", 1957);
            BookDetails    bookDetails    = new BookDetails(book, new decimal(12.99), new decimal(0.05), 12, "Something Fishy is a novel by P. G. Wodehouse, first published in the United Kingdom on 18 January 1957 by Herbert Jenkins, London and in the United States on 28 January 1957 by Simon & Schuster, Inc., New York, under the title The Butler Did It.");
            Client         client         = new Client("ClName", "ClLastName", "99101023432", "321654987");

            dataService.AddBook(book);
            dataService.AddBookDetails(bookDetails);
            dataService.BuyBook(new Publisher("Publisher1", "111111111"), dataService.GetBookDetails(0), 112);

            Assert.AreEqual(dataService.GetAllPurchases().First(), dataService.GetPurchase(0));
        }
Exemplo n.º 7
0
        public void BuyBookTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);
            Book           book           = new Book("Bk name", "Bk author", 2010);
            BookDetails    bookDetails    = new BookDetails(book, new decimal(24.99), new decimal(0.05), 33, "Book that contains words");
            Publisher      publisher      = new Publisher("Name", "2115");

            dataService.AddBook(book);
            dataService.AddBookDetails(bookDetails);

            Assert.AreEqual(dataService.GetNumberOfBooks(book), 33);
            dataService.BuyBook(publisher, bookDetails, 25);
            Assert.AreEqual(dataService.GetNumberOfBooks(book), 58);
        }
Exemplo n.º 8
0
        public void SellBookTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);
            Book           book           = new Book("Bk name", "Bk author", 2010);
            BookDetails    bookDetails    = new BookDetails(book, new decimal(24.99), new decimal(0.05), 33, "Book that contains words");
            Client         client         = new Client("ClName", "ClLastName", "99101023432", "321654987");

            dataService.AddBook(book);
            dataService.AddBookDetails(bookDetails);

            Assert.AreEqual(dataService.GetNumberOfBooks(book), 33);
            dataService.SellBook(client, bookDetails, 10);
            Assert.AreEqual(dataService.GetNumberOfBooks(book), 23);
            Assert.IsTrue(dataService.GetPurchasesForClient(client).First().BookDetails.Equals(bookDetails));
        }
Exemplo n.º 9
0
        public void GetPurchasesForPublisherTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);
            Book           book           = new Book("Something Fishy", "Wodehouse", 1957);
            BookDetails    bookDetails    = new BookDetails(book, new decimal(12.99), new decimal(0.05), 12, "Something Fishy is a novel by P. G. Wodehouse, first published in the United Kingdom on 18 January 1957 by Herbert Jenkins, London and in the United States on 28 January 1957 by Simon & Schuster, Inc., New York, under the title The Butler Did It.");
            Publisher      publisher      = new Publisher("Publisher1", "111111111");

            dataService.AddPublisher(publisher);
            dataService.AddBook(book);
            dataService.AddBookDetails(bookDetails);
            dataService.BuyBook(publisher, dataService.GetBookDetails(0), 112);

            CollectionAssert.AreEqual(new List <Purchase> {
                dataService.GetPurchase(0)
            }, dataService.GetPurchasesForPublisher(dataService.GetPublisher(0)).ToList());
        }
Exemplo n.º 10
0
        public void GetPurchasesForClientTest()
        {
            DataRepository dataRepository = new DataRepository();
            DataService    dataService    = new DataService(dataRepository);
            Book           book           = new Book("Something Fishy", "Wodehouse", 1957);
            BookDetails    bookDetails    = new BookDetails(book, new decimal(12.99), new decimal(0.05), 12, "Something Fishy is a novel by P. G. Wodehouse, first published in the United Kingdom on 18 January 1957 by Herbert Jenkins, London and in the United States on 28 January 1957 by Simon & Schuster, Inc., New York, under the title The Butler Did It.");
            Client         client         = new Client("ClName", "ClLastName", "99101023432", "321654987");

            dataService.AddClient(client);
            dataService.AddBook(book);
            dataService.AddBookDetails(bookDetails);
            dataService.SellBook(client, bookDetails, 10);

            CollectionAssert.AreEqual(new List <Purchase> {
                dataService.GetPurchase(0)
            }, dataService.GetPurchasesForClient(dataService.GetClient(0)).ToList());
        }