Example #1
0
        public void ToStringTest()
        {
            ConstantDataFiller filler     = new ConstantDataFiller();
            DataRepository     repository = new DataRepository(filler.Fill(new DataContext()));

            Assert.AreEqual("Publisher: Publisher1, phone numer: 111111111\n", repository.GetPublisher(0).ToString());
        }
        public void FillTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));

            Assert.AreEqual(5, dataRepository.GetAllClients().Count());
            Assert.AreEqual("Client: Ellie Doe, PESEL: 21151112115, phone number: 111112115\n", dataRepository.GetClient(0).ToString());
            Assert.AreEqual("Client: Luis Snow, PESEL: 21152222115, phone number: 222222115\n", dataRepository.GetClient(1).ToString());
            Assert.AreEqual("Client: Rachel Sanchez, PESEL: 21153332115, phone number: 333332115\n", dataRepository.GetClient(2).ToString());
            Assert.AreEqual("Client: Jud Smith, PESEL: 21154442115, phone number: 444442115\n", dataRepository.GetClient(3).ToString());
            Assert.AreEqual("Client: Gage Butler, PESEL: 21155552115, phone number: 555552115\n", dataRepository.GetClient(4).ToString());

            Assert.AreEqual(5, dataRepository.GetAllPublishers().Count());
            Assert.AreEqual("Publisher: Publisher1, phone numer: 111111111\n", dataRepository.GetPublisher(0).ToString());
            Assert.AreEqual("Publisher: Publisher2, phone numer: 222222222\n", dataRepository.GetPublisher(1).ToString());
            Assert.AreEqual("Publisher: Publisher3, phone numer: 333333333\n", dataRepository.GetPublisher(2).ToString());
            Assert.AreEqual("Publisher: Publisher4, phone numer: 444444444\n", dataRepository.GetPublisher(3).ToString());
            Assert.AreEqual("Publisher: Publisher5, phone numer: 555555555\n", dataRepository.GetPublisher(4).ToString());

            Assert.AreEqual(5, dataRepository.GetAllBooks().Count());
            Assert.AreEqual("Book: \"Something Fishy\" by Wodehouse (1957)", dataRepository.GetBook(0).ToString());
            Assert.AreEqual("Book: \"Pet Sematary\" by King (1983)", dataRepository.GetBook(1).ToString());
            Assert.AreEqual("Book: \"Harry Potter and the Half-Blook Prince\" by Rowling (2005)", dataRepository.GetBook(2).ToString());
            Assert.AreEqual("Book: \"Marley & Me\" by Grogan (2005)", dataRepository.GetBook(3).ToString());
            Assert.AreEqual("Book: \"Feast\" by Masterton (1988)", dataRepository.GetBook(4).ToString());

            Assert.AreEqual(5, dataRepository.GetAllBooksDetails().Count());
            Assert.AreEqual("Book details: Book: \"Something Fishy\" by Wodehouse (1957), price: 12,99, tax: 5,00%, count: 114, description: \"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.\"\n", dataRepository.GetBookDetails(0).ToString());
            Assert.AreEqual("Book details: Book: \"Pet Sematary\" by King (1983), price: 32,99, tax: 5,00%, count: 120, description: \"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.\"\n", dataRepository.GetBookDetails(1).ToString());
            Assert.AreEqual("Book details: Book: \"Harry Potter and the Half-Blook Prince\" by Rowling (2005), price: 25,99, tax: 5,00%, count: 156, description: \"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.\"\n", dataRepository.GetBookDetails(2).ToString());
            Assert.AreEqual("Book details: Book: \"Marley & Me\" by Grogan (2005), price: 15,99, tax: 5,00%, count: 137, description: \"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.\"\n", dataRepository.GetBookDetails(3).ToString());
            Assert.AreEqual("Book details: Book: \"Feast\" by Masterton (1988), price: 30,99, tax: 5,00%, count: 125, description: \"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.\"\n", dataRepository.GetBookDetails(4).ToString());

            Assert.AreEqual(10, dataRepository.GetAllPurchases().Count());
        }
        public void GetAllPurchasesTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));

            Assert.AreEqual(10, dataRepository.GetAllPurchases().Count());
            Assert.IsInstanceOfType(dataRepository.GetAllPurchases(), typeof(IEnumerable <Purchase>));
        }
        public void GetAllBooksDetailsTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));

            Assert.AreEqual(5, dataRepository.GetAllBooksDetails().Count());
            Assert.IsInstanceOfType(dataRepository.GetAllBooksDetails(), typeof(IEnumerable <BookDetails>));
        }
Example #5
0
        public void TestConstantDataFiler()
        {
            DataContext context = ConstantDataFiller.Fill();

            Assert.AreEqual <int>(4, context.books.Count);
            Assert.AreEqual <int>(4, context.bookStates.Count);
            Assert.AreEqual <int>(4, context.clients.Count);
            Assert.AreEqual <int>(8, context.events.Count);
        }
Example #6
0
        public void GetHashCodeTest()
        {
            ConstantDataFiller filler     = new ConstantDataFiller();
            DataRepository     repository = new DataRepository(filler.Fill(new DataContext()));

            BuyBook buyBookA = new BuyBook(repository.GetPublisher(0), repository.GetBookDetails(0), new DateTime(), 12);
            BuyBook buyBookB = new BuyBook(repository.GetPublisher(0), repository.GetBookDetails(0), new DateTime(), 12);

            Assert.AreEqual(buyBookA.GetHashCode(), buyBookB.GetHashCode());
        }
        public void GetBookTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            Book book = new Book("Bk name", "Bk author", 2010);

            Assert.ThrowsException <ArgumentException>(() => dataRepository.GetBook(5));
            dataRepository.AddBook(book);
            Assert.AreEqual(dataRepository.GetBook(5), book);
        }
