Exemple #1
0
        public void DoSomthing()
        {
            Specification specification =
                new AndSpecification(new EqualSpecification("key1", SpecificationValue.Single("value1")), new
                                     OrSpecification(
                                         new HasValueSpecification("key2"),
                                         new EqualSpecification("key5", SpecificationValue.Single(new DateTime(2018, 10, 10, 1, 2, 3, DateTimeKind.Local))),

                                         // value of key3 should be equal to any of values 1,2,3
                                         new EqualSpecification("key3", SpecificationValue.AnyOf(1, 2, 3))),

                                     // key4 should be greater or equal to value with name "currentDateTime" which will be resolved at specification evaluation
                                     new GreaterOrEqualSpecification("key4", SpecificationValue.Ref("currentDateTime")));

            Dictionary <string, object> values = new Dictionary <string, object>
            {
                { "key1", "value1" },
                { "key3", 1 },
                { "key4", DateTime.Now.AddMinutes(1) },

                // value referenced from specification
                { "currentDateTime", DateTime.UtcNow }
            };

            SpecificationResult result = specification.Evaluate(values);

            Assert.True(result.IsSatisfied);

            string xml = specification.ToXml();

            Console.WriteLine(xml);

            Specification sp2 = Specification.Parse.FromXml(XElement.Parse(xml));
        }
        public void AndFalse()
        {
            AndSpecification    and    = new AndSpecification(ConstantSpecification.True, ConstantSpecification.False);
            SpecificationResult result = and.Evaluate(new Dictionary <string, object>());

            Assert.False(result.IsSatisfied);
            Assert.Equal("and[1]/Constant false", result.Details);
        }
        public void AndTrue()
        {
            AndSpecification    and    = new AndSpecification(ConstantSpecification.True, ConstantSpecification.True);
            SpecificationResult result = and.Evaluate(new Dictionary <string, object>());

            Assert.True(result.IsSatisfied);
            Assert.Null(result.Details);
        }
        public void AndFalseWithoutDetails()
        {
            AndSpecification    and    = new AndSpecification(ConstantSpecification.True, ConstantSpecification.False);
            SpecificationResult result = and.Evaluate(
                new Dictionary <string, object>(),
                new SpecificationEvaluationSettings()
            {
                IncludeDetails = false
            });

            Assert.False(result.IsSatisfied);
            Assert.Null(result.Details);
        }