Beispiel #1
0
        public static WireMockServer RunServer(string path, string url)
        {
            var server = WireMockServer.Start(new WireMockServerSettings
            {
                AllowCSharpCodeMatcher = true,
                Urls = new[] { url },
                StartAdminInterface = true,
                ReadStaticMappings  = false,
                WatchStaticMappings = false,
                WatchStaticMappingsInSubdirectories = false,
                Logger = new WireMockConsoleLogger()
            });

            Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));

            server.SetBasicAuthentication("a", "b");

            var settings = new WireMockOpenApiParserSettings
            {
                PathPatternToUse = ExampleValueType.Wildcard
            };

            server.WithMappingFromOpenApiFile(path, settings, out var diag);

            return(server);
        }
Beispiel #2
0
        public static void RunServer(string path)
        {
            string url1 = "http://localhost:9091/";

            var server = WireMockServer.Start(new WireMockServerSettings
            {
                AllowCSharpCodeMatcher = true,
                Urls = new[] { url1 },
                StartAdminInterface = true,
                ReadStaticMappings  = false,
                WatchStaticMappings = false,
                WatchStaticMappingsInSubdirectories = false,
                Logger = new WireMockConsoleLogger()
            });

            Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));

            server.SetBasicAuthentication("a", "b");

            var settings = new WireMockOpenApiParserSettings
            {
                PathPatternToUse = ExampleValueType.Wildcard
            };

            server.WithMappingFromOpenApiFile(path, settings, out var diag);

            Console.WriteLine("Press any key to stop the server");
            System.Console.ReadKey();
            server.Stop();
        }
Beispiel #3
0
 public ExampleValueGenerator(WireMockOpenApiParserSettings settings)
 {
     _settings = settings ?? throw new ArgumentNullException(nameof(settings));
     if (_settings.DynamicExamples)
     {
         _settings.ExampleValues = new WireMockOpenApiParserDynamicExampleValues();
     }
     else
     {
         _settings.ExampleValues = new WireMockOpenApiParserExampleValues();
     }
 }
Beispiel #4
0
        public IEnumerable <MappingModel> FromFile(string path, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
        {
            OpenApiDocument document;

            if (Path.GetExtension(path).EndsWith("raml", StringComparison.OrdinalIgnoreCase))
            {
                diagnostic = new OpenApiDiagnostic();
                document   = new RamlConverter().ConvertToOpenApiDocument(path);
            }
            else
            {
                var reader = new OpenApiStreamReader();
                document = reader.Read(File.OpenRead(path), out diagnostic);
            }

            return(FromDocument(document, settings));
        }
Beispiel #5
0
 public IEnumerable <MappingModel> FromDocument(OpenApiDocument openApiDocument, WireMockOpenApiParserSettings settings = null)
 {
     return(new OpenApiPathsMapper(settings).ToMappingModels(openApiDocument.Paths));
 }
Beispiel #6
0
 public IEnumerable <MappingModel> FromStream(Stream stream, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
 {
     return(FromDocument(_reader.Read(stream, out diagnostic), settings));
 }
Beispiel #7
0
 public OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
 {
     _settings = settings ?? throw new ArgumentNullException(nameof(settings));
     _exampleValueGenerator = new ExampleValueGenerator(settings);
 }
Beispiel #8
0
        public static IWireMockServer WithMappingFromOpenApiDocument(this IWireMockServer server, OpenApiDocument document, WireMockOpenApiParserSettings settings = null)
        {
            Guard.NotNull(server, nameof(server));
            Guard.NotNull(document, nameof(document));

            var mappings = new WireMockOpenApiParser().FromDocument(document, settings);

            return(server.WithMapping(mappings.ToArray()));
        }
Beispiel #9
0
        public static IWireMockServer WithMappingFromOpenApiStream(this IWireMockServer server, Stream stream, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
        {
            Guard.NotNull(server, nameof(server));
            Guard.NotNull(stream, nameof(stream));
            Guard.NotNull(settings, nameof(settings));

            var mappings = new WireMockOpenApiParser().FromStream(stream, settings, out diagnostic);

            return(server.WithMapping(mappings.ToArray()));
        }
Beispiel #10
0
        public static IWireMockServer WithMappingFromOpenApiFile(this IWireMockServer server, string path, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
        {
            Guard.NotNull(server, nameof(server));
            Guard.NotNullOrEmpty(path, nameof(path));

            var mappings = new WireMockOpenApiParser().FromFile(path, settings, out diagnostic);

            return(server.WithMapping(mappings.ToArray()));
        }