mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-26 02:38:54 +02:00
Fix ProtoBuf mapping.json (#1236)
* Fix ProtoBuf Mappings * [Fact(Skip = "#1233")] * fix? * PortUtils
This commit is contained in:
@@ -184,124 +184,7 @@ public partial class WireMockAdminApiTests
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, null)]
|
||||
[InlineData(-1, -1)]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(200, 200)]
|
||||
[InlineData("200", "200")]
|
||||
public async Task IWireMockAdminApi_PostMappingAsync_WithStatusCode(object statusCode, object expectedStatusCode)
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var model = new MappingModel
|
||||
{
|
||||
Request = new RequestModel { Path = "/1" },
|
||||
Response = new ResponseModel { Body = "txt", StatusCode = statusCode },
|
||||
Priority = 500,
|
||||
Title = "test"
|
||||
};
|
||||
var result = await api.PostMappingAsync(model).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsNotNull();
|
||||
Check.That(result.Status).IsNotNull();
|
||||
Check.That(result.Guid).IsNotNull();
|
||||
|
||||
var mapping = server.Mappings.Single(m => m.Priority == 500);
|
||||
Check.That(mapping).IsNotNull();
|
||||
Check.That(mapping.Title).Equals("test");
|
||||
|
||||
var response = await mapping.ProvideResponseAsync(new RequestMessage(new UrlDetails("http://localhost/1"), "GET", "")).ConfigureAwait(false);
|
||||
Check.That(response.Message.StatusCode).Equals(expectedStatusCode);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_PostMappingsAsync()
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var model1 = new MappingModel
|
||||
{
|
||||
Request = new RequestModel { Path = "/1" },
|
||||
Response = new ResponseModel { Body = "txt 1" },
|
||||
Title = "test 1"
|
||||
};
|
||||
var model2 = new MappingModel
|
||||
{
|
||||
Request = new RequestModel { Path = "/2" },
|
||||
Response = new ResponseModel { Body = "txt 2" },
|
||||
Title = "test 2"
|
||||
};
|
||||
var result = await api.PostMappingsAsync(new[] { model1, model2 }).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsNotNull();
|
||||
Check.That(result.Status).IsNotNull();
|
||||
Check.That(result.Guid).IsNull();
|
||||
Check.That(server.Mappings.Where(m => !m.IsAdminInterface)).HasSize(2);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_PostMappingsAsync_WithDuplicateGuids_Should_Return_400()
|
||||
{
|
||||
// Arrange
|
||||
var guid = Guid.Parse("1b731398-4a5b-457f-a6e3-d65e541c428f");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var model1WithGuid = new MappingModel
|
||||
{
|
||||
Guid = guid,
|
||||
Request = new RequestModel { Path = "/1g" },
|
||||
Response = new ResponseModel { Body = "txt 1g" },
|
||||
Title = "test 1g"
|
||||
};
|
||||
var model2WithGuid = new MappingModel
|
||||
{
|
||||
Guid = guid,
|
||||
Request = new RequestModel { Path = "/2g" },
|
||||
Response = new ResponseModel { Body = "txt 2g" },
|
||||
Title = "test 2g"
|
||||
};
|
||||
var model1 = new MappingModel
|
||||
{
|
||||
Request = new RequestModel { Path = "/1" },
|
||||
Response = new ResponseModel { Body = "txt 1" },
|
||||
Title = "test 1"
|
||||
};
|
||||
var model2 = new MappingModel
|
||||
{
|
||||
Request = new RequestModel { Path = "/2" },
|
||||
Response = new ResponseModel { Body = "txt 2" },
|
||||
Title = "test 2"
|
||||
};
|
||||
|
||||
var models = new[]
|
||||
{
|
||||
model1WithGuid,
|
||||
model2WithGuid,
|
||||
model1,
|
||||
model2
|
||||
};
|
||||
|
||||
var sutMethod = async () => await api.PostMappingsAsync(models);
|
||||
var exceptionAssertions = await sutMethod.Should().ThrowAsync<ApiException>();
|
||||
exceptionAssertions.Which.Content.Should().Be(@"{""Status"":""The following Guids are duplicate : '1b731398-4a5b-457f-a6e3-d65e541c428f' (Parameter 'mappingModels')""}");
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_FindRequestsAsync()
|
||||
@@ -1140,5 +1023,10 @@ text
|
||||
// Assert
|
||||
status.Status.Should().Be("Static Mappings reloaded");
|
||||
}
|
||||
|
||||
private static string ReadMappingFile(string filename)
|
||||
{
|
||||
return File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "__admin", "mappings", filename));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user