public void GetPostById_GetsThreadViaHttp() { var thread = SetupExampleThread(); var httpClient = new Mock <IHttpClient>(); httpClient.SetupRequest("http://localhost/", "api/v3/teams/" + TEAM_ID + "/posts/" + POST_ID) .WithToken(TOKEN) .Get() .Responses(thread.SerializeToPayload()); var sut = new RestServiceImpl(httpClient.Object); var result = sut.GetPostById(Uri, TOKEN, TEAM_ID, POST_ID); Assert.That(result, Is.EqualTo(thread)); }
public void GetPostById_DisposesHttpResonse() { var thread = SetupExampleThread(); var httpClient = new Mock <IHttpClient>(); var httpResponse = httpClient.SetupRequest("http://localhost/", "api/v3/teams/" + TEAM_ID + "/posts/" + POST_ID) .WithToken(TOKEN) .Get(); httpResponse.Responses(thread.SerializeToPayload()); var sut = new RestServiceImpl(httpClient.Object); sut.GetPostById(Uri, TOKEN, TEAM_ID, POST_ID); httpResponse.Verify(x => x.Dispose()); }
public void GetPostById_ThrowsMattermostExceptionWithError_IfHttpExceptionWithErrorPayload() { var error = SetupExampleError(); var httpClient = new Mock <IHttpClient>(); httpClient.SetupRequest("http://localhost/", "api/v3/teams/" + TEAM_ID + "/posts/" + POST_ID) .WithToken(TOKEN) .FailsAtGet() .Responses(error.SerializeToPayload()); var sut = new RestServiceImpl(httpClient.Object); try { sut.GetPostById(Uri, TOKEN, TEAM_ID, POST_ID); Assert.Fail(); } catch (MattermostException mex) { mex.Message.Should().Be(error.Message); mex.Details.Should().Be(error.DetailedError); } }