public UpdateCounty(int countyId, UpdateCountyModel county) { County = new CountyModel { Id = countyId, Name = county.Name, Code = county.Code, Diaspora = county.Diaspora, Order = county.Order, NumberOfPollingStations = county.NumberOfPollingStations }; }
public async Task <IActionResult> UpdateCountyAsync(int countyId, [FromBody] UpdateCountyModel county) { var response = await _mediator.Send(new UpdateCounty(countyId, county)); if (response.IsSuccess) { return(Ok()); } return(BadRequest(new ErrorModel { Message = response.Error })); }
public async Task When_updating_county_by_existent_id() { using (var context = new VoteMonitorContext(_dbContextOptions)) { context.Counties.Add(new County { Code = "Code1", Diaspora = false, Id = 1, Name = "Name1", Order = 12, NumberOfPollingStations = 14 }); context.Counties.Add(new County { Code = "Code2", Diaspora = true, Id = 2, Name = "Name2", Order = 3, NumberOfPollingStations = 2 }); context.Counties.Add(new County { Code = "Code3", Diaspora = true, Id = 3, Name = "Name3", Order = 1, NumberOfPollingStations = 2 }); context.SaveChanges(); } using (var context = new VoteMonitorContext(_dbContextOptions)) { var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper); var updateCountyModel = new UpdateCountyModel() { Name = "Super Iasi", Code = "IS", Order = 33, Diaspora = false, NumberOfPollingStations = 767 }; var county = await countiesCommandHandler.Handle(new UpdateCounty(2, updateCountyModel), new CancellationToken(false)); county.IsSuccess.ShouldBeTrue(); context.Counties.Count().ShouldBe(3); var updatedCounty = await context.Counties.FirstOrDefaultAsync(x => x.Id == 2); updatedCounty.ShouldNotBeNull(); updatedCounty.Id.ShouldBe(2); updatedCounty.Code.ShouldBe("IS"); updatedCounty.Name.ShouldBe("Super Iasi"); updatedCounty.NumberOfPollingStations.ShouldBe(767); updatedCounty.Diaspora.ShouldBe(false); updatedCounty.Order.ShouldBe(33); } }