public async Task given_valid_command_then_SendCreateMovieCommand_returns_location_result( HttpMessageHandlerDouble handlerStub, Uri endpoint, CreateNewMovie command, MovieLocation location) { // Arrange bool predicate(HttpRequestMessage req) { string path = "api/commands/SendCreateMovieCommand"; return(req.Method == HttpMethod.Post && req.RequestUri == new Uri(endpoint, path) && req.Content is ObjectContent <CreateNewMovie> 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 <MovieLocation> actual = await sut.SendCreateMovieCommand(command); // Assert actual.Should().BeOfType <Success <MovieLocation> >(); actual.Should().BeEquivalentTo(new { Value = location }); }
public Task <IResult <MovieLocation> > SendCreateMovieCommand( CreateNewMovie command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } return(Run()); async Task <IResult <MovieLocation> > Run() { string path = "api/commands/SendCreateMovieCommand"; HttpResponseMessage response = await _client.PostAsJsonAsync(new Uri(_endpoint, path), command); switch (response.StatusCode) { case BadRequest: return(await ReadError <MovieLocation>(response)); } var location = new MovieLocation(response.Headers.Location); return(new Success <MovieLocation>(location)); } }