public async Task ValidateAsync_ByerExists_DoesNothing() { // Arrange var ByerContainer = new Mock <IByerContainer>(); var byer = new Byer(); var byerService = new Mock <IByerService>(); var byerDAL = new Mock <IByerDAL>(); var byerIdentity = new Mock <IByerIdentity>(); byerDAL.Setup(x => x.GetAsync(byerIdentity.Object)).ReturnsAsync(byer); var byerGetService = new ByerService(byerDAL.Object, pictureService.Object); // Act var action = new Func <Task>(() => byerGetService.ValidateAsync(byerContainer.Object)); // Assert await action.Should().NotThrowAsync <Exception>(); }
public async Task ValidateAsync_ByerNotExists_ThrowsError() { // Arrange var fixture = new Fixture(); var id = fixture.Create <int>(); var byerContainer = new Mock <IByerContainer>(); byerContainer.Setup(x => x.ByerId).Returns(id); var byerIdentity = new Mock <IByerIdentity>(); var byerService = new Mock <IByerService>(); var byer = new Byer(); var byerDAL = new Mock <IByerDAL>(); byerDAL.Setup(x => x.GetAsync(byerIdentity.Object)).ReturnsAsync((Byer)null); var byerGetService = new ByerService(byerDAL.Object, pictureService.Object); // Act var action = new Func <Task>(() => byerGetService.ValidateAsync(byerContainer.Object)); // Assert await action.Should().ThrowAsync <InvalidOperationException>($"Byer not found by id {id}"); }