diff --git a/Directory.Packages.props b/Directory.Packages.props index 97b36bf..a56de20 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,7 +13,7 @@ - + diff --git a/src/ActionResult/HttpBuildR.ActionResult.Tests/ActionResultBuilderTests.cs b/src/ActionResult/HttpBuildR.ActionResult.Tests/ActionResultBuilderTests.cs index 118da2b..e1b6ded 100644 --- a/src/ActionResult/HttpBuildR.ActionResult.Tests/ActionResultBuilderTests.cs +++ b/src/ActionResult/HttpBuildR.ActionResult.Tests/ActionResultBuilderTests.cs @@ -1,4 +1,3 @@ -using System.Net; using System.Text.Json; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -9,7 +8,7 @@ namespace HttpBuildR.ActionResult.Tests; -public static class ActionResultBuilderTests +public sealed class ActionResultBuilderTests { private static async Task ConvertToResponse(ActionResult ar) { @@ -24,23 +23,23 @@ private static async Task ConvertToResponse(ActionResult a } [Fact(DisplayName = "A T can be converted to an OK response")] - public static void Case1() => ActionResultBuilder.Ok("this is a test").Should().NotBeNull(); + public void Case1() => ActionResultBuilder.Ok("this is a test").Should().NotBeNull(); [Fact(DisplayName = "A T can be converted to an OK response and cookie")] - public static async Task Case2() => - await ActionResultBuilder + public Task Case2() => + ActionResultBuilder .Ok("this is a test", Cookie.New("a", "c")) - .ArrangeData() + .Arrange() .Act(ConvertToResponse) - .Assert(r => r.StatusCode.Should().Be((int)HttpStatusCode.OK)) + .Assert(r => r.StatusCode.Should().Be((int)Resp.OK)) .And(r => r.Headers.Should().ContainKey("Set-Cookie").And.ContainValue("a=c; path=/")) .And(async r => (await new StreamReader(r.Body).ReadToEndAsync()).Should().Be("\"this is a test\"") ); [Fact(DisplayName = "A response can be converted to an action response")] - public static async Task Case3() => - await Resp + public Task Case3() => + Resp .BadRequest.Result() .WithProblemDetails( "a", @@ -50,9 +49,9 @@ await Resp new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase } ) .ToActionResult(Cookie.New("a", "b")) - .ArrangeData() + .Arrange() .Act(ConvertToResponse) - .Assert(r => r.StatusCode.Should().Be((int)HttpStatusCode.BadRequest)) + .Assert(r => r.StatusCode.Should().Be((int)Resp.BadRequest)) .And(r => r.Headers.Should().ContainKey("Set-Cookie").And.ContainValue("a=b; path=/")) .And(async r => (await new StreamReader(r.Body).ReadToEndAsync()) @@ -63,14 +62,14 @@ await Resp ); [Fact(DisplayName = "A response can be converted to an action response with no content")] - public static async Task Case4() => - await Resp + public Task Case4() => + Resp .NotAcceptable.Result() .WithHeader("a", "b") .ToActionResult() - .ArrangeData() + .Arrange() .Act(ConvertToResponse) - .Assert(r => r.StatusCode.Should().Be((int)HttpStatusCode.NotAcceptable)) + .Assert(r => r.StatusCode.Should().Be((int)Resp.NotAcceptable)) .And(r => r.Headers.Should().ContainKey("a").And.ContainValue("b")) .And(r => r.ContentType.Should().BeNullOrEmpty()) .And(r => r.ContentLength.Should().Be(0L)); diff --git a/src/Request/HttpBuildR.Request.Tests/GlobalUsings.cs b/src/Request/HttpBuildR.Request.Tests/GlobalUsings.cs index a495466..c0be45d 100644 --- a/src/Request/HttpBuildR.Request.Tests/GlobalUsings.cs +++ b/src/Request/HttpBuildR.Request.Tests/GlobalUsings.cs @@ -1,4 +1,3 @@ global using BunsenBurner; global using FluentAssertions; global using Xunit; -global using Scenario = BunsenBurner.Scenario; diff --git a/src/Request/HttpBuildR.Request.Tests/RequestContentTests.cs b/src/Request/HttpBuildR.Request.Tests/RequestContentTests.cs index bf0488d..902da97 100644 --- a/src/Request/HttpBuildR.Request.Tests/RequestContentTests.cs +++ b/src/Request/HttpBuildR.Request.Tests/RequestContentTests.cs @@ -4,21 +4,19 @@ namespace HttpBuildR.Request.Tests; -public static class RequestContentTests +using Scenario = TestBuilder.Acted; + +public sealed class RequestContentTests { - private static Scenario.Acted ArrangeAndAct( - Func fn - ) => + private static Scenario Arrange(Func fn) => new HttpRequestMessage() - .ArrangeData() + .Arrange() .Act(fn) .And((_, req) => req.Content ?? throw new InvalidOperationException()); [Fact(DisplayName = "Json content can be added to a request")] - public static async Task Case1() => - await ArrangeAndAct(x => - x.WithJsonContent(new { A = 1, B = "2" }, JsonSerializerOptions.Default) - ) + public Task Case1() => + Arrange(x => x.WithJsonContent(new { A = 1, B = "2" }, JsonSerializerOptions.Default)) .Assert(async content => { content.Headers.ContentType!.MediaType.Should().Be("application/json"); @@ -27,8 +25,8 @@ public static class RequestContentTests }); [Fact(DisplayName = "Json content can be added to a request without options")] - public static async Task Case2() => - await ArrangeAndAct(x => x.WithJsonContent(new { A = 1, B = "2" })) + public Task Case2() => + Arrange(x => x.WithJsonContent(new { A = 1, B = "2" })) .Assert(async content => { content.Headers.ContentType!.MediaType.Should().Be("application/json"); @@ -43,8 +41,8 @@ public class Person } [Fact(DisplayName = "Xml content can be added to a request")] - public static async Task Case3() => - await ArrangeAndAct(x => + public Task Case3() => + Arrange(x => x.WithXmlContent( new Person { Name = "John", Age = 36 }, new XmlWriterSettings { Indent = false } @@ -62,8 +60,8 @@ public class Person }); [Fact(DisplayName = "Xml content can be added and the writer customized")] - public static async Task Case4() => - await ArrangeAndAct(x => + public Task Case4() => + Arrange(x => x.WithXmlContent(new Person { Name = "John", Age = 36 }, modifyWriterFunc: w => w) ) .Assert(async content => @@ -78,8 +76,8 @@ public class Person }); [Fact(DisplayName = "Text content can be added to a request")] - public static async Task Case5() => - await ArrangeAndAct(x => x.WithTextContent("
some text
", "text/html")) + public Task Case5() => + Arrange(x => x.WithTextContent("
some text
", "text/html")) .Assert(async content => { content.Headers.ContentType!.MediaType.Should().Be(MediaTypeNames.Text.Html); @@ -88,8 +86,8 @@ await ArrangeAndAct(x => x.WithTextContent("
some text
", "text/html")) }); [Fact(DisplayName = "Text content can be added to a request without media type")] - public static async Task Case6() => - await ArrangeAndAct(x => x.WithTextContent("hello world")) + public Task Case6() => + Arrange(x => x.WithTextContent("hello world")) .Assert(async content => { content.Headers.ContentType!.MediaType.Should().Be(MediaTypeNames.Text.Plain); @@ -98,8 +96,8 @@ await ArrangeAndAct(x => x.WithTextContent("hello world")) }); [Fact(DisplayName = "Form url encoded content can be added to a request")] - public static async Task Case7() => - await ArrangeAndAct(x => + public Task Case7() => + Arrange(x => x.WithFormUrlContent( new Dictionary(StringComparer.Ordinal) { @@ -118,8 +116,8 @@ await ArrangeAndAct(x => x.WithTextContent("hello world")) }); [Fact(DisplayName = "Form url encoded content can be added to a request")] - public static async Task Case7b() => - await ArrangeAndAct(x => + public Task Case7B() => + Arrange(x => x.WithFormUrlContent(KeyValuePair.Create("A", "1"), KeyValuePair.Create("B", "2")) ) .Assert(async content => @@ -132,8 +130,8 @@ await ArrangeAndAct(x => x.WithTextContent("hello world")) }); [Fact(DisplayName = "Json content can be added to a request using a source generator")] - public static async Task Case8() => - await ArrangeAndAct(x => + public Task Case8() => + Arrange(x => x.WithJsonContent( new Widget("Test", 123.50), ExampleJsonSourceGenerator.Default.Widget diff --git a/src/Request/HttpBuildR.Request.Tests/RequestHeadersTests.cs b/src/Request/HttpBuildR.Request.Tests/RequestHeadersTests.cs index f126b37..30f08ca 100644 --- a/src/Request/HttpBuildR.Request.Tests/RequestHeadersTests.cs +++ b/src/Request/HttpBuildR.Request.Tests/RequestHeadersTests.cs @@ -2,31 +2,31 @@ namespace HttpBuildR.Request.Tests; -public static class RequestHeadersTests +public sealed class RequestHeadersTests { [Fact(DisplayName = "Base authentication can be set")] - public static void Case1() => + public void Case1() => new HttpRequestMessage() .WithBasicToken("abcd") .Headers.Authorization.Should() .BeEquivalentTo(new { Scheme = "Basic", Parameter = "abcd" }); [Fact(DisplayName = "Bearer authentication can be set")] - public static void Case2() => + public void Case2() => new HttpRequestMessage() .WithBearerToken("abcde") .Headers.Authorization.Should() .BeEquivalentTo(new { Scheme = "Bearer", Parameter = "abcde" }); [Fact(DisplayName = "Custom header can be set with a single value")] - public static void Case3() => + public void Case3() => new HttpRequestMessage() .WithHeader("a", "1") .Headers.Should() .Contain(x => x.Key == "a" && x.Value.Count() == 1 && x.Value.First() == "1"); [Fact(DisplayName = "Custom header can be set with multiple values")] - public static void Case4() => + public void Case4() => new HttpRequestMessage() .WithHeader("a", "1", "2", "3") .Headers.Should() @@ -39,14 +39,14 @@ public static class RequestHeadersTests ); [Fact(DisplayName = "Proxy authorization header can be set")] - public static void Case5() => + public void Case5() => new HttpRequestMessage() .WithProxyAuthorization("Test", "abcdef") .Headers.ProxyAuthorization.Should() .BeEquivalentTo(new { Scheme = "Test", Parameter = "abcdef" }); [Fact(DisplayName = "Cache control header can be set")] - public static void Case6() => + public void Case6() => new HttpRequestMessage() .WithCacheControl( new CacheControlHeaderValue { MaxAge = TimeSpan.FromSeconds(20), NoStore = true } @@ -55,88 +55,88 @@ public static class RequestHeadersTests .BeEquivalentTo(new { MaxAge = TimeSpan.FromSeconds(20), NoStore = true }); [Fact(DisplayName = "Connection close header can be set")] - public static void Case7() => + public void Case7() => new HttpRequestMessage() - .WithConnectionClose(true) + .WithConnectionClose(value: true) .Headers.ConnectionClose.Should() .BeTrue(); [Fact(DisplayName = "Date header can be set")] - public static void Case8() => + public void Case8() => new HttpRequestMessage() .WithDate(DateTimeOffset.UtcNow) .Headers.Date.Should() .BeCloseTo(DateTimeOffset.Now, TimeSpan.FromSeconds(1)); [Fact(DisplayName = "Accept headers can be set")] - public static void Case9() => + public void Case9() => new HttpRequestMessage() .WithAccept("text/json", 0.20) .Headers.Accept.Should() .Contain(x => x.MediaType == "text/json" && x.Quality == 0.20); [Fact(DisplayName = "Accept headers can be set without quality")] - public static void Case10() => + public void Case10() => new HttpRequestMessage() .WithAccept("text/json2") .Headers.Accept.Should() .Contain(x => x.MediaType == "text/json2" && !x.Quality.HasValue); [Fact(DisplayName = "If-Modified-Since header can be set")] - public static void Case11() => + public void Case11() => new HttpRequestMessage() .WithIfModifiedSince(DateTimeOffset.UtcNow) .Headers.IfModifiedSince.Should() .BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(1)); [Fact(DisplayName = "Range header can be set")] - public static void Case12() => + public void Case12() => new HttpRequestMessage() .WithRange(20, 50) .Headers.Range.Should() .BeEquivalentTo(new RangeHeaderValue(20, 50)); [Fact(DisplayName = "If-Range header can be set using data time")] - public static void Case13() => + public void Case13() => new HttpRequestMessage() .WithIfRange(DateTimeOffset.Now) .Headers.IfRange!.Date.Should() .BeCloseTo(DateTimeOffset.Now, TimeSpan.FromSeconds(1)); [Fact(DisplayName = "If-Range header can be set using e-tag")] - public static void Case14() => + public void Case14() => new HttpRequestMessage() .WithIfRange(new EntityTagHeaderValue("\"a\"")) .Headers.IfRange!.EntityTag.Should() .BeEquivalentTo(new EntityTagHeaderValue("\"a\"")); [Fact(DisplayName = "If-Unmodified-Since header can be set")] - public static void Case15() => + public void Case15() => new HttpRequestMessage() .WithIfUnmodifiedSince(DateTimeOffset.UtcNow) .Headers.IfUnmodifiedSince.Should() .BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(1)); [Fact(DisplayName = "Max-Forwards header can be set")] - public static void Case16() => + public void Case16() => new HttpRequestMessage().WithMaxForwards(3).Headers.MaxForwards.Should().Be(3); [Fact(DisplayName = "Referrer header can be set")] - public static void Case17() => + public void Case17() => new HttpRequestMessage() .WithReferrer("https://some-domain") .Headers.Referrer.Should() .Be(new Uri("https://some-domain")); [Fact(DisplayName = "Transfer-Encoding header can be set")] - public static void Case18() => + public void Case18() => new HttpRequestMessage() .WithTransferEncodingChunked(true) .Headers.TransferEncodingChunked.Should() .BeTrue(); [Fact(DisplayName = "Headers can be modified using an action")] - public static void Case19() => + public void Case19() => new HttpRequestMessage() .WithHeaderModifications(h => { diff --git a/src/Request/HttpBuildR.Request.Tests/RequestTests.cs b/src/Request/HttpBuildR.Request.Tests/RequestTests.cs index a0baa61..b07a833 100644 --- a/src/Request/HttpBuildR.Request.Tests/RequestTests.cs +++ b/src/Request/HttpBuildR.Request.Tests/RequestTests.cs @@ -2,10 +2,10 @@ namespace HttpBuildR.Request.Tests; -public static class RequestTests +public sealed class RequestTests { [Fact(DisplayName = "A HttpMethod can start building a HttpRequestMessage with a string uri")] - public static void Case1() => + public void Case1() => Req .Get.To("Http://some-host") .Should() @@ -19,7 +19,7 @@ public static class RequestTests ); [Fact(DisplayName = "A HttpMethod can start building a HttpRequestMessage with a Uri uri")] - public static void Case2() => + public void Case2() => Req .Get.To(new Uri("Http://some-host")) .Should() @@ -35,7 +35,7 @@ public static class RequestTests [Fact( DisplayName = "A HttpMethod can start building a HttpRequestMessage with a string uri, at version 1.1" )] - public static void Case3() => + public void Case3() => Req .Get.To("Http://some-host", HttpVersion.Version11) .Should() @@ -51,7 +51,7 @@ public static class RequestTests [Fact( DisplayName = "A HttpMethod can start building a HttpRequestMessage with a Uri uri, at version 1.1" )] - public static void Case4() => + public void Case4() => Req .Get.To(new Uri("Http://some-host"), HttpVersion.Version11) .Should() @@ -65,15 +65,18 @@ public static class RequestTests ); [Fact(DisplayName = "2 builders can be run one after the other, with independent results")] - public static async Task Case5() - { - var req1 = Req + public Task Case5() => + Req .Get.To(new Uri("Http://some-host")) .WithHeader("a", "1") - .WithTextContent("test"); - var req2 = (await req1.Clone()).WithHeader("b", "2"); - - req1.Headers.Should().HaveCount(1); - req2.Headers.Should().HaveCount(2); - } + .WithTextContent("test") + .Arrange() + .Act(async req => (await req.Clone()).WithHeader("b", "2")) + .Assert( + (req1, req2) => + { + req1.Headers.Should().HaveCount(1); + req2.Headers.Should().HaveCount(2); + } + ); } diff --git a/src/Response/HttpBuildR.Response.Tests/GlobalUsings.cs b/src/Response/HttpBuildR.Response.Tests/GlobalUsings.cs index a495466..c0be45d 100644 --- a/src/Response/HttpBuildR.Response.Tests/GlobalUsings.cs +++ b/src/Response/HttpBuildR.Response.Tests/GlobalUsings.cs @@ -1,4 +1,3 @@ global using BunsenBurner; global using FluentAssertions; global using Xunit; -global using Scenario = BunsenBurner.Scenario; diff --git a/src/Response/HttpBuildR.Response.Tests/ResponseContentTests.cs b/src/Response/HttpBuildR.Response.Tests/ResponseContentTests.cs index e4bec81..17bfdfb 100644 --- a/src/Response/HttpBuildR.Response.Tests/ResponseContentTests.cs +++ b/src/Response/HttpBuildR.Response.Tests/ResponseContentTests.cs @@ -4,21 +4,19 @@ namespace HttpBuildR.Response.Tests; -public static class ResponseContentTests +using Scenario = TestBuilder.Acted; + +public sealed class ResponseContentTests { - private static Scenario.Acted ArrangeAndAct( - Func fn - ) => + private static Scenario Arrange(Func fn) => new HttpResponseMessage() - .ArrangeData() + .Arrange() .Act(fn) .And((_, req) => req.Content ?? throw new InvalidOperationException()); [Fact(DisplayName = "Json content can be added to a response")] - public static async Task Case1() => - await ArrangeAndAct(x => - x.WithJsonContent(new { A = 1, B = "2" }, JsonSerializerOptions.Default) - ) + public Task Case1() => + Arrange(x => x.WithJsonContent(new { A = 1, B = "2" }, JsonSerializerOptions.Default)) .Assert(async content => { content.Headers.ContentType!.MediaType.Should().Be("application/json"); @@ -27,8 +25,8 @@ public static class ResponseContentTests }); [Fact(DisplayName = "Json content can be added to a response without options")] - public static async Task Case2() => - await ArrangeAndAct(x => x.WithJsonContent(new { A = 1, B = "2" })) + public Task Case2() => + Arrange(x => x.WithJsonContent(new { A = 1, B = "2" })) .Assert(async content => { content.Headers.ContentType!.MediaType.Should().Be("application/json"); @@ -43,8 +41,8 @@ public class Person } [Fact(DisplayName = "Xml content can be added to a response")] - public static async Task Case3() => - await ArrangeAndAct(x => + public Task Case3() => + Arrange(x => x.WithXmlContent( new Person { Name = "John", Age = 36 }, new XmlWriterSettings { Indent = false } @@ -62,8 +60,8 @@ public class Person }); [Fact(DisplayName = "Xml content can be added to a response without settings")] - public static async Task Case4() => - await ArrangeAndAct(x => + public Task Case4() => + Arrange(x => x.WithXmlContent( new Person { Name = "John", Age = 36 }, modifyWriterFunc: writer => writer @@ -81,8 +79,8 @@ public class Person }); [Fact(DisplayName = "Text content can be added to a response")] - public static async Task Case5() => - await ArrangeAndAct(x => x.WithTextContent("
some text
", "text/html")) + public Task Case5() => + Arrange(x => x.WithTextContent("
some text
", "text/html")) .Assert(async content => { content.Headers.ContentType!.MediaType.Should().Be(MediaTypeNames.Text.Html); @@ -91,8 +89,8 @@ await ArrangeAndAct(x => x.WithTextContent("
some text
", "text/html")) }); [Fact(DisplayName = "Text content can be added to a response without media type")] - public static async Task Case6() => - await ArrangeAndAct(x => x.WithTextContent("hello world")) + public Task Case6() => + Arrange(x => x.WithTextContent("hello world")) .Assert(async content => { content.Headers.ContentType!.MediaType.Should().Be(MediaTypeNames.Text.Plain); @@ -101,8 +99,8 @@ await ArrangeAndAct(x => x.WithTextContent("hello world")) }); [Fact(DisplayName = "Form url encoded content can be added to a response")] - public static async Task Case7() => - await ArrangeAndAct(x => + public Task Case7() => + Arrange(x => x.WithFormUrlContent( new Dictionary(StringComparer.Ordinal) { @@ -121,8 +119,8 @@ await ArrangeAndAct(x => x.WithTextContent("hello world")) }); [Fact(DisplayName = "Form url encoded content can be added to a request")] - public static async Task Case7b() => - await ArrangeAndAct(x => + public Task Case7B() => + Arrange(x => x.WithFormUrlContent(KeyValuePair.Create("A", "1"), KeyValuePair.Create("B", "2")) ) .Assert(async content => @@ -135,8 +133,8 @@ await ArrangeAndAct(x => x.WithTextContent("hello world")) }); [Fact(DisplayName = "Json content can be added to a request using a source generator")] - public static async Task Case8() => - await ArrangeAndAct(x => + public Task Case8() => + Arrange(x => x.WithJsonContent( new Widget("Test", 123.50), ExampleJsonSourceGenerator.Default.Widget diff --git a/src/Response/HttpBuildR.Response.Tests/ResponseHeadersTests.cs b/src/Response/HttpBuildR.Response.Tests/ResponseHeadersTests.cs index aae3a28..fab81e7 100644 --- a/src/Response/HttpBuildR.Response.Tests/ResponseHeadersTests.cs +++ b/src/Response/HttpBuildR.Response.Tests/ResponseHeadersTests.cs @@ -2,17 +2,17 @@ namespace HttpBuildR.Response.Tests; -public static class ResponseHeadersTests +public sealed class ResponseHeadersTests { [Fact(DisplayName = "Custom header can be set with a single value")] - public static void Case1() => + public void Case1() => new HttpResponseMessage() .WithHeader("a", "1") .Headers.Should() .Contain(x => x.Key == "a" && x.Value.Count() == 1 && x.Value.First() == "1"); [Fact(DisplayName = "Custom header can be set with multiple values")] - public static void Case2() => + public void Case2() => new HttpResponseMessage() .WithHeader("a", "1", "2", "3") .Headers.Should() @@ -25,7 +25,7 @@ public static class ResponseHeadersTests ); [Fact(DisplayName = "Cache control header can be set")] - public static void Case3() => + public void Case3() => new HttpResponseMessage() .WithCacheControl( new CacheControlHeaderValue { MaxAge = TimeSpan.FromSeconds(20), NoStore = true } @@ -34,63 +34,63 @@ public static class ResponseHeadersTests .BeEquivalentTo(new { MaxAge = TimeSpan.FromSeconds(20), NoStore = true }); [Fact(DisplayName = "Connection close header can be set")] - public static void Case4() => + public void Case4() => new HttpResponseMessage() .WithConnectionClose(true) .Headers.ConnectionClose.Should() .BeTrue(); [Fact(DisplayName = "Date header can be set")] - public static void Case5() => + public void Case5() => new HttpResponseMessage() .WithDate(DateTimeOffset.UtcNow) .Headers.Date.Should() .BeCloseTo(DateTimeOffset.Now, TimeSpan.FromSeconds(1)); [Fact(DisplayName = "Transfer-Encoding header can be set")] - public static void Case6() => + public void Case6() => new HttpResponseMessage() - .WithTransferEncodingChunked(true) + .WithTransferEncodingChunked(value: true) .Headers.TransferEncodingChunked.Should() .BeTrue(); [Fact(DisplayName = "Age header can be set")] - public static void Case7() => + public void Case7() => new HttpResponseMessage() .WithAge(TimeSpan.FromDays(1)) .Headers.Age.Should() .Be(TimeSpan.FromDays(1)); [Fact(DisplayName = "ETag header can be set")] - public static void Case8() => + public void Case8() => new HttpResponseMessage() .WithETag(EntityTagHeaderValue.Any) .Headers.ETag.Should() .Be(EntityTagHeaderValue.Any); [Fact(DisplayName = "Location header can be set")] - public static void Case9() => + public void Case9() => new HttpResponseMessage() .WithLocation("https://some-host") .Headers.Location.Should() .Be(new Uri("https://some-host")); [Fact(DisplayName = "RetryAfter header can be set")] - public static void Case10() => + public void Case10() => new HttpResponseMessage() .WithRetryAfter(TimeSpan.FromMinutes(1)) .Headers.RetryAfter!.Delta.Should() .Be(TimeSpan.FromMinutes(1)); [Fact(DisplayName = "RetryAfter header can be set using a date time")] - public static void Case11() => + public void Case11() => new HttpResponseMessage() .WithRetryAfter(DateTimeOffset.UtcNow) .Headers.RetryAfter!.Date.Should() .BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(1)); [Fact(DisplayName = "Headers can be modified using an action")] - public static void Case19() => + public void Case19() => new HttpResponseMessage() .WithHeaderModifications(h => { diff --git a/src/Response/HttpBuildR.Response.Tests/ResponseTests.cs b/src/Response/HttpBuildR.Response.Tests/ResponseTests.cs index 051831a..55bfa0c 100644 --- a/src/Response/HttpBuildR.Response.Tests/ResponseTests.cs +++ b/src/Response/HttpBuildR.Response.Tests/ResponseTests.cs @@ -2,10 +2,10 @@ namespace HttpBuildR.Response.Tests; -public static class ResponseTests +public sealed class ResponseTests { [Fact(DisplayName = "A HttpStatusCode can start building a HttpResponseMessage")] - public static void Case1() => + public void Case1() => Resp .OK.Result() .Should() @@ -14,7 +14,7 @@ public static class ResponseTests [Fact( DisplayName = "A HttpStatusCode can start building a HttpResponseMessage with a reason phrase, at version 1.1" )] - public static void Case2() => + public void Case2() => Resp .Accepted.Result("some reason phrase", new HttpRequestMessage(), HttpVersion.Version11) .Should() @@ -28,12 +28,18 @@ public static class ResponseTests ); [Fact(DisplayName = "2 builders can be run one after the other, with independent results")] - public static async Task Case3() - { - var req1 = Resp.OK.Result().WithHeader("a", "1").WithTextContent("test"); - var req2 = (await req1.Clone()).WithHeader("b", "2"); - - req1.Headers.Should().HaveCount(1); - req2.Headers.Should().HaveCount(2); - } + public Task Case3() => + Resp + .OK.Result() + .WithHeader("a", "1") + .WithTextContent("test") + .Arrange() + .Act(async req => (await req.Clone()).WithHeader("b", "2")) + .Assert( + (req1, req2) => + { + req1.Headers.Should().HaveCount(1); + req2.Headers.Should().HaveCount(2); + } + ); }