コード例 #1
0
        public async Task WireMockServer_ProxySSL_Should_log_proxied_requests()
        {
            // Assign
            var settings = new WireMockServerSettings
            {
                UseSSL = true,
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url               = "https://www.google.com",
                    SaveMapping       = true,
                    SaveMappingToFile = false
                }
            };
            var server = WireMockServer.Start(settings);

            // Act
            var requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(server.Urls[0])
            };
            var httpClientHandler = new HttpClientHandler {
                AllowAutoRedirect = false
            };

            await new HttpClient(httpClientHandler).SendAsync(requestMessage);

            // Assert
            Check.That(server.Mappings).HasSize(2);
            Check.That(server.LogEntries).HasSize(1);
        }
コード例 #2
0
        public async void WireMockMiddleware_Invoke_Mapping_Has_ProxyAndRecordSettings_And_SaveMapping_Is_False_But_WireMockServerSettings_SaveMapping_Is_True()
        {
            // Assign
            var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1", null, new Dictionary <string, string[]>());

            _requestMapperMock.Setup(m => m.MapAsync(It.IsAny <IRequest>(), It.IsAny <IWireMockMiddlewareOptions>())).ReturnsAsync(request);

            _optionsMock.SetupGet(o => o.AuthorizationMatcher).Returns(new ExactMatcher());

            var fileSystemHandlerMock = new Mock <IFileSystemHandler>();

            fileSystemHandlerMock.Setup(f => f.GetMappingFolder()).Returns("m");

            var logger = new Mock <IWireMockLogger>();

            var proxyAndRecordSettings = new ProxyAndRecordSettings
            {
                SaveMapping       = false,
                SaveMappingToFile = false
            };

            var settings = new WireMockServerSettings
            {
                FileSystemHandler      = fileSystemHandlerMock.Object,
                Logger                 = logger.Object,
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    SaveMapping       = true,
                    SaveMappingToFile = true
                }
            };

            var responseBuilder = Response.Create().WithProxy(proxyAndRecordSettings);

            _mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
            _mappingMock.SetupGet(m => m.Settings).Returns(settings);

            var newMappingFromProxy = new Mapping(Guid.NewGuid(), "", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null);

            _mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny <RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));

            var requestBuilder = Request.Create().UsingAnyMethod();

            _mappingMock.SetupGet(m => m.RequestMatcher).Returns(requestBuilder);

            var result = new MappingMatcherResult {
                Mapping = _mappingMock.Object
            };

            _matcherMock.Setup(m => m.FindBestMatch(It.IsAny <RequestMessage>())).Returns((result, result));

            // Act
            await _sut.Invoke(_contextMock.Object);

            // Assert and Verify
            fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny <string>(), It.IsAny <string>()), Times.Once);

            _mappings.Count.Should().Be(1);
        }
コード例 #3
0
        public void BeforeEachTest()
        {
            var serverSettings = new WireMockServerSettings();

            // serverSettings.Port = 5005;
            serverSettings.AllowPartialMapping = true;

            _server = WireMockServer.Start(serverSettings);
        }
コード例 #4
0
        public async Task WireMockServer_Proxy_Should_exclude_blacklisted_cookies_in_mapping()
        {
            // Assign
            string path = $"/prx_{Guid.NewGuid().ToString()}";
            var    serverForProxyForwarding = WireMockServer.Start();

            serverForProxyForwarding
            .Given(Request.Create().WithPath(path))
            .RespondWith(Response.Create());

            var settings = new WireMockServerSettings
            {
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url                = serverForProxyForwarding.Urls[0],
                    SaveMapping        = true,
                    SaveMappingToFile  = false,
                    BlackListedCookies = new[] { "ASP.NET_SessionId" }
                }
            };
            var server         = WireMockServer.Start(settings);
            var defaultMapping = server.Mappings.First();

            // Act
            var requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri($"{server.Urls[0]}{path}"),
                Content    = new StringContent("stringContent")
            };

            var cookieContainer = new CookieContainer(3);

            cookieContainer.Add(new Uri("http://localhost"), new Cookie("ASP.NET_SessionId", "exact_match"));
            cookieContainer.Add(new Uri("http://localhost"), new Cookie("AsP.NeT_SessIonID", "case_mismatch"));
            cookieContainer.Add(new Uri("http://localhost"), new Cookie("GoodCookie", "I_should_pass"));

            var handler = new HttpClientHandler {
                CookieContainer = cookieContainer
            };

            await new HttpClient(handler).SendAsync(requestMessage);

            // Assert
            var mapping = server.Mappings.FirstOrDefault(m => m.Guid != defaultMapping.Guid);

            Check.That(mapping).IsNotNull();

            var matchers = ((Request)mapping.RequestMatcher).GetRequestMessageMatchers <RequestMessageCookieMatcher>().Select(m => m.Name).ToList();

            Check.That(matchers).Not.Contains("ASP.NET_SessionId");
            Check.That(matchers).Not.Contains("AsP.NeT_SessIonID");
            Check.That(matchers).Contains("GoodCookie");
        }
コード例 #5
0
        public async Task RequestMatchWithCodeJsonTest()
        {
            var settings = new WireMockServerSettings()
            {
                Port = 9090,
                ReadStaticMappings = true
            };
            var server = WireMockServer.Start(settings);
            var obj    = await new HttpClient().GetStringAsync($"http://localhost:9090/exact?from=abc&to=def");

            Assert.Equal("Exact match", obj);
        }
コード例 #6
0
        protected BaseTestController(WebApplicationFactory factory)
        {
            HttpClient = factory.CreateClient();
            var wiereMockConfig = new WireMockServerSettings
            {
                Urls = new[] { "http://localhost:9093" },
                ReadStaticMappings = true
            };

            httpMockServer = WireMockServer.Start(wiereMockConfig);
            httpMockServer.ResetMappings();
            httpMockServer.ReadStaticMappings("Integration/Mappings/");
        }
コード例 #7
0
        public async Task WireMockServer_Proxy_Should_preserve_Authorization_header_in_proxied_request()
        {
            // Assign
            string path = $"/prx_{Guid.NewGuid()}";
            var    serverForProxyForwarding = WireMockServer.Start();

            serverForProxyForwarding
            .Given(Request.Create().WithPath(path))
            .RespondWith(Response.Create().WithCallback(x => new ResponseMessage
            {
                BodyData = new BodyData
                {
                    BodyAsString     = x.Headers["Authorization"].ToString(),
                    DetectedBodyType = Types.BodyType.String
                }
            }));

            var settings = new WireMockServerSettings
            {
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url               = serverForProxyForwarding.Urls[0],
                    SaveMapping       = true,
                    SaveMappingToFile = false
                }
            };
            var server = WireMockServer.Start(settings);

            // Act
            var requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri($"{server.Urls[0]}{path}"),
                Content    = new StringContent("stringContent", Encoding.ASCII)
            };

            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("BASIC", "test-A");
            var result = await new HttpClient().SendAsync(requestMessage);

            // Assert
            (await result.Content.ReadAsStringAsync()).Should().Be("BASIC test-A");

            var receivedRequest     = serverForProxyForwarding.LogEntries.First().RequestMessage;
            var authorizationHeader = receivedRequest.Headers["Authorization"].ToString().Should().Be("BASIC test-A");

            server.Mappings.Should().HaveCount(2);
            var authorizationRequestMessageHeaderMatcher = ((Request)server.Mappings.Single(m => !m.IsAdminInterface).RequestMatcher)
                                                           .GetRequestMessageMatcher <RequestMessageHeaderMatcher>(x => x.Matchers.Any(m => m.GetPatterns().Contains("BASIC test-A")));

            authorizationRequestMessageHeaderMatcher.Should().NotBeNull();
        }
