diff --git a/src/WireMock.Net.StandAlone/StandAloneApp.cs b/src/WireMock.Net.StandAlone/StandAloneApp.cs index a4d3a9d1..9ce3c969 100644 --- a/src/WireMock.Net.StandAlone/StandAloneApp.cs +++ b/src/WireMock.Net.StandAlone/StandAloneApp.cs @@ -37,30 +37,31 @@ namespace WireMock.Net.StandAlone [ValueArgument(typeof(string), "X509Certificate2ThumbprintOrSubjectName", Description = "The X509Certificate2 Thumbprint or SubjectName to use.", Optional = true)] public string X509Certificate2ThumbprintOrSubjectName { get; set; } + + [ValueArgument(typeof(string), "AdminUsername", Description = "The username needed for __admin access.", Optional = true)] + public string AdminUsername { get; set; } + + [ValueArgument(typeof(string), "AdminPassword", Description = "The password needed for __admin access.", Optional = true)] + public string AdminPassword { get; set; } } /// - /// Start WireMock.Net standalone bases on the FluentMockServerSettings. + /// Start WireMock.Net standalone based on the FluentMockServerSettings. /// /// The FluentMockServerSettings - /// Allow Partial Mapping (default set to false). - public static FluentMockServer Start([NotNull] FluentMockServerSettings settings, bool allowPartialMapping = false) + [PublicAPI] + public static FluentMockServer Start([NotNull] FluentMockServerSettings settings) { Check.NotNull(settings, nameof(settings)); - var server = FluentMockServer.Start(settings); - if (allowPartialMapping) - { - server.AllowPartialMapping(); - } - - return server; + return FluentMockServer.Start(settings); } /// /// Start WireMock.Net standalone bases on the commandline arguments. /// /// The commandline arguments + [PublicAPI] public static FluentMockServer Start([NotNull] string[] args) { Check.NotNull(args, nameof(args)); @@ -83,6 +84,9 @@ namespace WireMock.Net.StandAlone Urls = options.Urls.ToArray(), StartAdminInterface = options.StartAdminInterface, ReadStaticMappings = options.ReadStaticMappings, + AllowPartialMapping = options.AllowPartialMapping, + AdminUsername = options.AdminUsername, + AdminPassword = options.AdminPassword }; if (!string.IsNullOrEmpty(options.ProxyURL)) @@ -95,7 +99,7 @@ namespace WireMock.Net.StandAlone }; } - FluentMockServer server = Start(settings, options.AllowPartialMapping); + FluentMockServer server = Start(settings); Console.WriteLine("WireMock.Net server listening at {0}", string.Join(" and ", server.Urls)); diff --git a/src/WireMock.Net/Server/FluentMockServer.cs b/src/WireMock.Net/Server/FluentMockServer.cs index d535f014..88239447 100644 --- a/src/WireMock.Net/Server/FluentMockServer.cs +++ b/src/WireMock.Net/Server/FluentMockServer.cs @@ -173,8 +173,18 @@ namespace WireMock.Server _httpServer.StartAsync(); + if (settings.AllowPartialMapping == true) + { + AllowPartialMapping(); + } + if (settings.StartAdminInterface == true) { + if (!string.IsNullOrEmpty(settings.AdminUsername) && !string.IsNullOrEmpty(settings.AdminPassword)) + { + SetBasicAuthentication(settings.AdminUsername, settings.AdminPassword); + } + InitAdmin(); } diff --git a/src/WireMock.Net/Settings/FluentMockServerSettings.cs b/src/WireMock.Net/Settings/FluentMockServerSettings.cs index 548af56b..936b6eab 100644 --- a/src/WireMock.Net/Settings/FluentMockServerSettings.cs +++ b/src/WireMock.Net/Settings/FluentMockServerSettings.cs @@ -54,5 +54,20 @@ /// StartTimeout /// public int StartTimeout { get; set; } = 10000; + + /// + /// Allow Partial Mapping (default set to false). + /// + public bool? AllowPartialMapping { get; set; } + + /// + /// The username needed for __admin access. + /// + public string AdminUsername { get; set; } + + /// + /// The password needed for __admin access. + /// + public string AdminPassword { get; set; } } } \ No newline at end of file