Exemplo n.º 1
0
        public ActionResult <RentalOutputDto> Post([FromBody] AddRentalInputDto dto)
        {
            var rental            = _mapper.Map <Rental>(dto);
            var insertedRental    = _rentalRepository.Insert(rental);
            var insertedRentalDto = _mapper.Map <RentalOutputDto>(insertedRental);

            return(StatusCode(201, insertedRentalDto));
        }
        public void Map_Rental_Input()
        {
            //Arrange
            var sut            = _mapperConfiguration.CreateMapper();
            var rentalInputDto = new AddRentalInputDto
            {
                UserId = 1,
                BookId = 2,
                Issued = DateTime.Now
            };

            //Act
            var rental = sut.Map <Rental>(rentalInputDto);

            //Assert
            Assert.That(rental.Book.Id, Is.EqualTo(rentalInputDto.BookId));
            Assert.That(rental.User.Id, Is.EqualTo(rentalInputDto.UserId));
            Assert.That(rental.Issued, Is.EqualTo(rentalInputDto.Issued));
            Assert.That(rental.Id, Is.EqualTo(0));
            Assert.That(rental.Returned, Is.Null);
        }