Exemplo n.º 1
0
 public DataRepository(IDataReaderFromFile dataReader)
 {
     id = Guid.NewGuid();
     this.dataReader  = dataReader;
     this.dataContext = new DataContext();
     this.key         = 0;
 }
Exemplo n.º 2
0
        public void CopyInfoOperations()
        {
            IDataReaderFromFile reader = null;
            IDataRepository     repo   = new DataRepository(reader);
            Random rnd = new Random();
            string title1 = "Dziady", title2 = "Wiersze", author1 = "Adam Mickiewicz", author2 = "Jan Brzechwa";
            int    stock    = rnd.Next(10, 128);
            double prize    = rnd.NextDouble() * 30;
            string currency = "USD";

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

            repo.AddCopyInfo(bookKey, stock, prize, currency);
            Assert.Equal(0, repo.FindExistedCopies(bookKey, prize, currency));
            stock    = rnd.Next(10, 128);
            prize    = rnd.NextDouble() * 30;
            currency = "PLN";
            bookKey  = repo.GetKey() - rnd.Next(1, 2);
            repo.UpdateCopyInfo(0, bookKey, stock, prize, currency);
            Assert.Equal(0, repo.FindExistedCopies(bookKey, prize, currency));
            int tmp  = repo.GetCopyInfoStock(0);
            int tmp2 = rnd.Next(100);

            repo.IncrementCopyInfoStock(0, tmp2);
            Assert.Equal(tmp + tmp2, repo.GetCopyInfoStock(0));
            repo.RemoveCopyInfo(0);
            Assert.Equal(0, repo.GetCopyInfosCount());
            Assert.Equal(2, repo.GetBookItemsCount());
        }
Exemplo n.º 3
0
        public void BookItemOperations()
        {
            IDataReaderFromFile reader = null;
            IDataRepository     repo = new DataRepository(reader);
            string title1 = "Dziady", title2 = "Wiersze", author1 = "Adam Mickiewicz", author2 = "Jan Brzechwa";

            repo.AddBookItem(title1, author1);
            Assert.Equal(repo.GetKey() - 1, repo.FindBookItem(title1, author1));
            repo.UpdateBookItem(repo.GetKey() - 1, title2, author2);
            Assert.Equal(repo.GetKey() - 1, repo.FindBookItem(title2, author2));
            Assert.True(repo.BookExist(repo.GetKey() - 1));
            repo.RemoveBookItem(repo.GetKey() - 1);
            Assert.False(repo.BookExist(repo.GetKey() - 1));
            Assert.Equal(0, repo.GetBookItemsCount());
            Random rnd = new Random();
            int    tmp = rnd.Next(2, 256);
            int    startKey = repo.GetKey();

            for (int i = 0; i < tmp; i++)
            {
                repo.AddBookItem("Test" + i.ToString(), "Sample");
            }
            Assert.Equal(tmp, repo.GetBookItemsCount());
            tmp = rnd.Next(tmp - 1);
            Assert.Equal(tmp + startKey, repo.FindBookItem("Test" + tmp.ToString(), "Sample"));
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        public void ReaderOperations()
        {
            IDataReaderFromFile fileReader = null;
            IDataRepository     repo = new DataRepository(fileReader);
            string name1 = "Jan", name2 = "Piotr", lastName1 = "Kowalski", lastName2 = "Nowak";

            repo.AddReader(name1, lastName1);
            Assert.Equal(0, repo.FindReader(name1, lastName1));
            repo.UpdateReader(0, name2, lastName2);
            Assert.Equal(0, repo.FindReader(name2, lastName2));
            repo.RemoveReader(0);
            Assert.Equal(0, repo.GetReadersCount());
            Random rnd = new Random();
            int    tmp = rnd.Next(2, 256);

            for (int i = 0; i < tmp; i++)
            {
                repo.AddReader("Test" + i.ToString(), "Sample");
            }
            Assert.Equal(tmp, repo.GetReadersCount());
            tmp = rnd.Next(tmp - 1);
            Assert.Equal(tmp, repo.FindReader("Test" + tmp.ToString(), "Sample"));
        }