public async Task EnsureNonNullArguments()
            {
                var orgMembers = new OrganizationMembersClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => orgMembers.CheckMember(null, "username"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => orgMembers.CheckMember(null, ""));

                await Assert.ThrowsAsync <ArgumentNullException>(() => orgMembers.CheckMember("org", null));

                await Assert.ThrowsAsync <ArgumentException>(() => orgMembers.CheckMember("", null));
            }
            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() == "orgs/org/members/username"),
                                        null, null).Returns(response);
                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);
                var client = new OrganizationMembersClient(apiConnection);

                await Assert.ThrowsAsync <ApiException>(() => client.CheckMember("org", "username"));
            }
            public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew <IApiResponse <object> >(() =>
                                                                              new ApiResponse <object>(new Response(status, null, new Dictionary <string, string>(), "application/json")));
                var connection = Substitute.For <IConnection>();

                connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "orgs/org/members/username"),
                                        null, null).Returns(response);
                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);
                var client = new OrganizationMembersClient(apiConnection);

                var result = await client.CheckMember("org", "username");

                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.GetAsync <object>(Arg.Is <Uri>(u => u.ToString() == "orgs/org/members/username"),
                                             null, null).Returns(response);
                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);
                var client = new OrganizationMembersClient(apiConnection);

                AssertEx.Throws <ApiException>(async() => await client.CheckMember("org", "username"));
            }
예제 #5
0
            public async Task ThrowsExceptionForInvalidStatusCode()
            {
                var response     = CreateResponse(HttpStatusCode.Conflict);
                var responseTask = Task.FromResult <IApiResponse <object> >(new ApiResponse <object>(response));

                var connection = Substitute.For <IConnection>();

                connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "orgs/org/members/username"), null, null)
                .Returns(responseTask);

                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);
                var client = new OrganizationMembersClient(apiConnection);

                await Assert.ThrowsAsync <ApiException>(() => client.CheckMember("org", "username"));
            }
예제 #6
0
            public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected)
            {
                var response     = CreateResponse(status);
                var responseTask = Task.FromResult <IApiResponse <object> >(new ApiResponse <object>(response));

                var connection = Substitute.For <IConnection>();

                connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "orgs/org/members/username"), null, null)
                .Returns(responseTask);

                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);
                var client = new OrganizationMembersClient(apiConnection);

                var result = await client.CheckMember("org", "username");

                Assert.Equal(expected, result);
            }
            public async Task EnsureNonNullArguments()
            {
                var orgMembers = new OrganizationMembersClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => orgMembers.CheckMember(null, "username"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => orgMembers.CheckMember(null, ""));
                await Assert.ThrowsAsync<ArgumentNullException>(() => orgMembers.CheckMember("org", null));
                await Assert.ThrowsAsync<ArgumentException>(() => orgMembers.CheckMember("", null));
            }
            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() == "orgs/org/members/username"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new OrganizationMembersClient(apiConnection);

                await Assert.ThrowsAsync<ApiException>(() => client.CheckMember("org", "username"));
            }
            public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew<IApiResponse<object>>(() =>
                    new ApiResponse<object>(new Response(status, null, new Dictionary<string, string>(), "application/json")));
                var connection = Substitute.For<IConnection>();
                connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/members/username"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new OrganizationMembersClient(apiConnection);

                var result = await client.CheckMember("org", "username");

                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.GetAsync<object>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/members/username"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new OrganizationMembersClient(apiConnection);

                AssertEx.Throws<ApiException>(async () => await client.CheckMember("org", "username"));
            }