public async Task ValidateAsync_WithTwoValidators_ShouldValidateEachProductTwice() { //arrange var mockValidatorA = new Mock <IBasketValidator>(); mockValidatorA.Setup(m => m.ValidateAsync(It.IsAny <IEnumerable <string> >())) .Returns(Task.FromResult <IEnumerable <ValidationError> >(new List <ValidationError>())); var mockValidatorB = new Mock <IBasketValidator>(); mockValidatorB.Setup(m => m.ValidateAsync(It.IsAny <IEnumerable <string> >())) .Returns(Task.FromResult <IEnumerable <ValidationError> >(new List <ValidationError>())); var mockValidatorProvider = new Mock <IValidatorsProvider>(); mockValidatorProvider.Setup(m => m.Get()) .Returns(new List <IBasketValidator> { mockValidatorA.Object, mockValidatorB.Object }); var basketValidationService = new BasketValidationService(mockValidatorProvider.Object); //act await basketValidationService.ValidateAsync(new string[] { "Milk", "Soup" }); //assert mockValidatorProvider.Verify(m => m.Get(), Times.Once); mockValidatorA.Verify(m => m.ValidateAsync(It.IsAny <IEnumerable <string> >()), Times.Exactly(1)); mockValidatorB.Verify(m => m.ValidateAsync(It.IsAny <IEnumerable <string> >()), Times.Exactly(1)); }
public async Task ValidateAsync_WithNullProducts_ShouldThrowException() { //arrange var basketValidationService = new BasketValidationService(null); //act await basketValidationService.ValidateAsync(null); //assert }