public async Task Handle_Given_ValidRequest_Should_EditHospital() { // Arrange var hospitalId = new Guid(); var command = new EditHospital.Command(hospitalId, "Lokesh Chandawar", new Address("Vanaz cornor, Kothrud", "Pune", "Maharashtra", "410038"), "9021433312"); var mockAppDbRepository = new Mock <IAppDbRepository>(); mockAppDbRepository .Setup(x => x.GetHospitalByIdAsync(It.IsAny <Guid>())) .ReturnsAsync( new Hospital { HospitalId = hospitalId }); mockAppDbRepository .Setup(x => x.EditHospitalByIdAsync(It.IsAny <Guid>(), It.IsAny <Hospital>())) .Returns(Task.CompletedTask); var handler = new EditHospital.Handler(mockAppDbRepository.Object); // Act var result = await handler.Handle(command, new CancellationToken()); // Assert Assert.True(result.Equals(hospitalId)); }
public async Task <ActionResult <Guid> > EditHospitalAsync([FromRoute] Guid hospitalId, [FromBody] EditHospital.Command command) { if (hospitalId == command.Id) { return(await Mediator.Send(command)); } ModelState.AddModelError(nameof(command.Id), "Id should be match"); return(BadRequest()); }