예제 #1
0
        public void OneMatchingViolationBetweenIsReturnedCustomResponsePut()
        {
            var between = new LengthBetween("Kind", 5, 8) { Response = @"{""Kind"":""OutOfRangeException"",""PropertyName"":""Kind"",""MinimumLength"":{MinimumLength}}" };

            var simulation1 = Moksy.Common.SimulationFactory.When.I.Put().ToImdb("/Pet").AsBodyParameters().And.NotExists("{Kind}").With.Constraint(between).And.HasConstraintViolations().Then.Return.StatusCode(System.Net.HttpStatusCode.LengthRequired).With.Body("{violationResponses}").And.AddToImdb();
            Proxy.Add(simulation1);

            var response = Put("/Pet", @"Kind=Cat&Name=Sir");
            Assert.AreEqual(System.Net.HttpStatusCode.LengthRequired, response.StatusCode);
            Assert.AreEqual(@"[{""Kind"":""OutOfRangeException"",""PropertyName"":""Kind"",""MinimumLength"":5}]", response.Content);
        }
예제 #2
0
 public void LengthBetween47PropertyEqual8()
 {
     var o = GetJ(@"{ ""TheProperty"" : ""ABCDEFGH"" }");
     LengthBetween isnull = new LengthBetween("TheProperty", 4, 7);
     Assert.IsFalse(isnull.Evaluate(o));
     Assert.AreEqual(8, isnull.ActualLength);
 }
예제 #3
0
 public void LengthBetween17PropertyNullNotImplicit()
 {
     var o = GetJ(@"{""TheProperty"":null}");
     LengthBetween isnull = new LengthBetween("TheProperty", 1, 7, false, false);
     Assert.IsFalse(isnull.Evaluate(o));
     Assert.AreEqual(0, isnull.ActualLength);
 }
예제 #4
0
 public void LengthBetween17PropertyMissingImplicit()
 {
     var o = GetJ(@"{}");
     LengthBetween isnull = new LengthBetween("TheProperty", 1, 7);
     Assert.IsFalse(isnull.Evaluate(o));
     Assert.AreEqual(0, isnull.ActualLength);
 }
예제 #5
0
 public void LengthBetween07PropertyNullImplicit()
 {
     var o = GetJ(@"{""TheProperty"":null}");
     LengthBetween isnull = new LengthBetween("TheProperty", 0, 7);
     Assert.IsTrue(isnull.Evaluate(o));
     Assert.AreEqual(0, isnull.ActualLength);
 }