public async Task Handle_Given_ValidRequest_Should_SavePatient() { // Arrange var hospitalId = Guid.NewGuid(); var command = new SavePatient.Command("Lokesh Chandawar", DateTime.Now, 0, new Address("Vanaz cornor, Kothrud", "Pune", "Maharashtra", "410038"), "9021433312"); var mockAppDbRepository = new Mock <IAppDbRepository>(); var mockNotificationService = new Mock <INotificationService>(); mockNotificationService .Setup(x => x.Send(It.IsAny <Message>())); mockAppDbRepository .Setup(x => x.GetPatientIdByMobileNumberAsync(It.IsAny <string>())) .ReturnsAsync( (Patient)null); mockAppDbRepository .Setup(x => x.GetHospitalIdByZipCode(It.IsAny <string>())) .ReturnsAsync(hospitalId); mockAppDbRepository .Setup(x => x.AddPatientAsync(It.IsAny <Patient>())) .Returns(Task.CompletedTask); var handler = new SavePatient.Handler(mockAppDbRepository.Object, mockNotificationService.Object); // Act var result = await handler.Handle(command, new CancellationToken()); // Assert Assert.NotEqual(Guid.Empty, result); }
public async Task Handle_Given_InValidRequest_ExistingMobileNumber_Should_Not_SavePatient() { // Arrange var hospitalId = Guid.NewGuid(); var command = new SavePatient.Command("Lokesh Chandawar", DateTime.Now, 0, new Address("Vanaz cornor, Kothrud", "Pune", "Maharashtra", "410038"), "9021433312"); var mockAppDbRepository = new Mock <IAppDbRepository>(); var mockNotificationService = new Mock <INotificationService>(); mockNotificationService .Setup(x => x.Send(It.IsAny <Message>())); mockAppDbRepository .Setup(x => x.GetPatientIdByMobileNumberAsync(It.IsAny <string>())) .ReturnsAsync( new Patient { PatientId = Guid.NewGuid() }); var handler = new SavePatient.Handler(mockAppDbRepository.Object, mockNotificationService.Object); // Act // Assert await Assert.ThrowsAsync <SystemException>(() => handler.Handle(command, new CancellationToken())); }