public void BackMappingTest() { // Check model to entity mapping is correct var model = new CarModel() { Id = generator.Next(1, 10000), Name = Guid.NewGuid().ToString("N"), Description = Guid.NewGuid().ToString("N") }; var entity = mapper.Back(model); Assert.AreEqual(model.Id, entity.PublicId); Assert.AreEqual(model.Name, entity.Name); Assert.AreEqual(model.Description, entity.Description); // Set triggers on entity and model property list changed. Test must fail in this case Assert.AreEqual(4, GetPropertiesCount(entity), $"Property list at class '{ nameof(Car) }' changed. Test must be updated"); Assert.AreEqual(3, GetPropertiesCount(model), $"Property list at class '{ model.GetType().Name }' changed. Test must be updated"); }
public async Task <IActionResult> Add([FromBody] CarModel value) { var carItem = carMapper.Back(value); try { await carsService.Add(carItem); return(Ok()); } catch (ValidationException ex) { return(BadRequest(ex.Message)); } }