public async Task Handle_Given_InValidRequest_PatientId_Should_Not_EditPatient() { // Arrange var patientId = Guid.NewGuid(); var hospitalId = Guid.NewGuid(); var command = new EditPatient.Command(patientId, "Lokesh Chandawar", DateTime.Now, 0, new Address("Vanaz cornor, Kothrud", "Pune", "Maharashtra", "410038"), "9021433312", hospitalId); var mockAppDbRepository = new Mock <IAppDbRepository>(); var mockNotificationService = new Mock <INotificationService>(); mockNotificationService .Setup(x => x.Send(It.IsAny <Message>())); mockAppDbRepository .Setup(x => x.GetPatientByIdAsync(It.IsAny <Guid>())) .ReturnsAsync((Patient)null); mockAppDbRepository .Setup(x => x.GetHospitalByIdAsync(It.IsAny <Guid>())) .ReturnsAsync((Hospital)null); mockAppDbRepository .Setup(x => x.EditHospitalByIdAsync(It.IsAny <Guid>(), It.IsAny <Hospital>())) .Returns(Task.CompletedTask); var handler = new EditPatient.Handler(mockAppDbRepository.Object, mockNotificationService.Object); // Act // Assert await Assert.ThrowsAsync <NotFoundException>(() => handler.Handle(command, new CancellationToken())); }
public async Task Handle_Given_ValidRequest_Should_EditPatient() { // Arrange var patientId = Guid.NewGuid(); var hospitalId = Guid.NewGuid(); var command = new EditPatient.Command(patientId, "Lokesh Chandawar", DateTime.Now, 0, new Address("Vanaz cornor, Kothrud", "Pune", "Maharashtra", "410038"), "9021433312", hospitalId); var mockAppDbRepository = new Mock <IAppDbRepository>(); var mockNotificationService = new Mock <INotificationService>(); mockNotificationService .Setup(x => x.Send(It.IsAny <Message>())); mockAppDbRepository .Setup(x => x.GetPatientByIdAsync(It.IsAny <Guid>())) .ReturnsAsync( new Patient { PatientId = patientId }); 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 EditPatient.Handler(mockAppDbRepository.Object, mockNotificationService.Object); // Act var result = await handler.Handle(command, new CancellationToken()); // Assert Assert.True(result.Equals(patientId)); }