예제 #1
0
        public void HttpStub_ReturnsProxy_ReturnsHttpProxyStub()
        {
            var predicateInvokingProxyStub = new ContainsPredicate <HttpPredicateFields>(new HttpPredicateFields
            {
                Path = "/aTestPath"
            });

            var proxyGeneratorPredicate = new MatchesPredicate <HttpPredicateFields>(new HttpPredicateFields
            {
                Path            = "/aTestPath",
                Method          = Method.Get,
                QueryParameters = new Dictionary <string, string> {
                    { "q", "value" }
                }
            });

            var proxyToUrl     = new Uri("http://someTestDestination.com");
            var proxyModeToUse = ProxyMode.ProxyTransparent;

            var stub = new HttpStub();

            stub.On(predicateInvokingProxyStub)
            .ReturnsProxy(proxyToUrl, proxyModeToUse, new [] { proxyGeneratorPredicate });

            var proxyResponse = stub.Responses.First() as ProxyResponse <ProxyResponseFields <HttpPredicateFields> >;

            Assert.AreEqual(proxyToUrl, proxyResponse.Fields.To);
            Assert.AreEqual(proxyModeToUse, proxyResponse.Fields.Mode);
            Assert.AreEqual(proxyGeneratorPredicate, proxyResponse.Fields.PredicateGenerators.First());
        }
예제 #2
0
        public void MatchesPredicate_Constructor_SetsFieldObject()
        {
            var expectedFields = new TestPredicateFields();
            var predicate      = new MatchesPredicate <TestPredicateFields>(expectedFields);

            Assert.AreSame(expectedFields, predicate.Fields);
        }
예제 #3
0
        public void MatchesPredicate_Constructor_SetsCaseSensitivity()
        {
            var fields    = new TestPredicateFields();
            var predicate = new MatchesPredicate <TestPredicateFields>(fields, isCaseSensitive: true);

            Assert.IsTrue(predicate.IsCaseSensitive);
        }
예제 #4
0
        public void TcpStub_ReturnsProxy_ReturnsTcpBooleanProxyStub()
        {
            var predicateInvokingProxyStub = new ContainsPredicate <TcpPredicateFields>(new TcpPredicateFields
            {
                Data = "123345"
            });

            var proxyGeneratorPredicate = new MatchesPredicate <TcpBooleanPredicateFields>(new TcpBooleanPredicateFields
            {
                Data = true
            });

            var proxyToUrl     = new Uri("tcp://someTestDestination.com");
            var proxyModeToUse = ProxyMode.ProxyTransparent;

            var stub = new TcpStub();

            stub.On(predicateInvokingProxyStub)
            .ReturnsProxy(proxyToUrl, proxyModeToUse, new [] { proxyGeneratorPredicate });

            var proxyResponse = stub.Responses.First() as ProxyResponse <ProxyResponseFields <TcpBooleanPredicateFields> >;

            Assert.AreEqual(proxyToUrl, proxyResponse.Fields.To);
            Assert.AreEqual(proxyModeToUse, proxyResponse.Fields.Mode);
            Assert.AreEqual(proxyGeneratorPredicate, proxyResponse.Fields.PredicateGenerators.First());
        }
예제 #5
0
        public void Constructor_SetsXpathSelector()
        {
            var expectedXPathSelector = new XPathSelector("!$");

            var fields = new TestPredicateFields();
            var predicate = new MatchesPredicate<TestPredicateFields>(fields, false, null, expectedXPathSelector);
            Assert.AreEqual(expectedXPathSelector, predicate.Selector);
        }
예제 #6
0
        public void Constructor_SetsExceptExpression()
        {
            const string expectedExceptRegex = "!$";

            var fields = new TestPredicateFields();
            var predicate = new MatchesPredicate<TestPredicateFields>(fields, false, expectedExceptRegex, null);
            Assert.AreEqual(expectedExceptRegex, predicate.ExceptExpression);
        }
예제 #7
0
        public void MatchesPredicate_Constructor_SetsJsonPathSelector()
        {
            var expectedJsonPathSelector = new JsonPathSelector("$..title");

            var fields    = new TestPredicateFields();
            var predicate = new MatchesPredicate <TestPredicateFields>(fields, jsonpath: expectedJsonPathSelector);

            Assert.AreEqual(expectedJsonPathSelector, predicate.JsonPathSelector);
        }
예제 #8
0
        public void MatchesPredicate_Constructor_SetsXpathSelector()
        {
            var expectedXPathSelector = new XPathSelector("!$");

            var fields    = new TestPredicateFields();
            var predicate = new MatchesPredicate <TestPredicateFields>(fields, xpath: expectedXPathSelector);

            Assert.AreEqual(expectedXPathSelector, predicate.XPathSelector);
        }
예제 #9
0
        public void MatchesPredicate_Constructor_SetsExceptExpression()
        {
            const string expectedExceptRegex = "!$";

            var fields    = new TestPredicateFields();
            var predicate = new MatchesPredicate <TestPredicateFields>(fields, exceptExpression: expectedExceptRegex);

            Assert.AreEqual(expectedExceptRegex, predicate.ExceptExpression);
        }
예제 #10
0
        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);
        }
예제 #11
0
 public void Constructor_SetsFieldObject()
 {
     var expectedFields = new TestPredicateFields();
     var predicate = new MatchesPredicate<TestPredicateFields>(expectedFields);
     Assert.AreSame(expectedFields, predicate.Fields);
 }
예제 #12
0
 public void Constructor_SetsCaseSensitivity()
 {
     var fields = new TestPredicateFields();
     var predicate = new MatchesPredicate<TestPredicateFields>(fields, true, null, null);
     Assert.IsTrue(predicate.IsCaseSensitive);
 }