Ejemplo n.º 1
0
        public void CanUseWhenWithContainsClauseLamdbaOnEmployee()
        {
            var employee = new Employee() { LastName = "Robbins", FirstName = "Dave", Age = 45 };

            var results = employee.Enforce("Employee", true)
                                        .When("FirstName", Compare.Contains, "Da")
                                        .When("Age", Compare.LessThan, 47);

            Assert.IsTrue(results.IsValid);
        }
Ejemplo n.º 2
0
        public void CanUseWhenClauseLamdaOnEmployee()
        {
            var employee = new Employee() { LastName = "Robbins", FirstName = "Dave", Age = 45};

            var results = employee.Enforce("Person", true)
                                    .When("Age", Compare.GreaterThan, 45)
                                    .When("FirstName", Compare.Equal, "Dave");

            Assert.IsTrue(results.IsValid);
        }
Ejemplo n.º 3
0
        public void CanUseWhenWithClauseAndReportErrors()
        {
            var employee = new Employee() { LastName = "Robbins", FirstName = "Dave", Age = 45 };

            //  Fail on purpose - age is wrong
            var results = employee.Enforce("Employee", true)
                                        .When("FirstName", Compare.Contains, "Da")
                                        .When("Age", Compare.GreaterThan, 47);

            Assert.IsFalse(results.IsValid);
            Assert.AreEqual(1, results.ErrorMessages.Count);

            Console.Out.WriteLine("Test CanUseWhenWithClauseAndReportErrors:");
            results.ErrorMessages
                    .ToList()
                    .ForEach(x => Console.Out.WriteLine(x));
        }
Ejemplo n.º 4
0
        public void CanUseWhenWithInClauseLambdaOnEmployeeAge()
        {
            var inValues = new List<int>() { 415, 416, 417 };
            var employee = new Employee() { LastName = "Robbins", FirstName = "Dave", Age = 45, Salary = 1000 };

            var result = employee.Enforce("Employee", true)
                                       .When("Age", Compare.In, inValues);

            Assert.IsFalse(result.IsValid);

            Console.Out.WriteLine("Test CanUseWhenWithInClauseLambdaOnEmployeeAge:");
            result.ErrorMessages
                    .ToList()
                    .ForEach(x => Console.Out.WriteLine(x));

            var newValues = new List<int>() { 45, 47, 34};

            var newResult = employee.Enforce("Employee", true)
                                        .When("Age", Compare.In, newValues);

            Assert.IsTrue(newResult.IsValid);

            var salaryRange = new List<decimal>() { 1000, 2000.7m, 2500.124m};
            var salResult = employee.Enforce("Employee", true)
                                        .When("Salary", Compare.In, salaryRange);

            Assert.IsTrue(salResult.IsValid);
        }