public DeliveryValidatorShould() { var orderValidator = new Mock <IOrderValidator>(); orderValidator.Setup(x => x.Validate(It.IsAny <IEnumerable <(Product, int)> >())) .Returns(OrderResult.Accepted); _sut = new DeliveryValidator(orderValidator.Object); }
public void CanUpdateDelivery_NullDelivery_ThrowsException() { // Arrange DeliveryValidator deliveryValidator = new DeliveryValidator(); Delivery delivery = null; // Act // Assert Assert.ThrowsException <ArgumentNullException>(() => deliveryValidator.CanUpdateDelivery(delivery)); }
public (bool isValid, IEnumerable <ValidationResult> errors) Validate() { var validator = new DeliveryValidator(); var result = validator.Validate(this); if (result.IsValid) { return(true, null); } return(false, result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new [] { item.PropertyName }))); }
public void CanUpdateDelivery_DeliveryHasEmptyPrice_ReturnErrorMessage() { // Arrange DeliveryValidator deliveryValidator = new DeliveryValidator(); Delivery delivery = new Delivery(); delivery.Name = "Name"; // Act List <KeyValuePair <string, string> > result = deliveryValidator.CanUpdateDelivery(delivery); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.AreEqual("Price", result[0].Key); }