Exemplo n.º 1
0
        public void LibrarianReposTest()
        {
            Start();
            LibrarianRepos librarianRepos = new LibrarianRepos(new LibraryContext(connectionOption));

            //Информация о книгах
            int Id = librarianRepos.AllBooks.ElementAt(1).Id;

            Assert.IsTrue(librarianRepos.BusyBooks.ElementAt(0).IsBusy);
            Assert.IsFalse(librarianRepos.FreeBooks.ElementAt(0).IsBusy);
            Assert.IsTrue(librarianRepos.GivenBooks.ElementAt(0).IsBorrow);
            Assert.AreEqual(librarianRepos.GetBook(Id).Title, "title2");

            //Удалить, добавить
            librarianRepos.AddBook(new Book()
            {
                Title = "12345", Author = "author3", Publisher = "publisher3", Genre = "genre3", IsBusy = true, IsBorrow = true
            });
            var book = librarianRepos.BookForTitle("12").First();

            Assert.AreEqual(book.Author, "author3");

            librarianRepos.RemoveBook(book.Id);
            Assert.IsNull(librarianRepos.BookForTitle("12").FirstOrDefault());
            Assert.IsNotNull(librarianRepos.BookForTitle("123"));

            //Сдача и приёмка
            librarianRepos.GiveBook(new History(1, Id, 20));
            Assert.IsTrue(librarianRepos.GetBook(Id).IsBorrow);

            librarianRepos.InitialAcceptBook(Id, 1);
            librarianRepos.AcceptBook(Id, 1, "Порвано");

            Assert.AreEqual(librarianRepos.GetBook(Id).State, "Порвано");
            Assert.IsTrue(librarianRepos.GetHistory(0, 1).FirstOrDefault().Damage);
            Assert.AreEqual(librarianRepos.GetHistory(0, 1).First().BookingTimeLib, 20);

            //Штрафы, просроченные сроки, aккаунты и история
            var users = librarianRepos.Users;

            Assert.IsTrue(users.Count() > 0);
            int accountId = users.ElementAt(0).Id;

            librarianRepos.ChargeFine(accountId, 200);
            Assert.IsTrue(librarianRepos.GetAccount(accountId).Penalty == 200);

            Assert.IsTrue(librarianRepos.DeadlineOverdue(2, 1) == 1);

            librarianRepos.PayOffFine(accountId, 100);
            Assert.IsTrue(librarianRepos.GetAccount(accountId).Penalty == 100);
            End();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            LibrarianRepos librarianRepos = new LibrarianRepos(new LibraryContext(new DbContextOptionsBuilder
                                                                                  <LibraryContext>().UseSqlServer
                                                                                      (@"Server=(localdb)\mssqllocaldb;Database=
                testdb;Trusted_Connection=True;").Options));

            librarianRepos.AddBook(new Library.Infrastructure.Bll.Data.Book()
            {
                Title = "@d"
            });
            Console.WriteLine("Hello World!");
        }