public void SerializeToFileCustom()
        {
            DataRepository  repo     = new DataRepository();
            Book            bok      = new Book("kartofle", "stefan");
            Book            bok2     = new Book("kartofle2", "stefan2");
            BookDescription bokDesc  = new BookDescription("bla", bok);
            BookDescription bokDesc2 = new BookDescription("bla2", bok2);
            Reader          red      = new Reader("zenek", "cos", 666126161);
            Reader          red2     = new Reader("zenek2", "cos2", 40445454);
            Borrow          bor      = new Borrow(red, bokDesc);

            repo.AddReader(red);
            repo.AddReader(red2);
            repo.AddBook(bok);
            repo.AddBook(bok2);
            repo.AddBookDescription(bokDesc);
            repo.AddBookDescription(bokDesc2);
            repo.AddBorrow(bor);
            repo.AddBookNumber(bokDesc, 5000);


            repo.SaveDataCustom("saveData");

            DataRepository repo2 = new DataRepository();

            repo2.LoadDataCustom("saveData");

            Assert.IsTrue(CheckIfSame(repo, repo2));
        }
        public void AddBorrowTest()
        {
            DataRepository dataRepository = new DataRepository();
            var            MockBorrow     = RandomBorrow();

            dataRepository.AddBorrow(MockBorrow.Object);

            var         data        = typeof(DataRepository).GetField("Data", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            DataContext dataContext = (DataContext)data.GetValue(dataRepository);

            Assert.AreEqual(1, dataContext.Borrows.Count());
        }
        public void BorrowConsoleNotificationAdd()
        {
            DataRepository dataRepository = new DataRepository();
            var            MockBorrow     = RandomBorrow();
            String         expectedOut    = "Change type: Add\r\nItems added: \r\nMOCK BORROW\r\n";;

            using (var consoleLogger = new ConsoleMiddleman())
            {
                dataRepository.AddBorrow(MockBorrow.Object);
                Assert.IsFalse(String.IsNullOrEmpty(consoleLogger.GetOuput()));
                Assert.IsTrue(String.Equals(expectedOut, consoleLogger.GetOuput()));
            }
            Console.Write(expectedOut);
        }
        public void GetAllBorrowsTest()
        {
            const int      NUMBER_OF_BORROWS = 500;
            DataRepository dataRepository    = new DataRepository();
            var            ExpectedBorowList = new List <Borrow>();

            for (int i = 0; i < NUMBER_OF_BORROWS; i++)
            {
                var MockBorrow = RandomBorrow();

                dataRepository.AddBorrow(MockBorrow.Object);
                ExpectedBorowList.Add(MockBorrow.Object);
            }

            Assert.IsTrue(ExpectedBorowList.SequenceEqual(dataRepository.GetAllBorrows()));
        }
        public void UpdateBorrowTest()
        {
            //preperation is the same as in addBorrow
            DataRepository dataRepository = new DataRepository();
            var            MockBorrow1    = RandomBorrow();
            var            MockBorrow2    = RandomBorrow();

            dataRepository.AddBorrow(MockBorrow1.Object);
            Borrow borrow = dataRepository.GetBorrow(0);

            Assert.AreEqual(borrow, MockBorrow1.Object);

            //test if book can be changed

            dataRepository.UpdateBorrow(0, MockBorrow2.Object);

            Assert.AreEqual(MockBorrow2.Object, dataRepository.GetBorrow(0));
        }
        public void DeleteBorrowTest()
        {
            DataRepository dataRepository = new DataRepository();
            var            MockBorrow     = RandomBorrow();

            dataRepository.AddBorrow(MockBorrow.Object);
            Borrow borrow = dataRepository.GetBorrow(0);

            Assert.AreEqual(borrow, MockBorrow.Object);

            dataRepository.DeleteBorrow(0);

            //Test reflected object
            var         data        = typeof(DataRepository).GetField("Data", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            DataContext dataContext = (DataContext)data.GetValue(dataRepository);

            Assert.AreEqual(0, dataContext.Borrows.Count());

            //Test object given by getAllBooks method
            Assert.AreEqual(0, dataRepository.GetAllBorrows().Count());
        }