From 08688bf32f780b427a120389b5731e4338f5f742 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 1 May 2022 10:52:01 +0200 Subject: [PATCH] Updated FluentAssertions (markdown) --- FluentAssertions.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/FluentAssertions.md b/FluentAssertions.md index 09f8e20..5ce0e8c 100644 --- a/FluentAssertions.md +++ b/FluentAssertions.md @@ -1,6 +1,8 @@ -#FluentAssertions +# FluentAssertions With the NuGet Package [WireMock.Net.FluentAssertions](https://www.nuget.org/packages/WireMock.Net.FluentAssertions), it's possible to verify if certain calls are made. +### Example +The example below checks if a specific call to an url is actually made by the HttpClient. ``` c# [Fact] @@ -12,4 +14,20 @@ public async Task AtUrl_WhenACallWasMadeToUrl_Should_BeOK() .HaveReceivedACall() .AtUrl($"http://localhost:{_portUsed}/anyurl"); } -``` \ No newline at end of file +``` +[snippet](https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/FluentAssertions/WireMockAssertionsTests.cs#L154) + + +## LogEntries +In addition to the Fluent Assertions interface, you can also get information about the calls being made to the WireMock.Net server. + +### Example +Use the code below in a unit-test to check if the HttpClient actually did send these specific headers. + +``` c# +var sentHeaders = _server.LogEntries.SelectMany(x => x.RequestMessage.Headers) + .ToDictionary(x => x.Key, x => x.Value)["Accept"] + .Select(x => $"\"{x}\"") + .ToList(); +``` +[snippet](https://github.com/WireMock-Net/WireMock.Net/blob/b5ae087b95cae55ebe5e14bf23ccce60552e0a95/test/WireMock.Net.Tests/FluentAssertions/WireMockAssertionsTests.cs#L109)