Inheritance: PredicateFields
示例#1
0
        /// <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);
        }
示例#2
0
        /// <summary>
        /// This test shows how to setup the imposter in the deepEquals predicate example
        /// at http://www.mbtest.org/docs/api/predicates.
        /// </summary>
        //[TestMethod]
        public void DeepEqualsPredicateExample()
        {
            var imposter = _client.CreateHttpImposter(4556, "DeepEqualsPredicateExample");

            // First stub
            var predicateFields = new HttpPredicateFields
            {
                QueryParameters = new Dictionary<string, string>()
            };

            var responseFields = new HttpResponseFields
            {
                ResponseObject = "first"
            };

            imposter.AddStub().On(new DeepEqualsPredicate<HttpPredicateFields>(predicateFields))
                .Returns(new IsResponse<HttpResponseFields>(responseFields));

            // Second stub
            predicateFields = new HttpPredicateFields
            {
                QueryParameters = new Dictionary<string, string> { { "first", "1" } }
            };

            responseFields = new HttpResponseFields
            {
                ResponseObject = "second"
            };

            imposter.AddStub().On(new DeepEqualsPredicate<HttpPredicateFields>(predicateFields))
                .Returns(new IsResponse<HttpResponseFields>(responseFields));

            // Third stub
            predicateFields = new HttpPredicateFields
            {
                QueryParameters = new Dictionary<string, string> { { "first", "1" }, { "second", "2" } }
            };

            responseFields = new HttpResponseFields
            {
                ResponseObject = "third"
            };

            imposter.AddStub().On(new DeepEqualsPredicate<HttpPredicateFields>(predicateFields))
                .Returns(new IsResponse<HttpResponseFields>(responseFields));

            _client.Submit(imposter);
        }