public async Task CreateAsync_ByerValidationSucceed_CreatesPatient() { // Arrange var byer = new ByerUpdateModel(); var expected = new Byer(); var pictureService = new Mock <IPictureService>(); pictureService.Setup(x => x.ValidateAsync(patient)); var byerDAL = new Mock <IByerDAL>(); byerDAL.Setup(x => x.InsertAsync(byer)).ReturnsAsync(expected); var byerService = new ByerService(byerDAL.Object, pictureService.Object); // Act var result = await byerService.CreateAsync(byer); // Assert result.Should().Be(expected); }
public async Task CreateAsync_ByerValidationFailed_ThrowsError() { // Arrange var fixture = new Fixture(); var byer = new ByerUpdateModel(); var expected = fixture.Create <string>(); var pictureService = new Mock <IPictureService>(); pictureService .Setup(x => x.ValidateAsync(byer)) .Throws(new InvalidOperationException(expected)); var byerDAL = new Mock <IByerDAL>(); var byerService = new ByerService(byerDAL.Object, pictureService.Object); var action = new Func <Task>(() => byerService.CreateAsync(byer)); // Assert await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected); byerDAL.Verify(x => x.InsertAsync(byer), Times.Never); }