Example #8
0
        public void BuyBookTest()
        {
            ConstantDataFiller filler     = new ConstantDataFiller();
            DataRepository     repository = new DataRepository(filler.Fill(new DataContext()));

            int numberOfBooksBeforePurchase = repository.GetBookCount(repository.GetBook(0));

            new BuyBook(repository.GetPublisher(0), repository.GetBookDetails(0), new DateTime(), 12);
            Assert.AreEqual(numberOfBooksBeforePurchase + 12, repository.GetBookDetails(0).Count);
        }
Example #9
0
        public void GetHashCodeTest()
        {
            ConstantDataFiller filler     = new ConstantDataFiller();
            DataRepository     repository = new DataRepository(filler.Fill(new DataContext()));

            SellBook sellBookA = new SellBook(repository.GetClient(0), repository.GetBookDetails(0), new DateTime(), 12);
            SellBook sellBookB = new SellBook(repository.GetClient(0), repository.GetBookDetails(0), new DateTime(), 12);

            Assert.AreEqual(sellBookA.GetHashCode(), sellBookB.GetHashCode());
        }
        public void GetClientTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            Client             client         = new Client("ClName", "ClLastName", "99101023432", "321654987");

            Assert.ThrowsException <ArgumentException>(() => dataRepository.GetClient(5));
            dataRepository.AddClient(client);
            Assert.AreEqual(dataRepository.GetClient(5), client);
        }
        public void AddBookTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            Book book = new Book("Bk name", "Bk author", 2010);

            dataRepository.AddBook(book);
            Assert.AreEqual(5, dataRepository.FindBook(book));
            Assert.IsTrue(dataRepository.GetAllBooks().Last().Equals(book));
            Assert.ThrowsException <ArgumentException>(() => dataRepository.AddBook(book));
        }
        public void DataRepositoryTest2()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));

            Assert.AreEqual(dataRepository.GetAllBooks().Count(), 5);
            Assert.AreEqual(dataRepository.GetAllPublishers().Count(), 5);
            Assert.AreEqual(dataRepository.GetAllPurchases().Count(), 10);
            Assert.AreEqual(dataRepository.GetAllBooksDetails().Count(), 5);
            Assert.AreEqual(dataRepository.GetAllClients().Count(), 5);
        }
        public void GetBookDetailsTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            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.ThrowsException <ArgumentException>(() => dataRepository.GetBookDetails(5));
            dataRepository.AddBookDetails(bookDetails);
            Assert.AreEqual(dataRepository.GetBookDetails(5), bookDetails);
        }
        public void DeleteBookTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            Book book = new Book("Bk name", "Bk author", 2010);

            Assert.ThrowsException <ArgumentException>(() => dataRepository.DeleteBook(dataRepository.FindBook(book)));
            Assert.ThrowsException <ArgumentException>(() => dataRepository.DeleteBook(123));
            Assert.AreEqual(dataRepository.GetAllBooks().Count(), 5);
            dataRepository.DeleteBook(4);
            Assert.AreEqual(dataRepository.GetAllBooks().Count(), 4);
        }
        public void GetBookCountTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            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");

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

            Assert.AreEqual(33, dataRepository.GetBookCount(book));
        }
        public void GetPurchaseTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            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");
            Purchase    purchase    = new SellBook(client, bookDetails, new DateTime(), 1);

            Assert.ThrowsException <ArgumentException>(() => dataRepository.GetPurchase(123));
            dataRepository.AddPurchase(purchase);
            Assert.AreEqual(dataRepository.GetPurchase(10), purchase);
        }
        public void TestSerialization()
        {
            string         path        = "./test.json";
            DataContext    context     = ConstantDataFiller.Fill();
            JsonSerializer serializing = new JsonSerializer();

            serializing.Serialize(context, path);
            DataContext deserializedContext = serializing.DeserializeToDataContext(path);

            Assert.AreEqual <int>(context.books.Count, deserializedContext.books.Count);
            Assert.AreEqual <int>(context.bookStates.Count, deserializedContext.bookStates.Count);
            Assert.AreEqual <int>(context.clients.Count, deserializedContext.clients.Count);
            Assert.AreEqual <int>(context.events.Count, deserializedContext.events.Count);

            for (int index = 0; index < context.books.Count; index++)
            {
                Assert.AreEqual <Book>(context.books[index], deserializedContext.books[index]);
            }

            for (int index = 0; index < context.bookStates.Count; index++)
            {
                Assert.AreEqual <BookState>(context.bookStates[index], deserializedContext.bookStates[index]);
            }

            for (int index = 0; index < context.clients.Count; index++)
            {
                Assert.AreEqual <Client>(context.clients[index], deserializedContext.clients[index]);
            }

            for (int index = 0; index < context.events.Count; index++)
            {
                Assert.AreEqual <Event>(context.events[index], deserializedContext.events[index]);
                if (index < 4)
                {
                    Assert.IsTrue(deserializedContext.events[index] is Purchase);
                }
                else
                {
                    Assert.IsTrue(deserializedContext.events[index] is Sale);
                }
            }
        }