コード例 #8
0
        public static IWireMockServer Start()
        {
            var settings = new WireMockServerSettings
            {
                Port   = 5021,
                Logger = new WireMockConsoleLogger()
            };

            var server = StandAloneApp.Start(settings);

            server.Given(Request.Create().WithPath(arg => Regex.IsMatch(arg, @"/demand/create"))
                         .UsingGet())
            .RespondWith(Response.Create()
                         .WithStatusCode(200)
                         .WithHeader("Content-Type", "application/json")
                         .WithBodyFromFile("create-demand.json"));

            server.Given(Request.Create().WithPath(arg => Regex.IsMatch(arg, @"/demand/create"))
                         .WithParam(MatchLocationParam)
                         .UsingGet())
            .RespondWith(Response.Create()
                         .WithStatusCode(200)
                         .WithHeader("Content-Type", "application/json")
                         .WithBodyFromFile("create-demand-location.json"));

            server.Given(Request.Create().WithPath(arg => Regex.IsMatch(arg, @"/demand/create"))
                         .UsingPost())
            .RespondWith(Response.Create()
                         .WithStatusCode(HttpStatusCode.Created)
                         .WithBody($"'{Guid.NewGuid().ToString()}'")
                         );

            server.Given(Request.Create().WithPath(arg => Regex.IsMatch(arg, @"/locations"))
                         .UsingGet()).RespondWith(Response.Create()
                                                  .WithStatusCode(200)
                                                  .WithHeader("Content-Type", "application/json")
                                                  .WithBodyFromFile("locations.json"));

            server.Given(Request.Create().WithPath(arg => Regex.IsMatch(arg, "/demand/aggregated/providers/\\d+"))
                         .UsingGet()).RespondWith(Response.Create()
                                                  .WithHeader("Content-Type", "application/json")
                                                  .WithBodyFromFile("provider-employer-demand.json"));

            server.Given(Request.Create().WithPath(arg => Regex.IsMatch(arg, "/demand/aggregated/providers/\\d+"))
                         .WithParam(MatchLocationParam)
                         .UsingGet()).RespondWith(Response.Create()
                                                  .WithHeader("Content-Type", "application/json")
                                                  .WithBodyFromFile("provider-employer-demand-location.json"));

            return(server);
        }
コード例 #9
0
        public void SetUp()
        {
            var settings = new WireMockServerSettings
            {
                Urls = new[] { Url },
                StartAdminInterface    = true,
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url = "http://localhost:8080"
                }
            };

            _server = WireMockServer.Start(settings);
            _driver = new ChromeDriver();
        }
コード例 #10
0
        public async Task WireMockServer_Proxy_Should_preserve_content_header_in_proxied_request()
        {
            // Assign
            string path = $"/prx_{Guid.NewGuid().ToString()}";
            var    serverForProxyForwarding = WireMockServer.Start();

            serverForProxyForwarding
            .Given(Request.Create().WithPath(path))
            .RespondWith(Response.Create());

            var settings = new WireMockServerSettings
            {
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url               = serverForProxyForwarding.Urls[0],
                    SaveMapping       = true,
                    SaveMappingToFile = false
                }
            };
            var server = WireMockServer.Start(settings);

            // Act
            var requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri($"{server.Urls[0]}{path}"),
                Content    = new StringContent("stringContent", Encoding.ASCII)
            };

            requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
            requestMessage.Content.Headers.Add("bbb", "test");
            await new HttpClient().SendAsync(requestMessage);

            // Assert
            var receivedRequest = serverForProxyForwarding.LogEntries.First().RequestMessage;

            Check.That(receivedRequest.BodyData.BodyAsString).IsEqualTo("stringContent");
            Check.That(receivedRequest.Headers).ContainsKey("Content-Type");
            Check.That(receivedRequest.Headers["Content-Type"].First()).Contains("text/plain");
            Check.That(receivedRequest.Headers).ContainsKey("bbb");

            // check that new proxied mapping is added
            Check.That(server.Mappings).HasSize(2);

            //var newMapping = _server.Mappings.First(m => m.Guid != guid);
            //var matcher = ((Request)newMapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().FirstOrDefault(m => m.Name == "bbb");
            //Check.That(matcher).IsNotNull();
        }
