Ejemplo n.º 1
0
        public void GetAllInvoicesTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Assert.Equal(6, dataRepository.GetAllEvents().Count());
        }
Ejemplo n.º 2
0
        public void CopyDetailsGeneratingTest()
        {
            ConstantDataFiller constantDataFiller = new ConstantDataFiller();
            IDataRepository    dataRepository     = new DataRepository(constantDataFiller);

            Dictionary <int, Book> books = new Dictionary <int, Book>();

            books.Add(0,
                      new Book("Harry Potter and the Philosopher's Stone_0", "Joanne Rowling", 1997));
            books.Add(1,
                      new Book("Harry Potter and the Philosopher's Stone_1", "Joanne Rowling", 1997));
            books.Add(2,
                      new Book("Harry Potter and the Philosopher's Stone_2", "Joanne Rowling", 1997));
            books.Add(3,
                      new Book("Harry Potter and the Philosopher's Stone_3", "Joanne Rowling", 1997));
            books.Add(4,
                      new Book("Harry Potter and the Philosopher's Stone_4", "Joanne Rowling", 1997));


            List <CopyDetails> copyDetailsList = new List <CopyDetails>();

            copyDetailsList.Add(new CopyDetails(books[0], 24.5m, 3.4m, 3, "short description 0"));
            copyDetailsList.Add(new CopyDetails(books[1], 14.59m, 2.4m, 1, "short description 1"));
            copyDetailsList.Add(new CopyDetails(books[2], 26.45m, 1.4m, 3, "short description 2"));
            copyDetailsList.Add(new CopyDetails(books[3], 246.99m, 35.4m, 5, "short description 3"));
            copyDetailsList.Add(new CopyDetails(books[4], 134.5m, 13.4m, 1, "short description 4"));

            for (int i = 0; i < copyDetailsList.Count; i++)
            {
                Assert.True(dataRepository.GetCopyDetails(i).Equals(copyDetailsList[i]));
            }
        }
Ejemplo n.º 3
0
        public void GetClientsForTheBookTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Book book = dataRepository.GetBook(3);

            ImmutableHashSet <Client> clients = dataService.GetClientsForTheBook(book).ToImmutableHashSet();
            IEnumerable <Event>       events  = dataService.GetEventsForTheBook(book);

            foreach (Event e in events)
            {
                Reclamation r = e as Reclamation;
                Invoice     i = e as Invoice;
                if (i != null)
                {
                    Assert.Contains(i.Client, clients);
                }
                else
                {
                    Assert.Contains(r.Invoice.Client, clients);
                }
            }
        }
Ejemplo n.º 4
0
        public void GetClientTest()
        {
            IDataFiller     constantDataFiller       = new ConstantDataFiller();
            IDataRepository dataRepository           = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService              = new DataService(dataRepository);
            Client          presentClient            = dataRepository.GetClient(2);
            String          presentClientEmail       = presentClient.Email;
            String          presentClientFirstName   = presentClient.FirstName;
            String          presentClientSecondName  = presentClient.SecondName;
            String          presentClientPhoneNumber = presentClient.PhoneNumber;

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

            Assert.Equal(presentClient,
                         dataService.GetClient(presentClientEmail, presentClientFirstName, presentClientSecondName,
                                               presentClientPhoneNumber));
            try
            {
                Assert.NotEqual(notPresentClient,
                                dataService.GetClient("michu_one_two_three", "Mich", "Kasztanek", "1234"));
            }
            catch (ArgumentException)
            {
            }
        }
