コード例 #1
0
        public async Task PassingTestCase()
        {
            var testcase = new NetmockeryTestCase
            {
                RequestPath = "/statuscode/404",
                ExpectedStatusCode = 404
            };

            Assert.True(testcase.HasExpectations);
            var result = await testcase.ExecuteAsync(EndpointCollectionReader.ReadFromDirectory("examples/example1"), handleErrors: false);
            Assert.True(result.OK);
        }
コード例 #2
0
        async public void RequestBodyCanBeUnspecified()
        {
            var endpointCollection = EndpointCollectionReader.ReadFromDirectory(dc.DirectoryName);

            var test = new NetmockeryTestCase
            {
                RequestPath            = "/foo/",
                ExpectedRequestMatcher = "Any request",
                ExpectedResponseBody   = "Hello world"
            };

            var result = await test.ExecuteAsync(endpointCollection, false);

            Assert.True(result.OK, result.Message);
        }
コード例 #3
0
        public async Task FailingTestCase()
        {
            Assert.False(new NetmockeryTestCase().HasExpectations);

            var testcase = new NetmockeryTestCase
            {
                RequestPath = "/statuscode/200",
                ExpectedStatusCode = 404
            };

            Assert.True(testcase.HasExpectations);
            var result = await testcase.ExecuteAsync(EndpointCollectionReader.ReadFromDirectory("examples/example1"), handleErrors: false);
            Assert.False(result.OK);
            Assert.Equal("Expected http status code: 404\nActual: 200", result.Message);
        }
コード例 #4
0
        public async Task Foo()
        {
            var endpoint = (new JSONEndpoint
            {
                name = "endpoint",
                pathregex = "/",
                responses = new[]
                {
                    new JSONResponse {
                        match = new JSONRequestMatcher {
                            methods = "POST"
                        }, literal = "Response from POST"
                    },
                    new JSONResponse {
                        match = new JSONRequestMatcher {
                            methods = "GET"
                        }, literal = "Response from GET"
                    }
                }
            }).CreateEndpoint(".", null);

            Assert.NotNull(endpoint);
            Assert.Equal(2, endpoint.Responses.Count());

            var getTestCase = new NetmockeryTestCase {
                Method = "GET", RequestPath = "/", ExpectedResponseBody = "Response from GET"
            };

            Assert.True((await getTestCase.ExecuteAsync(EndpointCollection.WithEndpoints(endpoint))).OK);

            var postTestCase = new NetmockeryTestCase {
                Method = "POST", RequestPath = "/", ExpectedResponseBody = "Response from POST"
            };

            Assert.True((await postTestCase.ExecuteAsync(EndpointCollection.WithEndpoints(endpoint))).OK);
        }
コード例 #5
0
 public override void WriteResult(int index, NetmockeryTestCase testCase, NetmockeryTestCaseResult result)
 {
     response.AppendLine(result.ResultAsString);
 }
コード例 #6
0
 public override void WriteBeginTest(int index, NetmockeryTestCase testcase)
 {
     response.Append($"{index} {testcase.Name} ");
 }