Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using WireMock.Server;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

/// <summary>
/// Provides assertion methods to verify the number of calls made to a WireMock server.
/// This class is used in the context of FluentAssertions.
/// This class is used in the context of AwesomeAssertions.
/// </summary>
public class WireMockANumberOfCallsAssertions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright © WireMock.Net

using WireMock.Extensions;
using WireMock.Matchers;

// ReSharper disable once CheckNamespace
namespace WireMock.AwesomeAssertions;

#pragma warning disable CS1591
public partial class WireMockAssertions
{
[CustomAssertion]
public AndWhichConstraint<WireMockAssertions, string> AtAbsolutePath(string absolutePath, string because = "", params object[] becauseArgs)
{
_ = AtAbsolutePath(new ExactMatcher(true, absolutePath), because, becauseArgs);

return new AndWhichConstraint<WireMockAssertions, string>(this, absolutePath);
}

[CustomAssertion]
public AndWhichConstraint<WireMockAssertions, IStringMatcher> AtAbsolutePath(IStringMatcher absolutePathMatcher, string because = "", params object[] becauseArgs)
{
var (filter, condition) = BuildFilterAndCondition(request => absolutePathMatcher.IsPerfectMatch(request.AbsolutePath));

var absolutePath = absolutePathMatcher.GetPatterns().FirstOrDefault().GetPattern();

_chain
.BecauseOf(because, becauseArgs)
.Given(() => RequestMessages)
.ForCondition(requests => CallsCount == 0 || requests.Any())
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the absolute path {0}{reason}, but no calls were made.",
absolutePath
)
.Then
.ForCondition(condition)
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the absolute path {0}{reason}, but didn't find it among the calls to {1}.",
_ => absolutePath,
requests => requests.Select(request => request.AbsolutePath)
);

FilterRequestMessages(filter);

return new AndWhichConstraint<WireMockAssertions, IStringMatcher>(this, absolutePathMatcher);
}

[CustomAssertion]
public AndWhichConstraint<WireMockAssertions, string> AtPath(string path, string because = "", params object[] becauseArgs)
{
_ = AtPath(new ExactMatcher(true, path), because, becauseArgs);

return new AndWhichConstraint<WireMockAssertions, string>(this, path);
}

[CustomAssertion]
public AndWhichConstraint<WireMockAssertions, IStringMatcher> AtPath(IStringMatcher pathMatcher, string because = "", params object[] becauseArgs)
{
var (filter, condition) = BuildFilterAndCondition(request => pathMatcher.IsPerfectMatch(request.Path));

var path = pathMatcher.GetPatterns().FirstOrDefault().GetPattern();

_chain
.BecauseOf(because, becauseArgs)
.Given(() => RequestMessages)
.ForCondition(requests => CallsCount == 0 || requests.Any())
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the path {0}{reason}, but no calls were made.",
path
)
.Then
.ForCondition(condition)
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the path {0}{reason}, but didn't find it among the calls to {1}.",
_ => path,
requests => requests.Select(request => request.Path)
);

FilterRequestMessages(filter);

return new AndWhichConstraint<WireMockAssertions, IStringMatcher>(this, pathMatcher);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using WireMock.Matchers;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

#pragma warning disable CS1591
public partial class WireMockAssertions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

public partial class WireMockAssertions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using WireMock.Constants;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

public partial class WireMockAssertions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using WireMock.Models;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

public partial class WireMockAssertions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma warning disable CS1591

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

public partial class WireMockAssertions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

public partial class WireMockAssertions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using WireMock.Server;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

public partial class WireMockAssertions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using WireMock.Server;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;
namespace WireMock.AwesomeAssertions;

/// <summary>
/// Contains a number of methods to assert that the <see cref="IWireMockServer"/> is in the expected state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using WireMock.Server;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions
namespace WireMock.AwesomeAssertions
{
/// <summary>
/// Contains extension methods for custom assertions in unit tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright © WireMock.Net

using WireMock.Extensions;
using WireMock.Matchers;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions;

#pragma warning disable CS1591
public partial class WireMockAssertions
{
[CustomAssertion]
public AndWhichConstraint<WireMockAssertions, string> AtAbsolutePath(string absolutePath, string because = "", params object[] becauseArgs)
{
_ = AtAbsolutePath(new ExactMatcher(true, absolutePath), because, becauseArgs);

return new AndWhichConstraint<WireMockAssertions, string>(this, absolutePath);
}

[CustomAssertion]
public AndWhichConstraint<WireMockAssertions, IStringMatcher> AtAbsolutePath(IStringMatcher absolutePathMatcher, string because = "", params object[] becauseArgs)
{
var (filter, condition) = BuildFilterAndCondition(request => absolutePathMatcher.IsPerfectMatch(request.AbsolutePath));

var absolutePath = absolutePathMatcher.GetPatterns().FirstOrDefault().GetPattern();

Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => RequestMessages)
.ForCondition(requests => CallsCount == 0 || requests.Any())
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the absolute path {0}{reason}, but no calls were made.",
absolutePath
)
.Then
.ForCondition(condition)
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the absolute path {0}{reason}, but didn't find it among the calls to {1}.",
_ => absolutePath,
requests => requests.Select(request => request.AbsolutePath)
);

FilterRequestMessages(filter);

return new AndWhichConstraint<WireMockAssertions, IStringMatcher>(this, absolutePathMatcher);
}

[CustomAssertion]
public AndWhichConstraint<WireMockAssertions, string> AtPath(string path, string because = "", params object[] becauseArgs)
{
_ = AtPath(new ExactMatcher(true, path), because, becauseArgs);

return new AndWhichConstraint<WireMockAssertions, string>(this, path);
}

[CustomAssertion]
public AndWhichConstraint<WireMockAssertions, IStringMatcher> AtPath(IStringMatcher pathMatcher, string because = "", params object[] becauseArgs)
{
var (filter, condition) = BuildFilterAndCondition(request => pathMatcher.IsPerfectMatch(request.Path));

var path = pathMatcher.GetPatterns().FirstOrDefault().GetPattern();

Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => RequestMessages)
.ForCondition(requests => CallsCount == 0 || requests.Any())
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the path {0}{reason}, but no calls were made.",
path
)
.Then
.ForCondition(condition)
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the path {0}{reason}, but didn't find it among the calls to {1}.",
_ => path,
requests => requests.Select(request => request.Path)
);

FilterRequestMessages(filter);

return new AndWhichConstraint<WireMockAssertions, IStringMatcher>(this, pathMatcher);
}
}
Loading