Ejemplo n.º 5
0
        public void GetInvoiceTest()
        {
            IDataFiller     constantDataFiller         = new ConstantDataFiller();
            IDataRepository dataRepository             = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService                = new DataService(dataRepository);
            Invoice         presentInvoice             = dataRepository.GetEvent(2) as Invoice;
            Client          presentInvoiceClient       = presentInvoice.Client;
            CopyDetails     presentInvoiceCopyDetails  = presentInvoice.CopyDetails;
            DateTime        presentInvoicePurchaseTime = presentInvoice.EventDateTime;
            String          presentInvoiceDescription  = presentInvoice.Description;


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

            Assert.Equal(presentInvoice,
                         dataService.GetInvoice(presentInvoiceClient, presentInvoiceCopyDetails, presentInvoicePurchaseTime,
                                                presentInvoiceDescription));
            try
            {
                Assert.NotEqual(notPresentInvoice,
                                dataService.GetInvoice(dataRepository.GetClient(2), dataRepository.GetCopyDetails(3),
                                                       new DateTime(2040, 2, 2), "description"));
            }
            catch (ArgumentException)
            {
            }
        }
Ejemplo n.º 6
0
        public void GetAllCopyDetailsesTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Assert.Equal(5, dataRepository.GetAllCopyDetails().Count());
        }
Ejemplo n.º 7
0
        public void GetBookInvalidValue()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            Book            book = new Book("Year 1984", "George Orwell", 1949);

            Assert.Throws <ArgumentException>(() => dataRepository.GetBook(dataRepository.FindBook(book)));
        }
Ejemplo n.º 8
0
        public void DeleteBookForbiddenTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            Book            book = (dataRepository.GetEvent(0) as Invoice).CopyDetails.Book;

            Assert.Throws <ArgumentException>(() => dataRepository.DeleteBook(book));
        }
Ejemplo n.º 9
0
        public void DeleteCopyDetailsForbiddenTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            CopyDetails     copyDetails        = (dataRepository.GetEvent(0) as Invoice).CopyDetails;

            Assert.Throws <ArgumentException>(() => dataRepository.DeleteCopyDetails(copyDetails));
        }
Ejemplo n.º 10
0
        public void DeleteClientForbiddenTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            Client          client             = (dataRepository.GetEvent(0) as Invoice).Client;

            Assert.Throws <ArgumentException>(() => dataRepository.DeleteClient(client));
        }
Ejemplo n.º 11
0
        public void DeleteBookInvalidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            Book            book = new Book("Year 1984", "George Orwell", 1949);

            Assert.Equal(5, dataRepository.GetAllBooks().Count());
            Assert.Throws <ArgumentException>(() => dataRepository.DeleteBook(book));
        }
Ejemplo n.º 12
0
        public void GetBookValidValue()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            Book            book = new Book("Year 1984", "George Orwell", 1949);

            dataRepository.AddBook(book);

            Assert.NotNull(dataRepository.GetBook(dataRepository.FindBook(book)));
        }
Ejemplo n.º 13
0
        public void GetBooksTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            IEnumerable <Book> allBooks = dataService.GetBooks();

            Assert.Equal(dataRepository.GetAllBooks().ToImmutableHashSet().Count, allBooks.ToImmutableHashSet().Count);
        }
Ejemplo n.º 14
0
        public void FindBookValidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Book book = new Book("Year 1984", "George Orwell", 1949);

            dataRepository.AddBook(book);
            Assert.StrictEqual(6, dataRepository.FindBook(book));
        }
