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

MappingModels #298

Merged
merged 3 commits into from
Jul 16, 2019
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>1.0.22</VersionPrefix>
<VersionPrefix>1.0.23</VersionPrefix>
</PropertyGroup>

<Choose>
Expand Down
2 changes: 1 addition & 1 deletion GitHubReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes

GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --version 1.0.22.0
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --version 1.0.23.0
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ steps:
%USERPROFILE%\.dotnet\tools\dotnet-sonarscanner end /d:sonar.login="$(SONAR_TOKEN)"
displayName: End SonarScanner

- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
displayName: 'WhiteSource Bolt'

# Upload coverage to codecov.io
- script: |
%USERPROFILE%\.nuget\packages\codecov\1.1.0\tools\codecov.exe -f "./test/WireMock.Net.Tests/coverage.opencover.xml" -t $(CODECOV_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions examples/WireMock.Net.Console.Net452.Classic/MainApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ public static void Run()
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { Id = "5bdf076c-5654-4b3e-842c-7caf1fabf8c9" }));

System.Console.WriteLine(JsonConvert.SerializeObject(server.MappingModels, Formatting.Indented));

System.Console.WriteLine("Press any key to stop the server");
System.Console.ReadKey();
server.Stop();
Expand Down
13 changes: 5 additions & 8 deletions src/WireMock.Net/Server/FluentMockServer.Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,14 @@ private static string SanitizeFileName(string name, char replaceChar = '_')
{
return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, replaceChar));
}
private IEnumerable<MappingModel> ToMappingModels()
{
return Mappings.Where(m => !m.IsAdminInterface).Select(MappingConverter.ToMappingModel);
}

private ResponseMessage MappingsGet(RequestMessage requestMessage)
{
var result = new List<MappingModel>();
foreach (var mapping in Mappings.Where(m => !m.IsAdminInterface))
{
var model = MappingConverter.ToMappingModel(mapping);
result.Add(model);
}

return ToJson(result);
return ToJson(ToMappingModels());
}

private ResponseMessage MappingsPost(RequestMessage requestMessage)
Expand Down
7 changes: 7 additions & 0 deletions src/WireMock.Net/Server/FluentMockServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading;
using WireMock.Admin.Mappings;
using WireMock.Exceptions;
using WireMock.Handlers;
using WireMock.Logging;
Expand Down Expand Up @@ -55,6 +56,12 @@ public partial class FluentMockServer : IDisposable
[PublicAPI]
public IEnumerable<IMapping> Mappings => _options.Mappings.Values.ToArray();

/// <summary>
/// Gets the mappings as MappingModels.
/// </summary>
[PublicAPI]
public IEnumerable<MappingModel> MappingModels => ToMappingModels();

/// <summary>
/// Gets the scenarios.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions test/WireMock.Net.Tests/FluentMockServerTests.Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public void FluentMockServer_Admin_ResetMappings()
server.ReadStaticMappings(folder);

Check.That(server.Mappings).HasSize(5);
Check.That(server.MappingModels).HasSize(5);

// Act
server.ResetMappings();

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

[Fact]
Expand Down