public async Task given_valid_command_then_SendAddScreeningCommand_returns_location_result( HttpMessageHandlerDouble handlerStub, Uri endpoint, AddNewScreening command, ScreeningLocation location) { // Arrange bool predicate(HttpRequestMessage req) { string path = "api/commands/SendAddScreeningCommand"; return(req.Method == HttpMethod.Post && req.RequestUri == new Uri(endpoint, path) && req.Content is ObjectContent <AddNewScreening> content && content.Value == command && content.Formatter is JsonMediaTypeFormatter); } var response = new HttpResponseMessage(HttpStatusCode.Accepted); response.Headers.Location = location.Uri; handlerStub.AddAnswer(predicate, answer: response); var sut = new ApiClient(new HttpClient(handlerStub), endpoint); // Act IResult <ScreeningLocation> actual = await sut.SendAddScreeningCommand(command); // Assert actual.Should().BeOfType <Success <ScreeningLocation> >(); actual.Should().BeEquivalentTo(new { Value = location }); }
public Task <IResult <ScreeningLocation> > SendAddScreeningCommand( AddNewScreening command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } return(Run()); async Task <IResult <ScreeningLocation> > Run() { string path = "api/commands/SendAddScreeningCommand"; HttpResponseMessage response = await _client.PostAsJsonAsync(new Uri(_endpoint, path), command); switch (response.StatusCode) { case BadRequest: return(await ReadError <ScreeningLocation>(response)); } var location = new ScreeningLocation(response.Headers.Location); return(new Success <ScreeningLocation>(location)); } }