Ejemplo n.º 15
0
        public void InvoiceGeneratingTest()
        {
            ConstantDataFiller constantDataFiller = new ConstantDataFiller();
            IDataRepository    dataRepository     = new DataRepository(constantDataFiller);

            List <Client> clients = new List <Client>();

            clients.Add(new Client("*****@*****.**", "Jan_0", "Kowalski", "000"));
            clients.Add(new Client("*****@*****.**", "Jan_1", "Kowalski", "0001"));
            clients.Add(new Client("*****@*****.**", "Jan_2", "Kowalski", "0002"));
            clients.Add(new Client("*****@*****.**", "Jan_3", "Kowalski", "0003"));
            clients.Add(new Client("*****@*****.**", "Jan_4", "Kowalski", "0004"));

            Dictionary <int, Book> books = new Dictionary <int, Book>();

            books.Add(0,
                      new Book("Harry Potter and the Philosopher's Stone_0", "Joanne Rowling", 1997));
            books.Add(1,
                      new Book("Harry Potter and the Philosopher's Stone_1", "Joanne Rowling", 1997));
            books.Add(2,
                      new Book("Harry Potter and the Philosopher's Stone_2", "Joanne Rowling", 1997));
            books.Add(3,
                      new Book("Harry Potter and the Philosopher's Stone_3", "Joanne Rowling", 1997));
            books.Add(4,
                      new Book("Harry Potter and the Philosopher's Stone_4", "Joanne Rowling", 1997));

            List <CopyDetails> copyDetailsList = new List <CopyDetails>();

            copyDetailsList.Add(new CopyDetails(books[0], 24.5m, 3.4m, 3, "short description 0"));
            copyDetailsList.Add(new CopyDetails(books[1], 14.59m, 2.4m, 1, "short description 1"));
            copyDetailsList.Add(new CopyDetails(books[2], 26.45m, 1.4m, 3, "short description 2"));
            copyDetailsList.Add(new CopyDetails(books[3], 246.99m, 35.4m, 5, "short description 3"));
            copyDetailsList.Add(new CopyDetails(books[4], 134.5m, 13.4m, 1, "short description 4"));


            List <Event> events = new List <Event>();

            events.Add(new Invoice(clients[0], copyDetailsList[0],
                                   new DateTime(2006, 4, 14, 2, 34, 44), "short description 0"));
            events.Add(new Invoice(clients[1], copyDetailsList[1],
                                   new DateTime(2007, 5, 4, 12, 24, 4), "short description 1"));
            events.Add(new Invoice(clients[2], copyDetailsList[2],
                                   new DateTime(2004, 9, 5, 1, 14, 54), "short description 2"));
            events.Add(new Invoice(clients[3], copyDetailsList[3],
                                   new DateTime(2008, 10, 10, 8, 39, 33), "short description 3"));
            events.Add(new Invoice(clients[4], copyDetailsList[4],
                                   new DateTime(2010, 1, 6, 3, 38, 14), "short description 4"));
            events.Add(new Reclamation(new DateTime(2006, 4, 17, 2, 34, 44),
                                       events[0] as Invoice, "short description for the reclamation"));

            for (int i = 0; i < events.Count; i++)
            {
                Assert.True(events[i].Equals(dataRepository.GetEvent(i)));
            }
        }
Ejemplo n.º 16
0
        public void FindCopyDetailsInvalidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Book b1 = new Book("Year 1984", "George Orwell", 1949);

            CopyDetails cd1 = new CopyDetails(b1, new decimal(35.99), new decimal(2.65), 1, "short description");

            Assert.Throws <ArgumentException>(() => (dataRepository.FindCopyDetails(cd1)) as object);
        }
Ejemplo n.º 17
0
        public void UpdateBookStockTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);
            CopyDetails     copyDetails        = dataRepository.GetCopyDetails(0);

            dataService.UpdateBookStock(copyDetails, 1);

            Assert.Equal(1, dataRepository.GetCopyDetails(0).Count);
        }
Ejemplo n.º 18
0
        public void DeleteBookValidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            Book            book = new Book("Year 1984", "George Orwell", 1949);

            dataRepository.AddBook(book);
            Assert.Equal(6, dataRepository.GetAllBooks().Count());
            dataRepository.DeleteBook(book);
            Assert.Equal(5, dataRepository.GetAllBooks().Count());
        }
Ejemplo n.º 19
0
        public void FindClientInvalidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            const string email       = "student.gmail.com";
            const string firstName   = "Lolek";
            const string secondName  = "Bolek";
            const string phoneNumber = "123456789";
            Client       client      = new Client(email, firstName, secondName, phoneNumber);

            Assert.Throws <ArgumentException>(() => dataRepository.FindClient(client) as object);
        }
Ejemplo n.º 20
0
        public void FindClientCopyDetailsValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Book b1 = new Book("Year 1984", "George Orwell", 1949);

            CopyDetails cd1 = new CopyDetails(b1, new decimal(35.99), new decimal(2.65), 1, "short description");

            dataRepository.AddCopyDetails(cd1);

            Assert.StrictEqual(5, dataRepository.FindCopyDetails(cd1));
        }
