Exemplo n.º 1
0
        public void GraphNavigationDeterminism()
        {
            // build the test object graph
            var user = new User("John", "Doe");

            var address1 = new Address(null, "11122", "Stockholm");
            address1.SetInhabitant(user);

            var address2 = new Address("Kungsgatan 5", "11122", "Stockholm");
            address2.SetInhabitant(user);

            user.AddAddress(address1);
            user.AddAddress(address2);

            var order = new Order(1);
            order.ShippingAddress = address1;
            order.BillingAddress = address2;
            order.Customer = user;

            var line1 = new OrderLine(order, 42);
            var line2 = new OrderLine(order, 101);
            order.AddOrderLine(line1);
            order.AddOrderLine(line2);

            var vtor = new ValidatorEngine();

            InvalidValue[] constraintViolations = vtor.Validate(order);
            Assert.AreEqual(3, constraintViolations.Length, "Wrong number of constraints");

            var expectedErrorMessages = new List<string>();
            expectedErrorMessages.Add("shippingAddress.addressline1");
            expectedErrorMessages.Add("customer.addresses[0].addressline1");
            expectedErrorMessages.Add("billingAddress.inhabitant.addresses[0].addressline1");

            foreach (InvalidValue violation in constraintViolations)
            {
                if (expectedErrorMessages.Contains(violation.PropertyPath))
                {
                    expectedErrorMessages.Remove(violation.PropertyPath);
                }
            }

            Assert.IsTrue(expectedErrorMessages.Count == 0, "All error messages should have occured once");
        }
Exemplo n.º 2
0
 public void AddAddress(Address address)
 {
     addresses.Add(address);
 }