コード例 #11
0
        public void WireMockServer_Admin_WatchStaticMappings()
        {
            // Assign
            var fileMock = new Mock <IFileSystemHandler>();
            var settings = new WireMockServerSettings
            {
                FileSystemHandler = fileMock.Object
            };
            var server = WireMockServer.Start(settings);

            // Act
            server.WatchStaticMappings();

            // Verify
            fileMock.Verify(f => f.GetMappingFolder(), Times.Once);
            fileMock.Verify(f => f.FolderExists(It.IsAny <string>()), Times.Once);
        }
コード例 #12
0
        public async Task WireMockServer_Proxy_Should_exclude_blacklisted_content_header_in_mapping()
        {
            // Assign
            string path = $"/prx_{Guid.NewGuid().ToString()}";
            var    serverForProxyForwarding = WireMockServer.Start();

            serverForProxyForwarding
            .Given(Request.Create().WithPath(path))
            .RespondWith(Response.Create());

            var settings = new WireMockServerSettings
            {
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url                = serverForProxyForwarding.Urls[0],
                    SaveMapping        = true,
                    SaveMappingToFile  = false,
                    BlackListedHeaders = new[] { "blacklisted" }
                }
            };
            var server         = WireMockServer.Start(settings);
            var defaultMapping = server.Mappings.First();

            // Act
            var requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri($"{server.Urls[0]}{path}"),
                Content    = new StringContent("stringContent")
            };

            requestMessage.Headers.Add("blacklisted", "exact_match");
            requestMessage.Headers.Add("ok", "ok-value");
            await new HttpClient().SendAsync(requestMessage);

            // Assert
            var mapping = server.Mappings.FirstOrDefault(m => m.Guid != defaultMapping.Guid);

            Check.That(mapping).IsNotNull();
            var matchers = ((Request)mapping.RequestMatcher).GetRequestMessageMatchers <RequestMessageHeaderMatcher>().Select(m => m.Name).ToList();

            Check.That(matchers).Not.Contains("blacklisted");
            Check.That(matchers).Contains("ok");
        }
