-
-
Save dcomartin/eee179995cc855ed2f421e7218644bb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class VinDecoderFixture | |
| { | |
| public static VinDecoder CreateSuccessful( | |
| int year = 2026, | |
| string make = "Ford", | |
| string model = "F-150") | |
| { | |
| var json = $$""" | |
| { | |
| "year": {{year}}, | |
| "make": "{{make}}", | |
| "model": "{{model}}", | |
| } | |
| """; | |
| var handler = new StubHttpMessageHandler(_ => | |
| new HttpResponseMessage(HttpStatusCode.OK) | |
| { | |
| Content = new StringContent(json, Encoding.UTF8, "application/json") | |
| }); | |
| var httpClient = new HttpClient(handler); | |
| return new VinDecoder(httpClient); | |
| } | |
| public static VinDecoder CreateFailure( | |
| HttpStatusCode statusCode = HttpStatusCode.BadRequest, | |
| string json = """{ "error": "invalid request" }""") | |
| { | |
| var handler = new StubHttpMessageHandler(_ => | |
| new HttpResponseMessage(statusCode) | |
| { | |
| Content = new StringContent(json, Encoding.UTF8, "application/json") | |
| }); | |
| var httpClient = new HttpClient(handler); | |
| return new VinDecoder(httpClient); | |
| } | |
| } | |
| public class Tests | |
| { | |
| [Fact] | |
| public async Task Handle_returns_vehicle_name() | |
| { | |
| var vinDecoder = VinDecoderFixture.CreateSuccessful( | |
| year: 2026, | |
| make: "Ford", | |
| model: "F-150"); | |
| var sut = new RegisterVehicleHandler(vinDecoder); | |
| var result = await sut.Handle(new RegisterVehicleCommand("123456789"), CancellationToken.None); | |
| Assert.Equal("2026 Ford F-150", result); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment