FluentValidation call count behaviour #462

Closed
opened 2025-12-29 15:24:23 +01:00 by adam · 4 comments
Owner

Originally created by @robvangeloven on GitHub (Oct 17, 2022).

Running the following unit tests I expect a different behaviour then I expected:

using System.Net;
using System.Net.Http.Headers;

using FluentAssertions;

using WireMock.FluentAssertions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;

var server = WireMockServer.Start();

// Should fail?
server
    .Should()
    .HaveReceived(100)
    .Calls();

// Should not fail?
server.Should()
    .HaveReceived(0)
    .Calls()
    .AtUrl(server.Url ?? string.Empty);

// Should not fail?
server.Should()
    .HaveReceivedNoCalls()
    .AtUrl(server.Url ?? string.Empty);

server.Stop();

Are my assumptions correct or is this correct behaviour?

Originally created by @robvangeloven on GitHub (Oct 17, 2022). Running the following unit tests I expect a different behaviour then I expected: ```csharp using System.Net; using System.Net.Http.Headers; using FluentAssertions; using WireMock.FluentAssertions; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; using WireMock.Server; var server = WireMockServer.Start(); // Should fail? server .Should() .HaveReceived(100) .Calls(); // Should not fail? server.Should() .HaveReceived(0) .Calls() .AtUrl(server.Url ?? string.Empty); // Should not fail? server.Should() .HaveReceivedNoCalls() .AtUrl(server.Url ?? string.Empty); server.Stop(); ``` Are my assumptions correct or is this correct behaviour?
adam added the question label 2025-12-29 15:24:23 +01:00
adam closed this issue 2025-12-29 15:24:23 +01:00
Author
Owner

@StefH commented on GitHub (Oct 17, 2022):

For the first test, the UsingAnyMethod is missing, however this is not yet implemented, I'll take a look.

@StefH commented on GitHub (Oct 17, 2022): For the first test, the `UsingAnyMethod` is missing, however this is not yet implemented, I'll take a look.
Author
Owner

@StefH commented on GitHub (Oct 17, 2022):

[Fact]
    public void HaveReceivedNoCalls_UsingAnyMethod_WhenNoCallsWereMade_Should_BeOK()
    {
        _server
            .Should()
            .HaveReceived(0)
            .Calls()
            .UsingAnyMethod();

        _server
            .Should()
            .HaveReceivedNoCalls()
            .UsingAnyMethod();
    }

    [Fact]
    public void HaveReceivedNoCalls_AtUrl_WhenNoCallsWereMade_Should_BeOK()
    {
        _server.Should()
            .HaveReceived(0)
            .Calls()
            .AtUrl(_server.Url ?? string.Empty);

        _server.Should()
            .HaveReceivedNoCalls()
            .AtUrl(_server.Url ?? string.Empty);
    }

Above tests are valid (I think) and work correctly using the latest preview (1.5.8-ci-16562). Can you test this?

@StefH commented on GitHub (Oct 17, 2022): ``` c# [Fact] public void HaveReceivedNoCalls_UsingAnyMethod_WhenNoCallsWereMade_Should_BeOK() { _server .Should() .HaveReceived(0) .Calls() .UsingAnyMethod(); _server .Should() .HaveReceivedNoCalls() .UsingAnyMethod(); } [Fact] public void HaveReceivedNoCalls_AtUrl_WhenNoCallsWereMade_Should_BeOK() { _server.Should() .HaveReceived(0) .Calls() .AtUrl(_server.Url ?? string.Empty); _server.Should() .HaveReceivedNoCalls() .AtUrl(_server.Url ?? string.Empty); } ``` Above tests are valid (I think) and work correctly using the latest preview (1.5.8-ci-16562). Can you test this?
Author
Owner

@robvangeloven commented on GitHub (Oct 17, 2022):

Yup. That version works! 👍🏻

@robvangeloven commented on GitHub (Oct 17, 2022): Yup. That version works! 👍🏻
Author
Owner

@StefH commented on GitHub (Oct 17, 2022):

https://github.com/WireMock-Net/WireMock.Net/pull/832

@StefH commented on GitHub (Oct 17, 2022): https://github.com/WireMock-Net/WireMock.Net/pull/832
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#462