public void CreatePropertyTest() { var properties = _realStateAPIRepository.GetProperties(); var lastProperty = properties[properties.Count - 1]; Property property = new Property { Name = "Property Test", Address = "Test 123", CodeInternal = "123ABC", Price = 1500, Views = 0, Year = 2015, IdOwner = 1 }; _realStateAPIRepository.CreateProperty(property); _realStateAPIRepository.Save(); var propertyCreated = _realStateAPIRepository.GetPropertyById(lastProperty.IdProperty + 1); Assert.AreEqual(property, propertyCreated); Assert.Pass(); }
public ActionResult <PropertyDTO> CreateProperty([FromBody] PropertyDTO propertyCreation) { try { Property property = _mapper.Map <Property>(propertyCreation); _realStateAPIRepository.CreateProperty(property); _realStateAPIRepository.Save(); PropertyDTO propertyDTO = _mapper.Map <PropertyDTO>(property); return(new CreatedAtRouteResult("GetPropertyById", new { idProperty = property.IdProperty }, propertyDTO)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }