Esempio n. 1
0
        public void DeleteClientTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Client client = new Client("michu_one_two_three", "Mich", "Kasztanek", "1234");

            dataService.AddClient(client);

            int originalCount = dataService.GetClients().ToImmutableHashSet().Count;

            dataService.DeleteClient(client);

            Assert.Equal(originalCount - 1, dataService.GetClients().ToImmutableHashSet().Count);
            Assert.DoesNotContain(client, dataService.GetClients());
        }
Esempio n. 2
0
        public void DeleteBookTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Book book = new Book("W pustyni i w puczczy", "Henryk Sienkiewicz", 1910);

            dataService.AddBook(book);

            int originalCount = dataService.GetBooks().ToImmutableHashSet().Count;

            dataService.DeleteBook(book);

            Assert.Equal(originalCount - 1, dataService.GetBooks().ToImmutableHashSet().Count);
            Assert.DoesNotContain(book, dataService.GetBooks());
        }
Esempio n. 3
0
        public void GetCopyDetailsTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);
            CopyDetails     presentCopyDetails = dataRepository.GetCopyDetails(3);
            Book            book        = presentCopyDetails.Book;
            decimal         price       = presentCopyDetails.Price;
            decimal         tax         = presentCopyDetails.Tax;
            int             count       = presentCopyDetails.Count;
            String          description = presentCopyDetails.Description;

            CopyDetails notPresentCopyDetails =
                new CopyDetails(book, price, tax, 50, "There is no such description");

            Assert.Equal(presentCopyDetails,
                         dataService.GetCopyDetails(book, price, tax, count, description));
            Assert.DoesNotContain(notPresentCopyDetails, dataService.GetAllCopyDetails());
        }
Esempio n. 4
0
        void ReturnBookTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Invoice invoice = dataRepository.GetEvent(2) as Invoice;

            int totalBookCount = invoice.CopyDetails.Count;

            dataService.ReturnBook(invoice, false, "sample reclamation");

            Assert.Equal(totalBookCount + 1, (dataRepository.GetEvent(2) as Invoice).CopyDetails.Count);

            Invoice notPresentInvoice = new Invoice(dataRepository.GetClient((2)), dataRepository.GetCopyDetails(2),
                                                    DateTime.Now, "sample description");

            Assert.Throws <InvalidOperationException>(() =>
                                                      dataService.ReturnBook(notPresentInvoice, false, "sample invoice"));
        }
Esempio n. 5
0
        public void GetBoughtBooksAndAmountTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            IEnumerable <ValueTuple <Book, int> > boughtBooks = dataService.GetBoughtBooksAndAmount();

            int booksCount = dataService.GetBooks().ToImmutableHashSet().Count;

            Assert.Equal(booksCount, boughtBooks.ToImmutableHashSet().Count);

            int totalInvoices = 0;

            foreach (ValueTuple <Book, int> book in boughtBooks)
            {
                totalInvoices += book.Item2;
            }

            Assert.Equal(dataService.GetEvents().ToImmutableHashSet().Count, totalInvoices);
        }
Esempio n. 6
0
        public void GetBookTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);
            Book            presentBook        = dataRepository.GetBook(0);
            String          presentBookName    = presentBook.BookName;
            String          presentBookAuthor  = presentBook.AuthorName;
            int             presentBookYear    = presentBook.Year;

            Book notPresentBook = new Book("I don't exist", "Neither do I", 2999);

            Assert.Equal(presentBook, dataService.GetBook(presentBookName, presentBookAuthor, presentBookYear));
            try
            {
                Assert.NotEqual(notPresentBook, dataService.GetBook("I don't exist", "Neither do I", 2999));
            }
            catch (ArgumentException)
            {
            }
        }
Esempio n. 7
0
        public void GetInvoicesForTheBookTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Book book = dataRepository.GetBook(1);
            IEnumerable <Event> eEvent = dataService.GetEventsForTheBook(book);

            foreach (Event e in eEvent)
            {
                Reclamation r = e as Reclamation;
                Invoice     i = e as Invoice;
                if (i != null)
                {
                    Assert.Equal(book, i.CopyDetails.Book);
                }
                else
                {
                    Assert.Equal(book, r.Invoice.CopyDetails.Book);
                }
            }
        }
Esempio n. 8
0
        public void GetInvoicesForTheClientTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Client client = dataRepository.GetClient(1);
            IEnumerable <Event> events = dataService.GetEventsForTheClient(client);

            foreach (Event e in events)
            {
                Reclamation r = e as Reclamation;
                Invoice     i = e as Invoice;
                if (i != null)
                {
                    Assert.Equal(client, i.Client);
                }
                else
                {
                    Assert.Equal(client, r.Invoice.Client);
                }
            }
        }
Esempio n. 9
0
        public void GetInvoicesBetweenTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            DateTime            startTime   = new DateTime(2005, 1, 1);
            DateTime            stopTime    = new DateTime(2008, 12, 31);
            IEnumerable <Event> invoices    = dataService.GetEventsBetween(startTime, stopTime);
            IEnumerable <Event> allInvoices = dataService.GetEvents();

            foreach (Event invoice in allInvoices)
            {
                if (invoice.EventDateTime >= startTime && invoice.EventDateTime <= stopTime)
                {
                    Assert.Contains(invoice, invoices);
                }

                else
                {
                    Assert.DoesNotContain(invoice, invoices);
                }
            }
        }