mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-26 02:08:29 +02:00
Version 2.x (#1359)
* Version 2.x * Setup .NET 9 * 12 * cleanup some #if for NETSTANDARD1_3 * cleanup + fix tests for net8 * openapi * NO ConfigureAwait(false) + cleanup * . * #endif * HashSet * WireMock.Net.NUnit * HttpContext * Add WebSockets (#1423) * Add WebSockets * Add tests * fix * more tests * Add tests * ... * remove IOwin * - * tests * fluent * ok * match * . * byte[] * x * func * func * byte * trans * ... * frameworks......... * jmes * xxx * sc * using var httpClient = new HttpClient(); * usings * maxRetries * up * xunit v3 * ct * --- * ct * ct2 * T Unit * WireMock.Net.TUnitTests / 10 * t unit first * --project * no tunit * t2 * --project * --project * ci - --project * publish ./test/wiremock-coverage.xml * windows * . * log * ... * log * goed * BodyType * . * . * --scenario * ... * pact * ct * . * WireMock.Net.RestClient.AwesomeAssertions (#1427) * WireMock.Net.RestClient.AwesomeAssertions * ok * atpath * fix test * sonar fixes * ports * proxy test * FIX? * --- * await Task.Delay(100, _ct); * ? * --project * Aspire: use IDistributedApplicationEventingSubscriber (#1428) * broadcast * ok * more tsts * . * Collection * up * . * 2 * remove nfluent * <VersionPrefix>2.0.0-preview-02</VersionPrefix> * ... * . * nuget icon * . * <PackageReference Include="JmesPath.Net" Version="1.1.0" /> * x * 500 * . * fix some warnings * ws
This commit is contained in:
@@ -1,20 +1,16 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
|
||||
using RestEase;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Client;
|
||||
using WireMock.Constants;
|
||||
using WireMock.Models;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.AdminApi;
|
||||
|
||||
@@ -35,17 +31,18 @@ public partial class WireMockAdminApiTests
|
||||
public async Task HttpClient_PostMappingsAsync_ForProtoBufMapping(string mappingFile, string guid)
|
||||
{
|
||||
// Arrange
|
||||
var cancelationToken = TestContext.Current.CancellationToken;
|
||||
var mappingsJson = ReadMappingFile(mappingFile);
|
||||
|
||||
using var server = WireMockServer.StartWithAdminInterface();
|
||||
var httpClient = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, WireMockConstants.ContentTypeJson));
|
||||
var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, WireMockConstants.ContentTypeJson), cancelationToken);
|
||||
result.EnsureSuccessStatusCode();
|
||||
|
||||
// Assert
|
||||
var mapping = await httpClient.GetStringAsync($"/__admin/mappings/{guid}");
|
||||
var mapping = await httpClient.GetStringAsync($"/__admin/mappings/{guid}", cancelationToken);
|
||||
mapping = RemoveLineContainingUpdatedAt(mapping);
|
||||
mapping.Should().Be(mappingsJson);
|
||||
}
|
||||
@@ -72,15 +69,15 @@ public partial class WireMockAdminApiTests
|
||||
Title = "test 2",
|
||||
Description = "description 2"
|
||||
};
|
||||
var result = await api.PostMappingsAsync(new[] { model1, model2 }).ConfigureAwait(false);
|
||||
var result = await api.PostMappingsAsync([model1, model2], TestContext.Current.CancellationToken);
|
||||
|
||||
// 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);
|
||||
Check.That(server.Mappings.Single(x => x.Title == "test 1").Description).IsEqualTo("description 1");
|
||||
Check.That(server.Mappings.Single(x => x.Title == "test 2").Description).IsEqualTo("description 2");
|
||||
result.Should().NotBeNull();
|
||||
result.Status.Should().NotBeNull();
|
||||
result.Guid.Should().BeNull();
|
||||
server.Mappings.Where(m => !m.IsAdminInterface).Should().HaveCount(2);
|
||||
server.Mappings.Single(x => x.Title == "test 1").Description.Should().Be("description 1");
|
||||
server.Mappings.Single(x => x.Title == "test 2").Description.Should().Be("description 2");
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -91,7 +88,7 @@ public partial class WireMockAdminApiTests
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(200, 200)]
|
||||
[InlineData("200", "200")]
|
||||
public async Task IWireMockAdminApi_PostMappingAsync_WithStatusCode(object statusCode, object expectedStatusCode)
|
||||
public async Task IWireMockAdminApi_PostMappingAsync_WithStatusCode(object? statusCode, object? expectedStatusCode)
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
@@ -105,19 +102,19 @@ public partial class WireMockAdminApiTests
|
||||
Priority = 500,
|
||||
Title = "test"
|
||||
};
|
||||
var result = await api.PostMappingAsync(model).ConfigureAwait(false);
|
||||
var result = await api.PostMappingAsync(model, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsNotNull();
|
||||
Check.That(result.Status).IsNotNull();
|
||||
Check.That(result.Guid).IsNotNull();
|
||||
result.Should().NotBeNull();
|
||||
result.Status.Should().NotBeNull();
|
||||
result.Guid.Should().NotBeNull();
|
||||
|
||||
var mapping = server.Mappings.Single(m => m.Priority == 500);
|
||||
Check.That(mapping).IsNotNull();
|
||||
Check.That(mapping.Title).Equals("test");
|
||||
mapping.Should().NotBeNull();
|
||||
mapping.Title.Should().Be("test");
|
||||
|
||||
var response = await mapping.ProvideResponseAsync(new RequestMessage(new UrlDetails("http://localhost/1"), "GET", "")).ConfigureAwait(false);
|
||||
Check.That(response.Message.StatusCode).Equals(expectedStatusCode);
|
||||
var response = await mapping.ProvideResponseAsync(Mock.Of<HttpContext>(), new RequestMessage(new UrlDetails("http://localhost/1"), "GET", ""));
|
||||
response.Message.StatusCode.Should().Be(expectedStatusCode);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -172,5 +169,4 @@ public partial class WireMockAdminApiTests
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user