Exemple #1
0
        public void TwoConstraintsWithRehydration()
        {
            var s = Moksy.Common.SimulationFactory.When.I.Get().From("/Pet");

            LengthEquals c = new LengthEquals("TheProperty", 10);
            s.Constraint(c);

            IsNull n = new IsNull("TheOtherProperty");
            s.Constraint(n);

            Assert.AreEqual(2, s.Constraints.Count);

            var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects };
            var json = JsonConvert.SerializeObject(s, settings);

            var h = JsonConvert.DeserializeObject<SimulationCondition>(json, settings);
            Assert.AreEqual(2, h.Constraints.Count);
        }
Exemple #2
0
        public void MatchesJsonOneViolation()
        {
            var v = new LengthEquals("TheProperty", 4);
            var s = Moksy.Common.SimulationFactory.When.I.Post().ToImdb("/Pet").With.Constraint(v);
            SimulationManager mgr = new SimulationManager();
            mgr.Add(s.Simulation);

            var matches = mgr.FindMatchingConstraints(s.Simulation, new List<ConstraintBase>() { v }, @"{ ""TheProperty"":""ABCD"" }", null);
            Assert.AreEqual(1, matches.Count());
        }
Exemple #3
0
        public void OneConstraint()
        {
            var s = Moksy.Common.SimulationFactory.When.I.Get().From("/Pet");

            LengthEquals c = new LengthEquals("TheProperty", 10);
            s.Constraint(c);

            Assert.AreEqual(1, s.Constraints.Count);
        }
Exemple #4
0
 public void LengthPropertyNameNull()
 {
     var o = GetJ(@"{ ""TheProperty"" : null }");
     LengthEquals isnull = new LengthEquals(null, 0);
     Assert.IsFalse(isnull.Evaluate(o));
 }
Exemple #5
0
 public void LengthPropertyNullNotImplicit()
 {
     var o = GetJ(@"{ ""TheProperty"" : null }");
     LengthEquals isnull = new LengthEquals("TheProperty", 0, false, false);
     Assert.IsFalse(isnull.Evaluate(o));
 }
Exemple #6
0
 public void LengthJobNull()
 {
     LengthEquals isnull = new LengthEquals("TheProperty", 0);
     Assert.IsFalse(isnull.Evaluate(null));
     Assert.AreEqual(0, isnull.ActualLength);
 }
Exemple #7
0
 public void LengthEqualsPropertyEqual4()
 {
     var o = GetJ(@"{ ""TheProperty"" : ""ABCD"" }");
     LengthEquals isnull = new LengthEquals("TheProperty", 0);
     Assert.IsFalse(isnull.Evaluate(o));
 }
Exemple #8
0
 public void LengthEqualsMissingNotImplicit()
 {
     var o = GetJ(@"{ }");
     LengthEquals isnull = new LengthEquals("TheProperty", 0, false, true);
     Assert.IsFalse(isnull.Evaluate(o));
 }
Exemple #9
0
 public void LengthEqualsMissingImplicit()
 {
     var o = GetJ(@"{ }");
     LengthEquals isnull = new LengthEquals("TheProperty", 0);
     Assert.IsTrue(isnull.Evaluate(o));
 }
 public void LengthEqualsTrue()
 {
     LengthEquals c = new LengthEquals("TheProperty", 4);
     var j = GetJ(@"{""TheProperty"":""ABCD""}");
     Assert.IsTrue(c.Evaluate(j));
     Assert.AreEqual(@"{""Name"":""Length"",""PropertyName"":""TheProperty"",""Kind"":""Equals"",""ExpectedLength"":4,""ActualLength"":4,""PropertyValue"":""ABCD"",""PropertyHasValue"":true,""Description"":""The property 'TheProperty' was expected to be of length '4'.""}", c.GetState(j));
 }