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 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 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 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 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);
        }