Exemplo n.º 1
0
        public ActionResult Post([FromBody] CarAdvertRequestModel requestModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var carAdvert = mapper.Map <CarAdvert>(requestModel);

            carAdvertService.Add(carAdvert);

            return(CreatedAtAction("Get", requestModel));
        }
Exemplo n.º 2
0
        public ActionResult Put(Guid id, [FromBody] CarAdvertRequestModel requestModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var carAdvert = carAdvertService.GetById(id);

            if (carAdvert == null)
            {
                return(NotFound());
            }

            mapper.Map(requestModel, carAdvert);
            carAdvertService.Update(carAdvert);
            return(NoContent());
        }
        public void Add_ValidObjectPassed_ReturnedResponseHasCreatedItem()
        {
            // Arrange
            var validCarAdvert = new CarAdvertRequestModel()
            {
                Title = "ValidObjectPassed",
                Fuel  = FuelType.Diesel,
                Price = 50000,
                New   = true,
            };
            var controller = GetSUT("Add_ValidObjectPassed_ReturnedResponseHasCreatedItem");

            // Act
            var createdResponse = controller.Post(validCarAdvert) as CreatedAtActionResult;
            var createdItem     = createdResponse.Value as CarAdvertRequestModel;

            // Assert
            Assert.IsType <CreatedAtActionResult>(createdResponse);
            Assert.Equal("ValidObjectPassed", createdItem.Title);
        }