partial void Orders_Validate(ScreenValidationResultsBuilder results) { /* * This is where the business logic would have gone * Compare this code to the code in OrderScreenValidationController.ValidateOrders * * foreach (var o in this.Orders) * { * if (o.Customer == null) * results.AddPropertyError("An order requires a customer."); * * if (o.Customer == null) * results.AddPropertyError("An order requires a product."); * * if (o.Product != null && !o.Product.Available) * results.AddPropertyError(o.Product.Name + " is not available to order."); * } */ var controller = new OrderScreenValidationController(this); IEnumerable <string> errorMessages; if (!controller.ValidateOrders(out errorMessages)) { foreach (var error in errorMessages) { results.AddPropertyError(error); } } }
public void WhenTheOrderIsValidated() { var orderModel = ((Mock <IScreenValidationModel>) ScenarioContext.Current["Order_Model"]).Object; var target = new OrderScreenValidationController(orderModel); IEnumerable <string> errorMessages; var result = target.ValidateOrders(out errorMessages); ScenarioContext.Current.Add("IsValid", result); }
public void Given_an_order_has_a_customer_and_has_an_available_product_then_we_can_create_an_order() { // arrange var mock = new Mock <IScreenValidationModel>(); mock.SetupGet(m => m.Orders).Returns(new[] { newMockIOrderWithCustomerAndAvailableProduct() } ); var target = new OrderScreenValidationController(mock.Object); // act IEnumerable <string> errorMessages; var result = target.ValidateOrders(out errorMessages); // assert Assert.IsTrue(result); }