mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-17 06:29:57 +02:00
Check if the path is valid when using WithPath(...) (#1377)
This commit is contained in:
42
test/WireMock.Net.Tests/Validators/PathValidatorTests.cs
Normal file
42
test/WireMock.Net.Tests/Validators/PathValidatorTests.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using FluentAssertions;
|
||||
using WireMock.Validators;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Validators;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathValidatorTests
|
||||
{
|
||||
[Fact]
|
||||
public void ValidateAndThrow_ValidPath_DoesNotThrow()
|
||||
{
|
||||
Action act = () => PathValidator.ValidateAndThrow("/valid/path");
|
||||
act.Should().NotThrow();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData("\r")]
|
||||
[InlineData("\n")]
|
||||
[InlineData("\t")]
|
||||
public void ValidateAndThrow_InvalidPath_ThrowsArgumentException_WithDefaultParamName(string? path)
|
||||
{
|
||||
Action act = () => PathValidator.ValidateAndThrow(path);
|
||||
var ex = act.Should().Throw<ArgumentException>().Which;
|
||||
ex.Message.Should().StartWith("Path must start with a '/' and cannot be null, empty or whitespace.");
|
||||
ex.ParamName.Should().Be("path");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateAndThrow_NoLeadingSlash_ThrowsArgumentException_WithProvidedParamName()
|
||||
{
|
||||
Action act = () => PathValidator.ValidateAndThrow("noSlash", "myParam");
|
||||
var ex = act.Should().Throw<ArgumentException>().Which;
|
||||
ex.ParamName.Should().Be("myParam");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user