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); }
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()); }
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); }
public void LengthPropertyNameNull() { var o = GetJ(@"{ ""TheProperty"" : null }"); LengthEquals isnull = new LengthEquals(null, 0); Assert.IsFalse(isnull.Evaluate(o)); }
public void LengthPropertyNullNotImplicit() { var o = GetJ(@"{ ""TheProperty"" : null }"); LengthEquals isnull = new LengthEquals("TheProperty", 0, false, false); Assert.IsFalse(isnull.Evaluate(o)); }
public void LengthJobNull() { LengthEquals isnull = new LengthEquals("TheProperty", 0); Assert.IsFalse(isnull.Evaluate(null)); Assert.AreEqual(0, isnull.ActualLength); }
public void LengthEqualsPropertyEqual4() { var o = GetJ(@"{ ""TheProperty"" : ""ABCD"" }"); LengthEquals isnull = new LengthEquals("TheProperty", 0); Assert.IsFalse(isnull.Evaluate(o)); }
public void LengthEqualsMissingNotImplicit() { var o = GetJ(@"{ }"); LengthEquals isnull = new LengthEquals("TheProperty", 0, false, true); Assert.IsFalse(isnull.Evaluate(o)); }
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)); }