Ejemplo n.º 21
0
        public void DeleteCopyDetailsInvalidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Book b1 = new Book("Year 1984", "George Orwell", 1949);

            CopyDetails cd1 = new CopyDetails(b1, new decimal(35.99), new decimal(2.65), 1, "short description");


            Assert.Equal(5, dataRepository.GetAllCopyDetails().Count());
            Assert.Throws <ArgumentException>(() => dataRepository.DeleteCopyDetails(cd1));
        }
Ejemplo n.º 22
0
        public void GetCopyDetailsValidValue()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Book b1 = new Book("Year 1984", "George Orwell", 1949);

            CopyDetails cd1 = new CopyDetails(b1, new decimal(35.99), new decimal(2.65), 1, "short description");

            dataRepository.AddCopyDetails(cd1);

            Assert.NotNull(dataRepository.GetCopyDetails(dataRepository.FindCopyDetails(cd1)));
        }
Ejemplo n.º 23
0
        public void AddBookTest()
        {
            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);

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

            dataService.AddBook(book);
            Assert.Equal(booksNumber + 1, dataService.GetBooks().ToImmutableHashSet().Count);
            Assert.Equal(book, dataService.GetBooks().Last());
        }
Ejemplo n.º 24
0
        public void UpdateClientTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Client client = dataRepository.GetClient(0);

            client.Email = "*****@*****.**";

            dataService.UpdateClient(client);

            Assert.Equal("*****@*****.**", dataService.GetClients().First().Email);
        }
Ejemplo n.º 25
0
        public void AddClientTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Client client = new Client("*****@*****.**", "Michał", "Kopytko", "8462");

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

            dataService.AddClient(client);
            Assert.Equal(clientsNumber + 1, dataService.GetClients().ToImmutableHashSet().Count);
            Assert.Equal(client, dataService.GetClients().Last());
        }
Ejemplo n.º 26
0
        public void FindClientValidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            const string email       = "student.gmail.com";
            const string firstName   = "Lolek";
            const string secondName  = "Bolek";
            const string phoneNumber = "123456789";
            Client       client      = new Client(email, firstName, secondName, phoneNumber);

            dataRepository.AddClient(client);
            Assert.StrictEqual(5, dataRepository.FindClient(client));
        }
Ejemplo n.º 27
0
        public void UpdateBookTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            Book book = dataRepository.GetBook(0);

            book.BookName = "W pustyni i w puszczy";

            dataService.UpdateBook(book);

            Assert.Equal("W pustyni i w puszczy", dataService.GetBooks().First().BookName);
        }
Ejemplo n.º 28
0
        public void AddCopyDetailsTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            CopyDetails copyDetails =
                new CopyDetails(dataRepository.GetBook(3), 15.60m, 2.60m, 2, "Sample book invoice");
            int copyDetailsNumber = dataService.GetAllCopyDetails().ToImmutableHashSet().Count;

            dataService.AddCopyDetails(copyDetails);
            Assert.Equal(copyDetailsNumber + 1, dataService.GetAllCopyDetails().ToImmutableHashSet().Count);
            Assert.Equal(copyDetails, dataService.GetAllCopyDetails().Last());
        }
Ejemplo n.º 29
0
        public void UpdateCopyDetailsTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepositoryForTest(constantDataFiller);
            IDataService    dataService        = new DataService(dataRepository);

            CopyDetails copyDetails = dataRepository.GetCopyDetails(0);

            copyDetails.Count = 999;

            dataService.UpdateCopyDetails(copyDetails);

            Assert.Equal(999, dataService.GetAllCopyDetails().First().Count);
        }
Ejemplo n.º 30
0
        public void AddCopyDetailsValidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Book b1 = new Book("Year 1984", "George Orwell", 1949);

            CopyDetails cd1 = new CopyDetails(b1, new decimal(35.99), new decimal(2.65), 1, "short description");

            dataRepository.AddCopyDetails(cd1);

            Assert.Equal(6, dataRepository.GetAllCopyDetails().Count());
            Assert.Equal(cd1, dataRepository.GetCopyDetails(5));
        }