public void Constructor_SetsCaseSensitivity() { var fields = new TestPredicateFields(); var predicate = new EqualsPredicate <TestPredicateFields>(fields, true, null, null); Assert.IsTrue(predicate.IsCaseSensitive); }
public void Constructor_SetsFieldObject() { var expectedFields = new TestPredicateFields(); var predicate = new EqualsPredicate <TestPredicateFields>(expectedFields); Assert.AreSame(expectedFields, predicate.Fields); }
// EqualityExpression := NotExpression '==' S NotExpression private State DoParseEqualityExpression1Rule(State _state, List <Result> _outResults) { State _start = _state; List <Result> results = new List <Result>(); _state = DoSequence(_state, results, delegate(State s, List <Result> r) { return(DoParse(s, r, "NotExpression")); }, delegate(State s, List <Result> r) { return(DoParseLiteral(s, r, "==")); }, delegate(State s, List <Result> r) { return(DoParse(s, r, "S")); }, delegate(State s, List <Result> r) { return(DoParse(s, r, "NotExpression")); }); if (_state.Parsed) { Predicate value = results.Count > 0 ? results[0].Value : default(Predicate); value = new EqualsPredicate(results[0].Value, results[2].Value); _outResults.Add(new Result(this, _start.Index, _state.Index - _start.Index, m_input, value)); } else { string expected; expected = "equality expression"; if (expected != null) { _state = new State(_start.Index, false, ErrorSet.Combine(_start.Errors, new ErrorSet(_state.Errors.Index, expected))); } } return(_state); }
public void Constructor_SetsExceptExpression() { const string expectedExceptRegex = "!$"; var fields = new TestPredicateFields(); var predicate = new EqualsPredicate<TestPredicateFields>(fields, false, expectedExceptRegex, null); Assert.AreEqual(expectedExceptRegex, predicate.ExceptExpression); }
public void Constructor_SetsXpathSelector() { var expectedXPathSelector = new XPathSelector("!$"); var fields = new TestPredicateFields(); var predicate = new EqualsPredicate<TestPredicateFields>(fields, false, null, expectedXPathSelector); Assert.AreEqual(expectedXPathSelector, predicate.Selector); }
public void NotPredicate_Constructor_SetsChildPredicate() { var expectedChildPredicate = new EqualsPredicate <TestPredicateFields>(new TestPredicateFields()); var predicate = new NotPredicate(expectedChildPredicate); Assert.AreEqual(expectedChildPredicate, predicate.ChildPredicate); }
public void EqualsPredicate_Constructor_SetsJsonPathSelector() { var expectedJsonPathSelector = new JsonPathSelector("$..title"); var fields = new TestPredicateFields(); var predicate = new EqualsPredicate<TestPredicateFields>(fields, jsonpath: expectedJsonPathSelector); Assert.AreEqual(expectedJsonPathSelector, predicate.JsonPathSelector); }
public void EqualsPredicate_Constructor_SetsXpathSelector() { var expectedXPathSelector = new XPathSelector("!$"); var fields = new TestPredicateFields(); var predicate = new EqualsPredicate<TestPredicateFields>(fields, xpath: expectedXPathSelector); Assert.AreEqual(expectedXPathSelector, predicate.XPathSelector); }
public void EqualsPredicate_Constructor_SetsExceptExpression() { const string expectedExceptRegex = "!$"; var fields = new TestPredicateFields(); var predicate = new EqualsPredicate<TestPredicateFields>(fields, exceptExpression: expectedExceptRegex); Assert.AreEqual(expectedExceptRegex, predicate.ExceptExpression); }
public void Constructor_SetsChildPredicate() { var expectedChildPredicate = new EqualsPredicate<TestPredicateFields>(new TestPredicateFields()); var predicate = new NotPredicate(expectedChildPredicate); Assert.AreEqual(expectedChildPredicate, predicate.ChildPredicate); }
public void WhenOneValueAddedToPredicate_Fails() { EqualsPredicate equals = new EqualsPredicate(); equals.Push(new Value(23m, "TEST")); Assert.IsTrue(equals.GetValue()); }
public void WhenEqualsPredicateLoadedWithMatchingValues_AnswerShouldBeFalse() { EqualsPredicate equals = new EqualsPredicate(); equals.Push(new Value(3.5m, "TEST")); equals.Push(new Value(3.5m, "TEST")); Assert.IsTrue(equals.GetValue()); }
/// <summary> /// Adds a predicate to the stub that will match when the request data equals the specified data. /// </summary> /// <param name="path">The data to match on</param> /// <returns>The stub that the predicate was added to</returns> public TcpStub OnDataEquals(string data) { var fields = new TcpPredicateFields { Data = data }; var predicate = new EqualsPredicate<TcpPredicateFields>(fields); return On(predicate); }
/// <summary> /// Adds a predicate to the stub that will match when the request path equals the specified path. /// </summary> /// <param name="path">The path to match on</param> /// <returns>The stub that the predicate was added to</returns> public HttpStub OnPathEquals(string path) { var fields = new HttpPredicateFields { Path = path }; var predicate = new EqualsPredicate <HttpPredicateFields>(fields); return(On(predicate)); }
/// <summary> /// Adds a predicate to the stub that will match when the request method equals the specified method. /// </summary> /// <param name="method">The method to match on</param> /// <returns>The stub that the predicate was added to</returns> public HttpStub OnMethodEquals(Method method) { var fields = new HttpPredicateFields { Method = method }; var predicate = new EqualsPredicate <HttpPredicateFields>(fields); return(On(predicate)); }
/// <summary> /// Adds a predicate to the stub that will match when the request data equals the specified data. /// </summary> /// <param name="path">The data to match on</param> /// <returns>The stub that the predicate was added to</returns> public TcpStub OnDataEquals(string data) { var fields = new TcpPredicateFields { Data = data }; var predicate = new EqualsPredicate <TcpPredicateFields>(fields); return(On(predicate)); }
/// <summary> /// Adds a predicate to the stub that will match when the request path equals the specified path /// and the method of the request matches the specified HTTP method. /// </summary> /// <param name="path">The path to match on</param> /// <param name="method">The method to match on</param> /// <returns>The stub that the predicate was added to</returns> public HttpStub OnPathAndMethodEqual(string path, Method method) { var fields = new HttpPredicateFields { Path = path, Method = method }; var predicate = new EqualsPredicate <HttpPredicateFields>(fields); return(On(predicate)); }
public void HttpStub_On_AddsPredicate() { var expectedPredicate = new EqualsPredicate <HttpPredicateFields>(new HttpPredicateFields()); var stub = new HttpStub(); stub.On(expectedPredicate); var predicate = stub.Predicates.First() as EqualsPredicate <HttpPredicateFields>; Assert.AreEqual(expectedPredicate, predicate); }
public void On_AddsPredicate() { var headers = new Dictionary <string, string> { { "Content-Type", "application/json" } }; var expectedPredicate = new EqualsPredicate <HttpPredicateFields>(new HttpPredicateFields()); var stub = new HttpStub(); stub.On(expectedPredicate); var predicate = stub.Predicates.First() as EqualsPredicate <HttpPredicateFields>; Assert.AreEqual(expectedPredicate, predicate); }
public async Task EqualsPredicateExample() { var imposter = _client.CreateHttpImposter(4545, "EqualsPredicateExample"); // First stub var bodyPredicateFields = new HttpPredicateFields { RequestBody = "hello, world" }; var bodyPredicate = new EqualsPredicate <HttpPredicateFields>(bodyPredicateFields, true, "$!", null); var complexPredicateFields = new HttpPredicateFields { Method = Method.Post, Path = "/test", QueryParameters = new Dictionary <string, object> { { "first", "1" }, { "second", "2" } }, Headers = new Dictionary <string, object> { { "Accept", "text/plain" } } }; var complexPredicate = new EqualsPredicate <HttpPredicateFields>(complexPredicateFields); imposter.AddStub().On(complexPredicate).On(bodyPredicate).ReturnsStatus(HttpStatusCode.BadRequest); // Second stub var fields = new HttpPredicateFields { Headers = new Dictionary <string, object> { { "Accept", "application/xml" } } }; imposter.AddStub().On(new EqualsPredicate <HttpPredicateFields>(fields)).ReturnsStatus(HttpStatusCode.NotAcceptable); // Third stub imposter.AddStub().OnMethodEquals(Method.Put).ReturnsStatus((HttpStatusCode)405); // Fourth stub imposter.AddStub().OnMethodEquals(Method.Put).ReturnsStatus((HttpStatusCode)500); await _client.SubmitAsync(imposter); }
public async Task NotPredicateExample() { var imposter = _client.CreateTcpImposter(4552, "NotPredicateExample"); var predicate = new EqualsPredicate <TcpPredicateFields>(new TcpPredicateFields { Data = "test\n" }); // First stub imposter.AddStub().On(new NotPredicate(predicate)) .ReturnsData("not test"); // Second stub imposter.AddStub().On(predicate) .ReturnsData("test"); await _client.SubmitAsync(imposter); }
/// <summary> /// This test shows how to setup the imposter in the not predicate example /// at http://www.mbtest.org/docs/api/predicates. /// </summary> //[TestMethod] public void NotPredicateExample() { var imposter = _client.CreateTcpImposter(4552, "NotPredicateExample", TcpMode.Text); var predicate = new EqualsPredicate <TcpPredicateFields>(new TcpPredicateFields { Data = "test\n" }); // First stub imposter.AddStub().On(new NotPredicate(predicate)) .ReturnsData("not test"); // Second stub imposter.AddStub().On(predicate) .ReturnsData("test"); _client.Submit(); }
private void InstallLocalPredicates() { // Input/Output _predicates["write/1"] = new WritePredicate(); _predicates["writeln/1"] = new WriteLnPredicate(); _predicates["nl/0"] = new NlPredicate(); _predicates["get0/1"] = new Get0Predicate(); _predicates["skip/1"] = new SkipPredicate(); _predicates["put/1"] = new PutPredicate(); // Comparison, numeric _predicates["=\\=/2"] = new NotEqualsPredicate(); _predicates["=:=/2"] = new EqualsPredicate(); _predicates[">=/2"] = new GreaterThanEqualPredicate(); _predicates[">/2"] = new GreaterThanPredicate(); _predicates["=</2"] = new LessThanEqualPredicate(); _predicates["</2"] = new LessThanPredicate(); // Control _predicates["call/1"] = new CallPredicate(); // Equality _predicates["=/2"] = new UnifyPredicate(); _predicates["\\=/2"] = new NotUnifiablePredicate(); // Meta _predicates["is/2"] = new IsPredicate(); _predicates["atom/1"] = new AtomPredicate(); _predicates["bound/1"] = new BoundPredicate(); _predicates["char/1"] = new CharPredicate(); _predicates["free/1"] = new FreePredicate(); _predicates["integer/1"] = new IntegerPredicate(); _predicates["nonvar/1"] = new NonVarPredicate(); _predicates["var/1"] = new VarPredicate(); // Object-Oriented Programming _predicates["object/2"] = new object_2(); _predicates["invoke/3"] = new invoke_2(); _predicates["get_property/3"] = new get_property_3(); // .NET Reflection }
public async Task JsonExample() { var imposter = _client.CreateHttpImposter(4545, "JsonExample"); var caseSensitiveFields = new HttpPredicateFields { RequestBody = new Book { Title = "Harry Potter" } }; var caseSensitivePredicate = new EqualsPredicate <HttpPredicateFields>(caseSensitiveFields, true, null, null); var exceptFields = new HttpPredicateFields { RequestBody = new Book { Title = "POTTER" } }; var exceptPredicate = new EqualsPredicate <HttpPredicateFields>(exceptFields, false, "HARRY ", null); var matchesFields = new HttpPredicateFields { RequestBody = new Book { Title = "^Harry" } }; var matchesPredicate = new MatchesPredicate <HttpPredicateFields>(matchesFields); // Exists examples not provided since MbDotNet does not yet support checking specific object keys imposter.AddStub() .On(caseSensitivePredicate) .On(exceptPredicate) .On(matchesPredicate) .ReturnsJson(HttpStatusCode.OK, new BookResponse { Code = "SUCCESS", Author = "J.K. Rowling" }); await _client.SubmitAsync(imposter); }
public void On_AddsPredicate() { var headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }; var expectedPredicate = new EqualsPredicate<HttpPredicateFields>(new HttpPredicateFields()); var stub = new HttpStub(); stub.On(expectedPredicate); var predicate = stub.Predicates.First() as EqualsPredicate<HttpPredicateFields>; Assert.AreEqual(expectedPredicate, predicate); }
public void WhenNoValuesAddedToPredicate_Fails() { EqualsPredicate equals = new EqualsPredicate(); Assert.IsTrue(equals.GetValue()); }
/// <summary> /// This test shows how to setup the imposter in the equals predicate example /// at http://www.mbtest.org/docs/api/predicates. /// </summary> //[TestMethod] public void EqualsPredicateExample() { var imposter = _client.CreateHttpImposter(4545, "EqualsPredicateExample"); // First stub var bodyPredicateFields = new HttpPredicateFields { RequestBody = "hello, world" }; var bodyPredicate = new EqualsPredicate<HttpPredicateFields>(bodyPredicateFields, true, "$!", null); var complexPredicateFields = new HttpPredicateFields { Method = Method.Post, Path = "/test", QueryParameters = new Dictionary<string, string> { { "first", "1" }, { "second", "2" } }, Headers = new Dictionary<string, string> { { "Accept", "text/plain" } } }; var complexPredicate = new EqualsPredicate<HttpPredicateFields>(complexPredicateFields); imposter.AddStub().On(complexPredicate).On(bodyPredicate).ReturnsStatus(HttpStatusCode.BadRequest); // Second stub var fields = new HttpPredicateFields { Headers = new Dictionary<string, string> { { "Accept", "application/xml" } } }; imposter.AddStub().On(new EqualsPredicate<HttpPredicateFields>(fields)).ReturnsStatus(HttpStatusCode.NotAcceptable); // Third stub imposter.AddStub().OnMethodEquals(Method.Put).ReturnsStatus((HttpStatusCode)405); // Fourth stub imposter.AddStub().OnMethodEquals(Method.Put).ReturnsStatus((HttpStatusCode)500); _client.Submit(imposter); }
/// <summary> /// This test shows how to setup the imposter in the not predicate example /// at http://www.mbtest.org/docs/api/predicates. /// </summary> //[TestMethod] public void NotPredicateExample() { var imposter = _client.CreateTcpImposter(4552, "NotPredicateExample", TcpMode.Text); var predicate = new EqualsPredicate<TcpPredicateFields>(new TcpPredicateFields { Data = "test\n" }); // First stub imposter.AddStub().On(new NotPredicate(predicate)) .ReturnsData("not test"); // Second stub imposter.AddStub().On(predicate) .ReturnsData("test"); _client.Submit(imposter); }
public void Constructor_SetsFieldObject() { var expectedFields = new TestPredicateFields(); var predicate = new EqualsPredicate<TestPredicateFields>(expectedFields); Assert.AreSame(expectedFields, predicate.Fields); }
public override bool Equals(T x, T y) { return(EqualsPredicate.Invoke(x, y)); }
public void Constructor_SetsCaseSensitivity() { var fields = new TestPredicateFields(); var predicate = new EqualsPredicate<TestPredicateFields>(fields, true, null, null); Assert.IsTrue(predicate.IsCaseSensitive); }