mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-30 14:22:20 +02:00
Include WireMockOpenApiParser project (#916)
* Fix some nullability warnings for WireMockOpenApiParser * . * . * . * opt * FromText * ab * . * private const string AdminOpenApi = "/__admin/openapi"; * fix test * rnd * . * urldetails * 0 * , * . * tests * . * CompressionUtilsTests * ut * .
This commit is contained in:
62
test/WireMock.Net.Tests/Util/CompressionUtilsTests.cs
Normal file
62
test/WireMock.Net.Tests/Util/CompressionUtilsTests.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using RandomDataGenerator.FieldOptions;
|
||||
using RandomDataGenerator.Randomizers;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class CompressionUtilsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("gzip")]
|
||||
[InlineData("deflate")]
|
||||
public void CompressDecompress_ValidInput_ReturnsOriginalData(string contentEncoding)
|
||||
{
|
||||
// Arrange
|
||||
byte[] data = Encoding.UTF8.GetBytes("Test data for compression");
|
||||
|
||||
// Act
|
||||
byte[] compressedData = CompressionUtils.Compress(contentEncoding, data);
|
||||
byte[] decompressedData = CompressionUtils.Decompress(contentEncoding, compressedData);
|
||||
|
||||
// Assert
|
||||
decompressedData.Should().BeEquivalentTo(data);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("gzip")]
|
||||
[InlineData("deflate")]
|
||||
public void Compress_ValidInput_ReturnsCompressedData(string contentEncoding)
|
||||
{
|
||||
// Arrange
|
||||
var text = RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = "[0-9A-Z]{1000}" }).Generate()!;
|
||||
byte[] data = Encoding.UTF8.GetBytes(text);
|
||||
|
||||
// Act
|
||||
byte[] compressedData = CompressionUtils.Compress(contentEncoding, data);
|
||||
|
||||
// Assert
|
||||
compressedData.Length.Should().BeLessThan(data.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CompressDecompress_InvalidContentEncoding_ThrowsNotSupportedException()
|
||||
{
|
||||
// Arrange
|
||||
byte[] data = Encoding.UTF8.GetBytes("Test data for compression");
|
||||
string contentEncoding = "invalid";
|
||||
|
||||
// Act
|
||||
Action compressAction = () => CompressionUtils.Compress(contentEncoding, data);
|
||||
Action decompressAction = () => CompressionUtils.Decompress(contentEncoding, data);
|
||||
|
||||
// Assert
|
||||
compressAction.Should().Throw<NotSupportedException>()
|
||||
.WithMessage($"ContentEncoding '{contentEncoding}' is not supported.");
|
||||
decompressAction.Should().Throw<NotSupportedException>()
|
||||
.WithMessage($"ContentEncoding '{contentEncoding}' is not supported.");
|
||||
}
|
||||
}
|
||||
83
test/WireMock.Net.Tests/Util/CultureInfoUtilsTests.cs
Normal file
83
test/WireMock.Net.Tests/Util/CultureInfoUtilsTests.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using FluentAssertions;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class CultureInfoUtilsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(null, typeof(CultureInfo))]
|
||||
[InlineData("en-US", typeof(CultureInfo))]
|
||||
[InlineData("fr-FR", typeof(CultureInfo))]
|
||||
[InlineData("es-ES", typeof(CultureInfo))]
|
||||
public void Parse_ValidInputs_ReturnsExpectedCultureInfo(string? value, Type expectedType)
|
||||
{
|
||||
// Act
|
||||
var result = CultureInfoUtils.Parse(value);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType(expectedType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("InvalidCulture")]
|
||||
[InlineData("123456")]
|
||||
public void Parse_InvalidInputs_ReturnsCurrentCulture(string? value)
|
||||
{
|
||||
// Arrange
|
||||
var expectedCulture = CultureInfo.CurrentCulture;
|
||||
|
||||
// Act
|
||||
var result = CultureInfoUtils.Parse(value);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedCulture);
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
[Fact]
|
||||
public void Parse_IntegerInput_ReturnsExpectedCultureInfo()
|
||||
{
|
||||
// Arrange
|
||||
string value = "1033"; // en-US culture identifier
|
||||
var expectedCulture = new CultureInfo(1033);
|
||||
|
||||
// Act
|
||||
var result = CultureInfoUtils.Parse(value);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedCulture);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Fact]
|
||||
public void Parse_CurrentCultureInput_ReturnsCurrentCulture()
|
||||
{
|
||||
// Arrange
|
||||
string value = nameof(CultureInfo.CurrentCulture);
|
||||
var expectedCulture = CultureInfo.CurrentCulture;
|
||||
|
||||
// Act
|
||||
var result = CultureInfoUtils.Parse(value);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedCulture);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_InvariantCultureInput_ReturnsInvariantCulture()
|
||||
{
|
||||
// Arrange
|
||||
string value = nameof(CultureInfo.InvariantCulture);
|
||||
var expectedCulture = CultureInfo.InvariantCulture;
|
||||
|
||||
// Act
|
||||
var result = CultureInfoUtils.Parse(value);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expectedCulture);
|
||||
}
|
||||
}
|
||||
59
test/WireMock.Net.Tests/Util/RegexUtilsTests.cs
Normal file
59
test/WireMock.Net.Tests/Util/RegexUtilsTests.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using FluentAssertions;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class RegexUtilsTests
|
||||
{
|
||||
[Fact]
|
||||
public void GetNamedGroups_ValidRegexWithNamedGroups_ReturnsNamedGroupsDictionary()
|
||||
{
|
||||
// Arrange
|
||||
var pattern = @"^(?<street>\w+)\s(?<number>\d+)$";
|
||||
var input = "MainStreet 123";
|
||||
var regex = new Regex(pattern);
|
||||
|
||||
// Act
|
||||
var namedGroupsDictionary = RegexUtils.GetNamedGroups(regex, input);
|
||||
|
||||
// Assert
|
||||
namedGroupsDictionary.Should().NotBeEmpty()
|
||||
.And.Contain(new KeyValuePair<string, string>("street", "MainStreet"))
|
||||
.And.Contain(new KeyValuePair<string, string>("number", "123"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "test", false, false)]
|
||||
[InlineData(null, "test", false, false)]
|
||||
[InlineData(".*", "test", true, true)]
|
||||
[InlineData("invalid[", "test", false, false)]
|
||||
public void MatchRegex_WithVariousPatterns_ReturnsExpectedResults(
|
||||
string? pattern, string input, bool expectedIsValid, bool expectedResult)
|
||||
{
|
||||
// Act
|
||||
var (isValidResult, matchResult) = RegexUtils.MatchRegex(pattern, input);
|
||||
|
||||
// Assert
|
||||
isValidResult.Should().Be(expectedIsValid);
|
||||
matchResult.Should().Be(expectedResult);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "test", false, false)]
|
||||
[InlineData(null, "test", false, false)]
|
||||
[InlineData(".*", "test", true, true)]
|
||||
[InlineData("invalid[", "test", false, false)]
|
||||
public void MatchRegex_WithVariousPatternsAndExtendedRegex_ReturnsExpectedResults(
|
||||
string? pattern, string input, bool expectedIsValid, bool expectedResult)
|
||||
{
|
||||
// Act
|
||||
var (isValidResult, matchResult) = RegexUtils.MatchRegex(pattern, input, useRegexExtended: true);
|
||||
|
||||
// Assert
|
||||
isValidResult.Should().Be(expectedIsValid);
|
||||
matchResult.Should().Be(expectedResult);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user