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