Exemplo n.º 1
0
        public async Task Create_ShouldCreated()
        {
            var oldCount = Rents.Count;
            var rent     = new RentDto()
            {
                Id         = Random.Next(int.MaxValue),
                Count      = 5,
                IsActive   = true,
                Book       = Mapper.Map <BookDto>(DefaultData.Books.ClrVia),
                Subscriber = Mapper.Map <SubscriberDto>(DefaultData.Subscribers.Maslov),
                Date       = DateTime.Now
            };
            await RentsService.Create(rent);

            Assert.That(Rents.Count, Is.EqualTo(oldCount + 1));
            var created = Rents.SingleOrDefault(x => x.Id == rent.Id);

            Assert.That(created, Is.Not.Null);
            Assert.That(created.Count, Is.EqualTo(rent.Count));
            Assert.That(created.IsActive, Is.EqualTo(rent.IsActive));
            Assert.That(created.Date, Is.EqualTo(created.Date));

            Assert.That(created.Subscriber.Fio, Is.EqualTo(rent.Subscriber.ToString()));
            Assert.That(created.Book.Id, Is.EqualTo(rent.Book.Id));
        }
Exemplo n.º 2
0
        public void Create_SubscriberNull_ShouldThrowRentNotHasBookOrSubscriberException()
        {
            var rent = new RentDto()
            {
                Id       = Random.Next(int.MaxValue),
                Count    = 55,
                IsActive = true,
                Book     = Mapper.Map <BookDto>(DefaultData.Books.ClrVia),
                Date     = DateTime.Now
            };

            Assert.Throws <RentNotHasBookOrSubscriberException>(async() => await RentsService.Create(rent));
        }
Exemplo n.º 3
0
        public void Create_CountMoreCountOfBooks_ShouldThrownRentCountMoreCountOfBookException()
        {
            var rent = new RentDto()
            {
                Id         = Random.Next(int.MaxValue),
                Count      = DefaultData.Books.ClrVia.Count + 1,
                IsActive   = true,
                Book       = Mapper.Map <BookDto>(DefaultData.Books.ClrVia),
                Subscriber = Mapper.Map <SubscriberDto>(DefaultData.Subscribers.Maslov),
                Date       = DateTime.Now
            };

            Assert.Throws <RentCountMoreCountOfBookException>(async() => await RentsService.Create(rent));
        }
Exemplo n.º 4
0
        public void Create_BookNotHasAvailableCount_ShouldThrownBookNotHasAvailableCountException()
        {
            var book     = Books.First();
            var reserved = Rents.Where(x => x.Book.Id == book.Id).Sum(x => x.Count);

            Rents.Add(new Rent(book, Subscribers.First(), book.Count - reserved)
            {
                Id   = Random.Next(int.MaxValue),
                Date = DateTime.Now,
            });

            var dto = new RentDto()
            {
                Subscriber = Mapper.Map <SubscriberDto>(Subscribers.First()),
                Book       = Mapper.Map <BookDto>(book),
                Count      = 1,
                Date       = DateTime.Now,
            };

            Assert.Throws <NotHasAvailableBooksCountException>(async() => await RentsService.Create(dto));
        }