Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose more settings to stand-alone app #40

Merged
merged 1 commit into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/WireMock.Net.StandAlone/StandAloneApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,31 @@ private class Options

[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; }
}

/// <summary>
/// Start WireMock.Net standalone bases on the FluentMockServerSettings.
/// Start WireMock.Net standalone based on the FluentMockServerSettings.
/// </summary>
/// <param name="settings">The FluentMockServerSettings</param>
/// <param name="allowPartialMapping">Allow Partial Mapping (default set to false).</param>
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);
}

/// <summary>
/// Start WireMock.Net standalone bases on the commandline arguments.
/// </summary>
/// <param name="args">The commandline arguments</param>
[PublicAPI]
public static FluentMockServer Start([NotNull] string[] args)
{
Check.NotNull(args, nameof(args));
Expand All @@ -83,6 +84,9 @@ public static FluentMockServer Start([NotNull] string[] args)
Urls = options.Urls.ToArray(),
StartAdminInterface = options.StartAdminInterface,
ReadStaticMappings = options.ReadStaticMappings,
AllowPartialMapping = options.AllowPartialMapping,
AdminUsername = options.AdminUsername,
AdminPassword = options.AdminPassword
};

if (!string.IsNullOrEmpty(options.ProxyURL))
Expand All @@ -95,7 +99,7 @@ public static FluentMockServer Start([NotNull] string[] args)
};
}

FluentMockServer server = Start(settings, options.AllowPartialMapping);
FluentMockServer server = Start(settings);

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

Expand Down
10 changes: 10 additions & 0 deletions src/WireMock.Net/Server/FluentMockServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,18 @@ private FluentMockServer(FluentMockServerSettings settings)

_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();
}

Expand Down
15 changes: 15 additions & 0 deletions src/WireMock.Net/Settings/FluentMockServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,20 @@ public class FluentMockServerSettings
/// StartTimeout
/// </summary>
public int StartTimeout { get; set; } = 10000;

/// <summary>
/// Allow Partial Mapping (default set to false).
/// </summary>
public bool? AllowPartialMapping { get; set; }

/// <summary>
/// The username needed for __admin access.
/// </summary>
public string AdminUsername { get; set; }

/// <summary>
/// The password needed for __admin access.
/// </summary>
public string AdminPassword { get; set; }
}
}