Beispiel #1
0
 public void MatchesTwoViolationsOnlyOneIndex()
 {
     var s = Moksy.Common.SimulationFactory.When.I.Post().ToImdb("/Pet").With.NotExists("Kind").Constraint(new LengthEquals("TheProperty", 4)).Constraint(new IsNull("Other"));
     SimulationManager mgr = new SimulationManager();
     mgr.Add(s.Simulation);
     StringContent content = new StringContent(@"{""TheProperty"":""ABCD""}");
     var match = mgr.Match(HttpMethod.Post, content, "/Pet", "", new List<Header>(), false);
     Assert.IsNull(match);
 }
Beispiel #2
0
 public void NullNoneMatchingConstraints()
 {
     var s = Moksy.Common.SimulationFactory.When.I.Post().ToImdb("/Pet").With.Constraint(new LengthEquals("TheProperty", 4));
     SimulationManager mgr = new SimulationManager();
     mgr.Add(s.Simulation);
     var result = mgr.FindMatchingConstraints(s.Simulation, null, null, null);
     Assert.AreEqual(0, result.Count());
 }
Beispiel #3
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());
        }
Beispiel #4
0
 public void MatchesOneViolationsNoIndex()
 {
     var s = Moksy.Common.SimulationFactory.When.I.Post().ToImdb("/Pet").With.Constraint(new LengthEquals("TheProperty", 4));
     SimulationManager mgr = new SimulationManager();
     mgr.Add(s.Simulation);
     StringContent content = new StringContent(@"{""TheProperty"":""ABCD""}");
     var match = mgr.Match(HttpMethod.Post, content, "/Pet", null, new List<Header>(), false);
     Assert.IsNotNull(match);
     Assert.AreEqual(1, match.EvaluatedMatchingConstraints.Count);
 }
        public void StorageDoesNotDecrement()
        {
            SimulationManager mgr = new SimulationManager();
            var s = SimulationFactory.When.Delete().From("/ThePath").Once().Simulation;
            mgr.Add(s);

            var match = mgr.Match(System.Net.Http.HttpMethod.Delete, "/ThePath", null, null, false, null);
            Assert.IsNotNull(match);
            Assert.AreEqual(1, match.Condition.SimulationConditionContent.Repeat);

            var all = mgr.Get();
            Assert.AreEqual(1, all.Count);
            Assert.AreEqual(1, all[0].Condition.SimulationConditionContent.Repeat);
        }
        public void PathMatchesNoEntries()
        {
            SimulationManager mgr = new SimulationManager();
            var post = SimulationFactory.When.I.Post().ToImdb("/Pet").AsJson().And.NotExists("Kind").Then.AddToImdb();
            mgr.Add(post.Simulation);

            var add = SimulationFactory.When.I.Get().FromImdb("/Pet('{Kind}')").AsJson().And.NotExists("{Kind}").Then.Return.StatusCode(System.Net.HttpStatusCode.OK);
            mgr.Add(add.Simulation);

            var match = mgr.Match(HttpMethod.Get, "/Pet('Dog')", null, new List<Header>(), false, null);
            Assert.IsNotNull(match);
            Assert.AreEqual("/Pet('{Kind}')", match.Condition.SimulationConditionContent.Pattern);
        }
        public void PathDoesMatchWithoutIdentityButWithImdb()
        {
            SimulationManager mgr = new SimulationManager();
            var post = SimulationFactory.When.I.Post().ToImdb("/Pet").AsJson().And.NotExists("Kind").Then.AddToImdb();
            mgr.Add(post.Simulation);

            var get = SimulationFactory.When.I.Get().FromImdb("/Pet('{Kind}')").AsJson().Then.Return.StatusCode(System.Net.HttpStatusCode.OK);
            mgr.Add(get.Simulation);

            var get2 = SimulationFactory.When.I.Get().FromImdb("/Pet").AsJson().Then.Return.StatusCode(System.Net.HttpStatusCode.OK);
            mgr.Add(get2.Simulation);

            var match = mgr.Match(HttpMethod.Get, "/Pet", "", new List<Header>(), false, null);
            Assert.IsNotNull(match);
            Assert.AreEqual("/Pet", match.Condition.SimulationConditionContent.Pattern);
        }
        public void GetFromImdbWhenPathButEntryDoesNotExistImplicit()
        {
            SimulationManager mgr = new SimulationManager();
            var post = SimulationFactory.When.I.Post().ToImdb("/Pet").AsJson().And.NotExists("Kind").Then.AddToImdb();
            mgr.Add(post.Simulation);

            var get = SimulationFactory.When.I.Get().FromImdb("/Pet('{Kind}')").AsJson().Then.Return.StatusCode(System.Net.HttpStatusCode.OK);
            mgr.Add(get.Simulation);

            mgr.AddToImdb(post.Simulation, "/Pet", "/Pet", @"{ ""Kind"" : ""Cat"" }", null);

            var match = mgr.GetFromImdb(HttpMethod.Get, "/Pet('Dog')", "", new List<Header>(), null);
            Assert.IsNull(match);
        }
        public void GetFromImdbWhenPathButDoesNotMatchPattern()
        {
            SimulationManager mgr = new SimulationManager();
            var get = SimulationFactory.When.I.Get().FromImdb("/Pet('{Kind}')").AsJson().Then.Return.StatusCode(System.Net.HttpStatusCode.OK);
            mgr.Add(get.Simulation);

            var match = mgr.GetFromImdb(HttpMethod.Get, "/Pet(Dog)", "", new List<Header>(), null);
            Assert.IsNull(match);
        }