| | | 1 | | using System.Linq; |
| | | 2 | | using WireMock.Server; |
| | | 3 | | using WireMock.Settings; |
| | | 4 | | using WireMock.Validation; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using WireMock.Logging; |
| | | 7 | | |
| | | 8 | | namespace WireMock.Net.StandAlone |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// The StandAloneApp |
| | | 12 | | /// </summary> |
| | | 13 | | public static class StandAloneApp |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Start WireMock.Net standalone Server based on the FluentMockServerSettings. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="settings">The FluentMockServerSettings</param> |
| | | 19 | | [PublicAPI] |
| | | 20 | | public static FluentMockServer Start([NotNull] IFluentMockServerSettings settings) |
| | 0 | 21 | | { |
| | 0 | 22 | | Check.NotNull(settings, nameof(settings)); |
| | | 23 | | |
| | 0 | 24 | | var server = FluentMockServer.Start(settings); |
| | | 25 | | |
| | 0 | 26 | | settings.Logger.Info("WireMock.Net server listening at {0}", string.Join(",", server.Urls)); |
| | | 27 | | |
| | 0 | 28 | | return server; |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Start WireMock.Net standalone Server based on the commandline arguments. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <param name="args">The commandline arguments</param> |
| | | 35 | | /// <param name="logger">The logger</param> |
| | | 36 | | [PublicAPI] |
| | | 37 | | public static FluentMockServer Start([NotNull] string[] args, [CanBeNull] IWireMockLogger logger = null) |
| | 0 | 38 | | { |
| | 0 | 39 | | Check.NotNull(args, nameof(args)); |
| | | 40 | | |
| | 0 | 41 | | var parser = new SimpleCommandLineParser(); |
| | 0 | 42 | | parser.Parse(args); |
| | | 43 | | |
| | 0 | 44 | | var settings = new FluentMockServerSettings |
| | 0 | 45 | | { |
| | 0 | 46 | | StartAdminInterface = parser.GetBoolValue("StartAdminInterface", true), |
| | 0 | 47 | | ReadStaticMappings = parser.GetBoolValue("ReadStaticMappings"), |
| | 0 | 48 | | WatchStaticMappings = parser.GetBoolValue("WatchStaticMappings"), |
| | 0 | 49 | | AllowPartialMapping = parser.GetBoolValue("AllowPartialMapping", false), |
| | 0 | 50 | | AdminUsername = parser.GetStringValue("AdminUsername"), |
| | 0 | 51 | | AdminPassword = parser.GetStringValue("AdminPassword"), |
| | 0 | 52 | | MaxRequestLogCount = parser.GetIntValue("MaxRequestLogCount"), |
| | 0 | 53 | | RequestLogExpirationDuration = parser.GetIntValue("RequestLogExpirationDuration"), |
| | 0 | 54 | | }; |
| | | 55 | | |
| | 0 | 56 | | if (logger != null) |
| | 0 | 57 | | { |
| | 0 | 58 | | settings.Logger = logger; |
| | 0 | 59 | | } |
| | | 60 | | |
| | 0 | 61 | | if (parser.Contains("Port")) |
| | 0 | 62 | | { |
| | 0 | 63 | | settings.Port = parser.GetIntValue("Port"); |
| | 0 | 64 | | } |
| | | 65 | | else |
| | 0 | 66 | | { |
| | 0 | 67 | | settings.Urls = parser.GetValues("Urls", new[] { "http://*:9091/" }); |
| | 0 | 68 | | } |
| | | 69 | | |
| | 0 | 70 | | string proxyURL = parser.GetStringValue("ProxyURL"); |
| | 0 | 71 | | if (!string.IsNullOrEmpty(proxyURL)) |
| | 0 | 72 | | { |
| | 0 | 73 | | settings.ProxyAndRecordSettings = new ProxyAndRecordSettings |
| | 0 | 74 | | { |
| | 0 | 75 | | Url = proxyURL, |
| | 0 | 76 | | SaveMapping = parser.GetBoolValue("SaveMapping"), |
| | 0 | 77 | | SaveMappingToFile = parser.GetBoolValue("SaveMappingToFile"), |
| | 0 | 78 | | ClientX509Certificate2ThumbprintOrSubjectName = parser.GetStringValue("ClientX509Certificate2Thumbpr |
| | 0 | 79 | | BlackListedHeaders = parser.GetValues("BlackListedHeaders") |
| | 0 | 80 | | }; |
| | 0 | 81 | | } |
| | | 82 | | |
| | 0 | 83 | | settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'"))); |
| | | 84 | | |
| | 0 | 85 | | FluentMockServer server = Start(settings); |
| | | 86 | | |
| | 0 | 87 | | return server; |
| | 0 | 88 | | } |
| | | 89 | | } |
| | | 90 | | } |