コード例 #13
0
        public void MatcherModelMapper_Map_ThrowExceptionWhenMatcherFails_True(string name)
        {
            // Assign
            var settings = new WireMockServerSettings
            {
                ThrowExceptionWhenMatcherFails = true
            };
            var sut   = new MatcherMapper(settings);
            var model = new MatcherModel
            {
                Name     = name,
                Patterns = new[] { "" }
            };

            // Act
            var matcher = sut.Map(model);

            // Assert
            matcher.ThrowException.Should().BeTrue();
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: underwater/csharp-wiremock
        static void Main(string[] args)
        {
            //Create a stub http server
            var settings = new WireMockServerSettings
            {
                // Urls = new[] { "http://+:5001" },
                StartAdminInterface = true
            };

            var server = WireMockServer.Start(settings);
            var port   = server.Ports[0];
            var url    = server.Urls[0];

            Configure(server);

            Console.WriteLine($"Mock Server listening on : {url}");
            Console.WriteLine("Press any key to stop the server");
            Console.ReadLine();
            server.Stop();
        }
コード例 #15
0
        public static IWireMockServer Start()
        {
            var settings = new WireMockServerSettings
            {
                Port   = 5016,
                Logger = new WireMockConsoleLogger()
            };

            var server = StandAloneApp.Start(settings);

            AddLandingPageResponses(server);
            AddArticlePageResponses(server);
            AddHubPageResponses(server);
            AddMenuResponses(server);
            AddSiteMapResponses(server);
            AddSectorsResponses(server);
            AddTrainingCoursesResponses(server);
            AddVacanciesResponses(server);
            AddBannerResponses(server);
            return(server);
        }
コード例 #16
0
        public void WireMockServer_Admin_ReadStaticMappings_FolderDoesNotExist()
        {
            // Assign
            var loggerMock = new Mock <IWireMockLogger>();

            loggerMock.Setup(l => l.Info(It.IsAny <string>(), It.IsAny <object[]>()));
            var settings = new WireMockServerSettings
            {
                Logger = loggerMock.Object
            };
            var server = WireMockServer.Start(settings);

            // Act
            server.ReadStaticMappings(Guid.NewGuid().ToString());

            // Assert
            Check.That(server.Mappings).HasSize(0);

            // Verify
            loggerMock.Verify(l => l.Info(It.Is <string>(s => s.StartsWith("The Static Mapping folder")), It.IsAny <object[]>()), Times.Once);
        }
コード例 #17
0
        public void BeforeEachTest()
        {
            var serverSettings = new WireMockServerSettings();

            //serverSettings.Port = 5005;
            serverSettings.AllowPartialMapping = true; //by default WireMock.NET returns 404 if request doesn't match exact parameter

            _server = WireMockServer.Start(serverSettings);

            _server
            .Given(Request.Create().WithPath("/test").UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithBody(jsonResponse)
                );

            Console.WriteLine("Press any key to stop the server");
            //Console.ReadKey();
            //app = AppInitializer.StartApp(platform);
        }
コード例 #18
0
        public async Task GlobalProxyTest()
        {
            var settings = new WireMockServerSettings
            {
                Urls = new[] { "http://localhost/" },
                StartAdminInterface    = true,
                ReadStaticMappings     = true,
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url               = "http://www.bbc.com",
                    SaveMapping       = true,
                    SaveMappingToFile = true,
                    SaveMappingForStatusCodePattern = "2xx"
                }
            };
            var server = WireMockServer.Start(settings);

            // please access: http://localhost:9090/earth/story/20170510-terrifying-20m-tall-rogue-waves-are-actually-real
            // and refresh the __admin/mappings/ directory and see the files added
            this.OpenUrl($"{server.Urls[0]}/earth/story/20170510-terrifying-20m-tall-rogue-waves-are-actually-real");
            await this.WaitingForResponse();
        }
コード例 #19
0
        public async Task WireMockServer_Proxy_With_SaveMappingForStatusCodePattern_Is_False_Should_Not_SaveMapping()
        {
            // Assign
            var fileSystemHandlerMock = new Mock <IFileSystemHandler>();

            fileSystemHandlerMock.Setup(f => f.GetMappingFolder()).Returns("m");

            var settings = new WireMockServerSettings
            {
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url               = "http://www.google.com",
                    SaveMapping       = true,
                    SaveMappingToFile = true,
                    SaveMappingForStatusCodePattern = "999" // Just make sure that we don't want this mapping
                },
                FileSystemHandler = fileSystemHandlerMock.Object
            };
            var server = WireMockServer.Start(settings);

            // Act
            var requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(server.Urls[0])
            };
            var httpClientHandler = new HttpClientHandler {
                AllowAutoRedirect = false
            };

            await new HttpClient(httpClientHandler).SendAsync(requestMessage);

            // Assert
            server.Mappings.Should().HaveCount(1);

            // Verify
            fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
