public void TruckEngineTest()
        {
            var truck = new Truck {
                Id = "1"
            };
            var personCar = new PersonCar {
                Id = "2"
            };
            var carPark = new CarPark
            {
                Cars = new ObservableCollection <Car> {
                    truck, personCar
                }
            };

            MEFValidationRules.RegisterType(typeof(TruckEngineValidator));
            var gr = carPark.EntityGraph(CarPark.Shape);

            Assert.IsFalse(truck.HasValidationErrors);
            Assert.IsFalse(truck.Engine.HasValidationErrors);

            truck.Engine.EngineType = EngineType.Benzin;

            Assert.IsTrue(truck.HasValidationErrors);
            Assert.IsFalse(truck.Engine.HasValidationErrors);

            truck.Engine.EngineType = EngineType.Diesel;
            Assert.IsFalse(truck.HasValidationErrors);
            Assert.IsFalse(truck.Engine.HasValidationErrors);
            MEFValidationRules.UnregisterType(typeof(TruckEngineValidator));
        }
        public void TruckTrailerTest()
        {
            var truck1 = new Truck {
                Id = "1"
            };
            var truck2 = new Truck {
                Id = "2"
            };
            var trailer = new Trailer();
            var carPark = new CarPark
            {
                Cars = new ObservableCollection <Car> {
                    truck1, truck2
                }
            };

            MEFValidationRules.RegisterType(typeof(TruckTrailerValidator));
            var gr = carPark.EntityGraph(CarPark.Shape);

            truck1.Trailer = trailer;
            Assert.IsFalse(truck1.HasValidationErrors);
            Assert.IsFalse(truck2.HasValidationErrors);

            truck2.Trailer = trailer;
            Assert.IsTrue(truck1.HasValidationErrors);
            Assert.IsTrue(truck2.HasValidationErrors);
            MEFValidationRules.UnregisterType(typeof(TruckTrailerValidator));
        }
        public void UniqIdsTest()
        {
            var truck = new Truck {
                Id = "1"
            };
            var personCar = new PersonCar {
                Id = "2"
            };
            var carPark = new CarPark
            {
                Cars = new ObservableCollection <Car> {
                    truck, personCar
                }
            };

            MEFValidationRules.RegisterType(typeof(UniqIds));
            var gr = carPark.EntityGraph(CarPark.Shape);

            Assert.IsFalse(truck.HasValidationErrors);
            Assert.IsFalse(personCar.HasValidationErrors);
            truck.Id = "2";
            Assert.IsTrue(truck.HasValidationErrors);
            Assert.IsTrue(personCar.HasValidationErrors);
            personCar.Id = "1";
            Assert.IsFalse(truck.HasValidationErrors);
            Assert.IsFalse(personCar.HasValidationErrors);

            MEFValidationRules.UnregisterType(typeof(UniqIds));
        }
 public override void TestCleanup()
 {
     base.TestCleanup();
     MEFValidationRules.UnregisterType(typeof(AValidator));
     MEFValidationRules.UnregisterType(typeof(MultiPropertyValidator));
     MEFValidationRules.UnregisterType(typeof(InputOutputInputOnlyValidator));
 }
        public void UnregisterTest()
        {
            MEFValidationRules.UnregisterType(typeof(RegisterUnregisterValidation));
            var validator = new ValidationEngine {
                RulesProvider = new MEFValidationRulesProvider <ValidationResult>()
            };

            RegisterUnregisterValidation.visited = false;

            validator.Validate(a, "B", new List <Entity> {
                a
            });
            Assert.IsFalse(RegisterUnregisterValidation.visited);
        }
        public void InputOutputInputOnlyValidatorTest()
        {
            MEFValidationRules.RegisterType(typeof(InputOutputInputOnlyValidator));
            a.name     = "John";
            a.lastName = "John";
            var gr = a.EntityGraph(EntityGraphs.CircularGraphFull);

            Assert.IsTrue(a.HasValidationErrors);
            var validationError = a.ValidationErrors.Single();

            Assert.IsTrue(validationError.MemberNames.Contains("name"));
            Assert.IsFalse(validationError.MemberNames.Contains("lastName"));
            Assert.IsTrue(validationError.MemberNames.Count() == 1);
            a.lastName = "Doe";
            Assert.IsFalse(a.HasValidationErrors);
            MEFValidationRules.UnregisterType(typeof(InputOutputInputOnlyValidator));
        }
        public void TruckEquipmentTest()
        {
            var truck = new Truck {
                Id = "1"
            };
            var personCar = new PersonCar {
                Id = "2"
            };
            var carPark = new CarPark
            {
                Cars = new ObservableCollection <Car> {
                    truck, personCar
                }
            };

            MEFValidationRules.RegisterType(typeof(TruckDoorsValidator));
            var gr = carPark.EntityGraph(CarPark.Shape);

            Assert.IsFalse(truck.HasValidationErrors);
            truck.Doors.Add(new Door());
            Assert.IsTrue(truck.HasValidationErrors);

            MEFValidationRules.UnregisterType(typeof(TruckDoorsValidator));
        }
예제 #8
0
 public override void TestCleanup()
 {
     base.TestCleanup();
     MEFValidationRules.UnregisterType(typeof(AValidator));
 }
예제 #9
0
 public override void TestSetup()
 {
     base.TestSetup();
     MEFValidationRules.RegisterType(typeof(AValidator));
 }