Ejemplo n.º 1
0
        public void BorrowingOperations()
        {
            IDataReaderFromFile reader = null;
            IDataRepository     repo   = new DataRepository(reader);
            Random rnd = new Random();
            string title1 = "Dziady", title2 = "Wiersze", author1 = "Adam Mickiewicz", author2 = "Jan Brzechwa";
            string name1 = "Jan", name2 = "Piotr", lastName1 = "Kowalski", lastName2 = "Nowak";

            repo.AddReader(name1, lastName1);
            repo.AddReader(name2, lastName2);
            int    stock    = rnd.Next(10, 128);
            double prize    = rnd.NextDouble() * 30;
            string currency = "USD";

            repo.AddBookItem(title1, author1);
            repo.AddBookItem(title2, author2);
            int bookKey = repo.GetKey() - rnd.Next(1, 2);

            repo.AddCopyInfo(bookKey, stock, prize, currency);
            stock    = rnd.Next(10, 128);
            prize    = rnd.NextDouble() * 30;
            currency = "PLN";
            bookKey  = repo.GetKey() - rnd.Next(1, 2);
            repo.AddCopyInfo(bookKey, stock, prize, currency);
            Assert.Equal(2, repo.GetReadersCount());
            Assert.Equal(2, repo.GetBookItemsCount());
            Assert.Equal(2, repo.GetCopyInfosCount());
            int tmp1 = rnd.Next(1, repo.GetReadersCount());
            int tmp2 = rnd.Next(1, repo.GetCopyInfosCount());

            repo.AddBorrowing(tmp1, tmp2);
            Assert.True(repo.IsBorrowing(0));
            Assert.Equal(tmp2, repo.GetCopyInfoFromBorrowing(0));
            Assert.NotEmpty(repo.GetInfo("borrowings")[0]);
            tmp1 = rnd.Next(1, repo.GetReadersCount());
            tmp2 = rnd.Next(1, repo.GetCopyInfosCount());
            DateTime date1 = new DateTime(1995, 1, 1);

            date1 = date1.AddDays(rnd.Next(200, 1000));
            repo.AddBorrowing(tmp1, tmp2, date1);
            Assert.Equal(1, repo.FindEvent(tmp1, tmp2, date1));
            tmp1 = rnd.Next(1, repo.GetReadersCount());
            tmp2 = rnd.Next(1, repo.GetCopyInfosCount());
            date1.AddDays(rnd.Next(200, 1000));
            DateTime date2 = date1.AddDays(rnd.Next(1, 100));

            repo.AddBorrowing(tmp1, tmp2, date1, date2);
            Assert.False(repo.IsBorrowingReturned(1));
            repo.SetBorrowingEndDate(1, DateTime.Now);
            Assert.True(repo.IsBorrowingReturned(1));
            repo.AddPurchase(0, 0);
            repo.AddPurchase(0, 1, date2);
            Assert.False(repo.IsBorrowing(3));
            Assert.Contains("Purchase", repo.GetInfo("events")[3]);
            Assert.Equal(5, repo.GetEventsCount());
        }
Ejemplo n.º 2
0
        public void AddBorrowingTest()
        {
            DataRepository dataRepository = new DataRepository(new ConstFiller());
            Reader         reader         = new Reader("Jan", "Kowalski", 1);
            Book           book           = new Book(1, "Ksiega Dzungli");
            State          state          = new State(book, 10);

            Borrowing borrowing = new Borrowing(reader, new DateTime(2018, 3, 4), state);

            dataRepository.AddBorrowing(borrowing);

            Assert.AreEqual(borrowing.GetHashCode(), dataRepository.GetBorrowing(1, 1).GetHashCode());
        }
Ejemplo n.º 3
0
        public void GetAllBorrowingTest()
        {
            DataRepository dataRepository = new DataRepository();
            Reader         reader         = new Reader("Jan", "Kowalski", 1);
            Book           book           = new Book(1, "Ksiega Dzungli");
            State          state          = new State(book, 10);

            Borrowing borrowing = new Borrowing(reader, new DateTime(2018, 3, 4), state);

            Reader    reader2    = new Reader("John", "Smith", 2);
            Borrowing borrowing2 = new Borrowing(reader2, new DateTime(2018, 3, 4), state);

            dataRepository.AddBorrowing(borrowing);
            dataRepository.AddBorrowing(borrowing2);

            ObservableCollection <Borrowing> collection = dataRepository.GetAllBorrowing();

            Borrowing tmp1 = collection.First();
            Borrowing tmp2 = collection[1];

            Assert.AreEqual(tmp1.GetHashCode(), borrowing.GetHashCode());
            Assert.AreEqual(tmp2.GetHashCode(), borrowing2.GetHashCode());
        }
Ejemplo n.º 4
0
        public void DeleteBorrowingTest()
        {
            DataRepository dataRepository = new DataRepository();
            Reader         reader         = new Reader("Jan", "Kowalski", 1);
            Book           book           = new Book(1, "Ksiega Dzungli");
            State          state          = new State(book, 10);

            Borrowing borrowing = new Borrowing(reader, new DateTime(2018, 3, 4), state);

            dataRepository.AddBorrowing(borrowing);

            dataRepository.DeleteBorrowing(borrowing);

            Assert.IsNull(dataRepository.GetBorrowing(1, 1));
        }
Ejemplo n.º 5
0
        public void UpdateBorrowingTest()
        {
            DataRepository dataRepository = new DataRepository();

            Reader reader = new Reader("Jan", "Kowalski", 1);
            Book   book   = new Book(1, "Ksiega Dzungli");
            State  state  = new State(book, 10);

            Borrowing borrowing = new Borrowing(reader, new DateTime(2018, 3, 4), state);

            dataRepository.AddBorrowing(borrowing);

            Reader    reader_modified    = new Reader("Janusz", "Nowak", 2);
            Borrowing borrowing_modified = new Borrowing(reader_modified, new DateTime(2018, 3, 4), state);

            dataRepository.UpdateBorrowing(1, 1, borrowing_modified);

            Assert.AreEqual(borrowing_modified.GetHashCode(), dataRepository.GetBorrowing(2, 1).GetHashCode());
        }