コード例 #20
0
        public async Task WireMockServer_Proxy_Should_change_absolute_location_header_in_proxied_response()
        {
            // Assign
            string path     = $"/prx_{Guid.NewGuid().ToString()}";
            var    settings = new WireMockServerSettings {
                AllowPartialMapping = false
            };

            var serverForProxyForwarding = WireMockServer.Start(settings);

            serverForProxyForwarding
            .Given(Request.Create().WithPath(path))
            .RespondWith(Response.Create()
                         .WithStatusCode(HttpStatusCode.Redirect)
                         .WithHeader("Location", "/testpath"));

            var server = WireMockServer.Start(settings);

            server
            .Given(Request.Create().WithPath(path).UsingAnyMethod())
            .RespondWith(Response.Create().WithProxy(serverForProxyForwarding.Urls[0]));

            // Act
            var requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri($"{server.Urls[0]}{path}")
            };
            var httpClientHandler = new HttpClientHandler {
                AllowAutoRedirect = false
            };
            var response = await new HttpClient(httpClientHandler).SendAsync(requestMessage);

            // Assert
            Check.That(response.Headers.Contains("Location")).IsTrue();
            Check.That(response.Headers.GetValues("Location")).ContainsExactly("/testpath");
        }
        public static IWireMockServer Start()
        {
            var settings = new WireMockServerSettings
            {
                Port   = 5007,
                Logger = new WireMockConsoleLogger()
            };

            var server = StandAloneApp.Start(settings);

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-list.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses/2/epaos$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-no-epaos.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses/14$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-integrated.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses/14/epaos$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-epaos-integrated.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses/(?!(?:14|2))\\d$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course.json"));



            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses/(?!(?:14|2))\\d/epaos$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-epaos.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/epaos/delivery-areas$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("delivery-areas.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses/\\d+/epaos/[eE][pP][aA]9999$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(404));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses/(?!(?:14|2))\\d/epaos/[eE][pP][aA](?!(?:9999)$)[0-9]{4,9}$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-epao.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/courses/14/epaos/[eE][pP][aA](?!(?:9999)$)[0-9]{4,9}$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-epao-integrated.json"));

            return(server);
        }
コード例 #22
0
        public static IWireMockServer Start()
        {
            var settings = new WireMockServerSettings
            {
                Port   = 5003,
                Logger = new WireMockConsoleLogger()
            };

            var server = StandAloneApp.Start(settings);

            server.Given(Request.Create()
                         .WithPath(s => Regex.IsMatch(s, "/trainingcourses/\\d+/providers/(?!(?:10000)$)\\d+$"))
                         .WithParam(MatchLocationParamCoventry)
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-provider-details-notfound.json"));

            server.Given(Request.Create()
                         .WithPath(s => Regex.IsMatch(s, "/trainingcourses/\\d+/providers/10000$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-provider-unavailable.json"));

            server.Given(Request.Create()
                         .WithPath(s => Regex.IsMatch(s, "/trainingcourses/\\d+/providers/(?!(?:10000)$)\\d+$"))
                         .WithParam(MatchLocationParam)
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-provider.json"));

            server.Given(Request.Create()
                         .WithPath(s => Regex.IsMatch(s, "/trainingcourses/\\d+/providers/(?!(?:10000)$)\\d+$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-provider-nolocation.json"));


            server.Given(Request.Create()
                         .WithPath(s => Regex.IsMatch(s, "/trainingcourses/(?!(?:102))\\d+/providers$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-providers-nolocation.json"));

            server.Given(Request.Create()
                         .WithPath(s => Regex.IsMatch(s, "/trainingcourses/102/providers$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-providers-0-results.json"));

            server.Given(Request.Create()
                         .WithPath(s => Regex.IsMatch(s, "/trainingcourses/(?!(?:102))\\d+/providers$"))
                         .WithParam(MatchLocationParam)
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-providers.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/trainingcourses/101$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-expired.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/trainingcourses/24$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-lastdatestarts.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/trainingcourses/333$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-regulated.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/trainingcourses/102$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course-no-providers-at-location.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/trainingcourses/(?!(?:101|102|24|333)$)\\d+$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("course.json"));

            server.Given(Request.Create().WithPath(IsLocation).UsingGet()).RespondWith(Response.Create()
                                                                                       .WithStatusCode(200)
                                                                                       .WithHeader("Content-Type", "application/json")
                                                                                       .WithBodyFromFile("locations.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/trainingcourses$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("courses.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "/shortlist/users/\\S+$"))
                         .UsingGet()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("shortlist.json"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "shortlist$"))
                         .UsingPost()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(202)
                .WithBody($"'{Guid.NewGuid().ToString()}'"));

            server.Given(Request.Create().WithPath(s => Regex.IsMatch(s, "shortlist/users/"))
                         .UsingDelete()
                         ).RespondWith(
                Response.Create()
                .WithStatusCode(202));

            return(server);
        }