Version 2.x

This commit is contained in:
Stef Heyenrath
2025-08-30 10:24:07 +02:00
parent 358590918e
commit 034766a2d6
83 changed files with 1077 additions and 999 deletions

View File

@@ -1,6 +1,6 @@
// Copyright © WireMock.Net
#if !(NET452 || NET461 || NETCOREAPP3_1)
//#if !(NET452 || NET461 || NETCOREAPP3_1)
using System;
using System.Collections.Generic;
using System.IO;
@@ -69,10 +69,10 @@ public partial class WireMockAdminApiTests
.WithAuthorization(adminUsername, adminPassword);
// Act 1
await api.WaitForHealthAsync().ConfigureAwait(false);
await api.WaitForHealthAsync();
// Act 2
var status = await api.GetHealthAsync().ConfigureAwait(false);
var status = await api.GetHealthAsync();
status.Should().Be("Healthy");
}
@@ -102,7 +102,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act
var settings = await api.GetSettingsAsync().ConfigureAwait(false);
var settings = await api.GetSettingsAsync();
Check.That(settings).IsNotNull();
}
@@ -118,7 +118,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0] + "/foo");
// Act
var settings = await api.GetSettingsAsync().ConfigureAwait(false);
var settings = await api.GetSettingsAsync();
// Assert
Check.That(settings).IsNotNull();
@@ -137,7 +137,7 @@ public partial class WireMockAdminApiTests
// Act
var settings = new SettingsModel();
var status = await api.PostSettingsAsync(settings).ConfigureAwait(false);
var status = await api.PostSettingsAsync(settings);
Check.That(status.Status).Equals("Settings updated");
}
@@ -150,7 +150,7 @@ public partial class WireMockAdminApiTests
// Act
var settings = new SettingsModel();
var status = await api.PutSettingsAsync(settings).ConfigureAwait(false);
var status = await api.PutSettingsAsync(settings);
Check.That(status.Status).Equals("Settings updated");
}
@@ -170,7 +170,7 @@ public partial class WireMockAdminApiTests
Priority = 500,
Title = "test"
};
var result = await api.PutMappingAsync(new Guid("a0000000-0000-0000-0000-000000000000"), model).ConfigureAwait(false);
var result = await api.PutMappingAsync(new Guid("a0000000-0000-0000-0000-000000000000"), model);
// Assert
Check.That(result).IsNotNull();
@@ -200,11 +200,11 @@ public partial class WireMockAdminApiTests
.RespondWith(Response.Create());
var serverUrl = "http://localhost:" + server.Ports[0];
await new HttpClient().GetAsync(serverUrl + "/foo").ConfigureAwait(false);
await new HttpClient().GetAsync(serverUrl + "/foo");
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
// Act
var requests = await api.FindRequestsAsync(new RequestModel { Methods = new[] { "GET" } }).ConfigureAwait(false);
var requests = await api.FindRequestsAsync(new RequestModel { Methods = new[] { "GET" } });
// Assert
requests.Should().HaveCount(1);
@@ -231,12 +231,12 @@ public partial class WireMockAdminApiTests
var serverUrl = "http://localhost:" + server.Ports[0];
using var client = new HttpClient();
await client.GetAsync(serverUrl + "/foo").ConfigureAwait(false);
await client.GetAsync(serverUrl + "/foo?bar=baz").ConfigureAwait(false);
await client.GetAsync(serverUrl + "/foo");
await client.GetAsync(serverUrl + "/foo?bar=baz");
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
// Act
var logEntryModels = await api.FindRequestsByMappingGuidAsync(mappingGuid).ConfigureAwait(false);
var logEntryModels = await api.FindRequestsByMappingGuidAsync(mappingGuid);
// Assert
logEntryModels.Should().HaveCount(2);
@@ -270,11 +270,11 @@ public partial class WireMockAdminApiTests
.RespondWith(Response.Create());
var serverUrl = "http://localhost:" + server.Ports[0];
await new HttpClient().GetAsync(serverUrl + "/foo").ConfigureAwait(false);
await new HttpClient().GetAsync(serverUrl + "/foo");
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
// Act
var logEntryModels = await api.FindRequestsByMappingGuidAsync(Guid.NewGuid()).ConfigureAwait(false);
var logEntryModels = await api.FindRequestsByMappingGuidAsync(Guid.NewGuid());
// Assert
logEntryModels.Should().BeEmpty();
@@ -307,11 +307,11 @@ public partial class WireMockAdminApiTests
Logger = new WireMockNullLogger()
});
var serverUrl = "http://localhost:" + server.Ports[0];
await new HttpClient().GetAsync(serverUrl + "/foo").ConfigureAwait(false);
await new HttpClient().GetAsync(serverUrl + "/foo");
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
// Act
var requests = await api.GetRequestsAsync().ConfigureAwait(false);
var requests = await api.GetRequestsAsync();
// Assert
Check.That(requests).HasSize(1);
@@ -347,7 +347,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
// Act
var requests = await api.GetRequestsAsync().ConfigureAwait(false);
var requests = await api.GetRequestsAsync();
// Assert
Check.That(requests).HasSize(1);
@@ -384,7 +384,7 @@ public partial class WireMockAdminApiTests
},
Response = new ResponseModel { Body = "world" }
};
var postMappingResult = await api.PostMappingAsync(model).ConfigureAwait(false);
var postMappingResult = await api.PostMappingAsync(model);
// Assert
postMappingResult.Should().NotBeNull();
@@ -392,7 +392,7 @@ public partial class WireMockAdminApiTests
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
mapping.Should().NotBeNull();
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
var getMappingResult = await api.GetMappingAsync(guid);
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
@@ -435,7 +435,7 @@ public partial class WireMockAdminApiTests
}
}
};
var postMappingResult = await api.PostMappingAsync(model).ConfigureAwait(false);
var postMappingResult = await api.PostMappingAsync(model);
// Assert
postMappingResult.Should().NotBeNull();
@@ -443,7 +443,7 @@ public partial class WireMockAdminApiTests
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
mapping.Should().NotBeNull();
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
var getMappingResult = await api.GetMappingAsync(guid);
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
@@ -475,7 +475,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
// Act
var requests = await api.GetRequestsAsync().ConfigureAwait(false);
var requests = await api.GetRequestsAsync();
// Assert
Check.That(requests).HasSize(1);
@@ -504,7 +504,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act
var request = await api.PostFileAsync("filename.txt", "abc").ConfigureAwait(false);
var request = await api.PostFileAsync("filename.txt", "abc");
// Assert
Check.That(request.Guid).IsNull();
@@ -537,7 +537,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act
var request = await api.PutFileAsync("filename.txt", "abc-abc").ConfigureAwait(false);
var request = await api.PutFileAsync("filename.txt", "abc-abc");
// Assert
Check.That(request.Guid).IsNull();
@@ -568,7 +568,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act and Assert
Check.ThatAsyncCode(() => api.PutFileAsync("filename.txt", "xxx")).Throws<ApiException>();
Check.ThatCode(() => api.PutFileAsync("filename.txt", "xxx")).Throws<ApiException>();
// Verify
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
@@ -595,7 +595,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act and Assert
Check.ThatAsyncCode(() => api.GetFileAsync("filename.txt")).Throws<ApiException>();
Check.ThatCode(() => api.GetFileAsync("filename.txt")).Throws<ApiException>();
// Verify
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
@@ -623,7 +623,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act
string file = await api.GetFileAsync("filename.txt").ConfigureAwait(false);
string file = await api.GetFileAsync("filename.txt");
// Assert
Check.That(file).Equals(data);
@@ -654,7 +654,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act
await api.DeleteFileAsync("filename.txt").ConfigureAwait(false);
await api.DeleteFileAsync("filename.txt");
// Verify
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
@@ -682,7 +682,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act and Assert
Check.ThatAsyncCode(() => api.DeleteFileAsync("filename.txt")).Throws<ApiException>();
Check.ThatCode(() => api.DeleteFileAsync("filename.txt")).Throws<ApiException>();
// Verify
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
@@ -708,7 +708,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act and Assert
Check.ThatAsyncCode(() => api.FileExistsAsync("filename.txt")).Throws<ApiException>();
Check.ThatCode(() => api.FileExistsAsync("filename.txt")).Throws<ApiException>();
// Verify
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
@@ -726,7 +726,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act
var status = await api.DeleteScenarioAsync(name).ConfigureAwait(false);
var status = await api.DeleteScenarioAsync(name);
status.Status.Should().Be("No scenario found by name 'x'.");
}
@@ -739,7 +739,7 @@ public partial class WireMockAdminApiTests
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act
var status = await api.ResetScenarioAsync(name).ConfigureAwait(false);
var status = await api.ResetScenarioAsync(name);
status.Status.Should().Be("No scenario found by name 'x'.");
}
@@ -756,7 +756,7 @@ public partial class WireMockAdminApiTests
{
State = null
};
var status = await api.PutScenarioStateAsync("x", update).ConfigureAwait(false);
var status = await api.PutScenarioStateAsync("x", update);
status.Status.Should().Be("No scenario found by name 'x'.");
}
@@ -790,7 +790,7 @@ public partial class WireMockAdminApiTests
{
State = null
};
var status = await api.PutScenarioStateAsync("s1", update).ConfigureAwait(false);
var status = await api.PutScenarioStateAsync("s1", update);
status.Status.Should().Be("Scenario state set to ''");
}
@@ -817,7 +817,7 @@ public partial class WireMockAdminApiTests
// Act
var api = RestClient.For<IWireMockAdminApi>(server.Url);
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
var getMappingResult = await api.GetMappingAsync(guid);
// Assert
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
@@ -852,10 +852,10 @@ public partial class WireMockAdminApiTests
// Act
var api = RestClient.For<IWireMockAdminApi>(server.Url);
var mappings = await api.GetMappingsAsync().ConfigureAwait(false);
var mappings = await api.GetMappingsAsync();
mappings.Should().HaveCount(1);
var code = await api.GetMappingCodeAsync(guid).ConfigureAwait(false);
var code = await api.GetMappingCodeAsync(guid);
// Assert
await Verifier.Verify(code).DontScrubDateTimes().DontScrubGuids();
@@ -942,7 +942,7 @@ public partial class WireMockAdminApiTests
.WithGuid(guid5)
.RespondWith(
Response.Create()
.WithStatusCode(HttpStatusCode.AlreadyReported)
.WithStatusCode(HttpStatusCode.Unused)
.WithBodyAsJson(new
{
@as = 1,
@@ -974,10 +974,10 @@ text
// Act
var api = RestClient.For<IWireMockAdminApi>(server.Url);
var mappings = await api.GetMappingsAsync().ConfigureAwait(false);
var mappings = await api.GetMappingsAsync();
mappings.Should().HaveCount(5);
var code = await api.GetMappingsCodeAsync().ConfigureAwait(false);
var code = await api.GetMappingsCodeAsync();
// Assert
await Verifier.Verify(code).DontScrubDateTimes().DontScrubGuids();
@@ -989,13 +989,13 @@ text
public async Task IWireMockAdminApi_OpenApiConvert_Yml()
{
// Arrange
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "petstore.yml"));
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "petstore.yml"));
var server = WireMockServer.StartWithAdminInterface();
var api = RestClient.For<IWireMockAdminApi>(server.Url);
// Act
var mappings = await api.OpenApiConvertAsync(openApiDocument).ConfigureAwait(false);
var mappings = await api.OpenApiConvertAsync(openApiDocument);
// Assert
server.MappingModels.Should().BeEmpty();
@@ -1008,13 +1008,13 @@ text
public async Task IWireMockAdminApi_OpenApiConvert_Json()
{
// Arrange
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "petstore-openapi3.json"));
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "petstore-openapi3.json"));
var server = WireMockServer.StartWithAdminInterface();
var api = RestClient.For<IWireMockAdminApi>(server.Url);
// Act
var mappings = await api.OpenApiConvertAsync(openApiDocument).ConfigureAwait(false);
var mappings = await api.OpenApiConvertAsync(openApiDocument);
// Assert
server.MappingModels.Should().BeEmpty();
@@ -1027,13 +1027,13 @@ text
public async Task IWireMockAdminApi_OpenApiSave_Json()
{
// Arrange
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "petstore-openapi3.json"));
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "petstore-openapi3.json"));
var server = WireMockServer.StartWithAdminInterface();
var api = RestClient.For<IWireMockAdminApi>(server.Url);
// Act
var statusModel = await api.OpenApiSaveAsync(openApiDocument).ConfigureAwait(false);
var statusModel = await api.OpenApiSaveAsync(openApiDocument);
// Assert
statusModel.Status.Should().Be("OpenApi document converted to Mappings");
@@ -1046,13 +1046,13 @@ text
public async Task IWireMockAdminApi_OpenApiSave_Yml()
{
// Arrange
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "petstore.yml"));
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "petstore.yml"));
var server = WireMockServer.StartWithAdminInterface();
var api = RestClient.For<IWireMockAdminApi>(server.Url);
// Act
var mappings = await api.OpenApiConvertAsync(openApiDocument).ConfigureAwait(false);
var mappings = await api.OpenApiConvertAsync(openApiDocument);
// Assert
server.MappingModels.Should().BeEmpty();
@@ -1069,7 +1069,7 @@ text
var api = RestClient.For<IWireMockAdminApi>(server.Url);
// Act
var status = await api.ReloadStaticMappingsAsync().ConfigureAwait(false);
var status = await api.ReloadStaticMappingsAsync();
// Assert
status.Status.Should().Be("Static Mappings reloaded");
@@ -1080,4 +1080,4 @@ text
return File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "__admin", "mappings", filename));
}
}
#endif
//#endif