public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected)
        {
            var response = Task.Factory.StartNew<IResponse<object>>(() =>
                new ApiResponse<object> { StatusCode = status });
            var connection = Substitute.For<IConnection>();
            connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "gists/1/star"),
                null, null).Returns(response);
            var apiConnection = Substitute.For<IApiConnection>();
            apiConnection.Connection.Returns(connection);
            var client = new GistsClient(apiConnection);

            var result = await client.IsStarred("1");

            Assert.Equal(expected, result);
        }
        public async Task ThrowsExceptionForInvalidStatusCode()
        {
            var response = Task.Factory.StartNew<IResponse<object>>(() =>
                new ApiResponse<object> { StatusCode = HttpStatusCode.Conflict });
            var connection = Substitute.For<IConnection>();
            connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "gists/1/star"),
                null, null).Returns(response);
            var apiConnection = Substitute.For<IApiConnection>();
            apiConnection.Connection.Returns(connection);

            var client = new GistsClient(apiConnection);

            await AssertEx.Throws<ApiException>(async () => await client.IsStarred("1"));
        }
示例#3
0
        public async Task ThrowsExceptionForInvalidStatusCode()
        {
            var response = Task.Factory.StartNew<IApiResponse<object>>(() =>
                new ApiResponse<object>(new Response(HttpStatusCode.Conflict, null, new Dictionary<string, string>(), "application/json")));
            var connection = Substitute.For<IConnection>();
            connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "gists/1/star"),
                null, null).Returns(response);
            var apiConnection = Substitute.For<IApiConnection>();
            apiConnection.Connection.Returns(connection);

            var client = new GistsClient(apiConnection);

            await Assert.ThrowsAsync<ApiException>(() => client.IsStarred("1"));
        }