public async Task <CreateCircuitViewModel> AddCircuit([FromBody] CreateCircuitViewModel pCircuitViewModel) { if (!ModelState.IsValid) { pCircuitViewModel.Errors = ModelState.Values.SelectMany(val => val.Errors).Select(err => err.ErrorMessage).ToList(); return(pCircuitViewModel); } var lDto = Mapping.Mapper.Map <CreateCircuitDto>(pCircuitViewModel); var lReturnedDto = await this._referenceServices.CreateCircuit(lDto); return(Mapping.Mapper.Map <CreateCircuitViewModel>(lReturnedDto)); }
public async Task AddCircuit_Error() { // Arrange CreateCircuitViewModel lCreateCircuitViewModel = new CreateCircuitViewModel() { Name = "England" }; this.submissionController.ModelState.AddModelError("aa", "error"); var lResult = await this.submissionController.AddCircuit(lCreateCircuitViewModel); // Assert Assert.AreEqual("England", lResult.Name); Assert.IsNull(lResult.Id); await this._referenceServices.Received(0).CreateCircuit(Arg.Any <CreateCircuitDto>()); }
public async Task AddCircuit() { // Arrange this._referenceServices.CreateCircuit(Arg.Any <CreateCircuitDto>()).Returns(new CreateCircuitDto { Id = 50 }); CreateCircuitViewModel lCreateCircuitViewModel = new CreateCircuitViewModel() { Name = "England" }; // Act var lResult = await this.submissionController.AddCircuit(lCreateCircuitViewModel); // Assert Assert.AreEqual(50, lResult.Id); await this._referenceServices.Received(1).CreateCircuit(Arg.Is <CreateCircuitDto>(dto => dto.Name == "England")); }