Exemple #1
0
        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));
        }
Exemple #2
0
        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());
        }
Exemple #3
0
        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);
            }
        }