private static ObservableAssigneesClient CreateFixtureWithNonReactiveClient()
 {
     var nonreactiveClient = new AssigneesClient(Substitute.For<IApiConnection>());
     var github = Substitute.For<IGitHubClient>();
     github.Issue.Assignee.Returns(nonreactiveClient);
     return new ObservableAssigneesClient(github);
 }
Ejemplo n.º 2
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new AssigneesClient(Substitute.For<IApiConnection>());

                await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForRepository(null, "name"));
                await AssertEx.Throws<ArgumentException>(async () => await client.GetForRepository(null, ""));
                await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForRepository("owner", null));
                await AssertEx.Throws<ArgumentException>(async () => await client.GetForRepository("", null));
            }
Ejemplo n.º 3
0
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new AssigneesClient(connection);

                client.GetForRepository("fake", "repo");

                connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/assignees"));
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new AssigneesClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.CheckAssignee(null, "name", "tweety"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.CheckAssignee(null, "", "tweety"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.CheckAssignee("owner", null, "tweety"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.CheckAssignee("", null, "tweety"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.CheckAssignee("owner", "name", null));
                await Assert.ThrowsAsync<ArgumentException>(() => client.CheckAssignee("owner", "name", ""));
            }
Ejemplo n.º 5
0
            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() == "repos/foo/bar/assignees/cody"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new AssigneesClient(apiConnection);

                AssertEx.Throws<ApiException>(async () => await client.CheckAssignee("foo", "bar", "cody"));
            }
            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() == "repos/foo/bar/assignees/cody"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new AssigneesClient(apiConnection);

                await Assert.ThrowsAsync<ApiException>(() => client.CheckAssignee("foo", "bar", "cody"));
            }
Ejemplo n.º 7
0
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new AssigneesClient(connection);

                await client.GetAllForRepository(1);

                connection.Received().GetAll<User>(
                    Arg.Is<Uri>(u => u.ToString() == "repositories/1/assignees"),
                    null,
                    AcceptHeaders.StableVersion,
                    Args.ApiOptions);
            }
Ejemplo n.º 8
0
            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.GetAsync<object>(Arg.Is<Uri>(u => u.ToString() == "repos/foo/bar/assignees/cody"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new AssigneesClient(apiConnection);

                var result = await client.CheckAssignee("foo", "bar", "cody");

                Assert.Equal(expected, result);
            }
Ejemplo n.º 9
0
            public async Task EnsuresNonNullArguments()
            {
                var client       = new AssigneesClient(Substitute.For <IApiConnection>());
                var newAssignees = new AssigneesUpdate(new List <string>()
                {
                    "assignee1", "assignee2"
                });

                await Assert.ThrowsAsync <ArgumentException>(() => client.RemoveAssignees("", "name", 2, newAssignees));

                await Assert.ThrowsAsync <ArgumentException>(() => client.RemoveAssignees("owner", "", 2, newAssignees));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.RemoveAssignees("owner", "name", 2, null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.RemoveAssignees(null, "name", 2, newAssignees));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.RemoveAssignees("owner", null, 2, newAssignees));
            }
Ejemplo n.º 10
0
            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.GetAsync <object>(Arg.Is <Uri>(u => u.ToString() == "repos/foo/bar/assignees/cody"),
                                             null, null).Returns(response);
                var apiConnection = Substitute.For <IApiConnection>();

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

                var result = await client.CheckAssignee("foo", "bar", "cody");

                Assert.Equal(expected, result);
            }
Ejemplo n.º 11
0
            public void RequestsCorrectUrlWithApiOptions()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new AssigneesClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    PageSize  = 1,
                    StartPage = 1
                };

                client.GetAllForRepository("fake", "repo", options);

                connection.Received().GetAll <User>(
                    Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/assignees"),
                    null,
                    AcceptHeaders.StableVersion,
                    options);
            }
Ejemplo n.º 12
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new AssigneesClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.CheckAssignee(null, "name", "tweety"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.CheckAssignee("owner", null, "tweety"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.CheckAssignee("owner", "name", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.CheckAssignee(1, null));

                await Assert.ThrowsAsync <ArgumentException>(() => client.CheckAssignee("", "name", "tweety"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.CheckAssignee("owner", "", "tweety"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.CheckAssignee("owner", "name", ""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.CheckAssignee(1, ""));
            }
Ejemplo n.º 13
0
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new AssigneesClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    PageSize = 1,
                    StartPage = 1
                };

                await client.GetAllForRepository("fake", "repo", options);

                connection.Received().GetAll<User>(
                    Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/assignees"),
                    null,
                    AcceptHeaders.StableVersion,
                    options);
            }
Ejemplo n.º 14
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new AssigneesClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository(null, "name"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository("owner", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository(1, null));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForRepository("", "name"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForRepository("owner", ""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForRepository("", "name", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForRepository("owner", "", ApiOptions.None));
            }
Ejemplo n.º 15
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new AssigneesClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, null));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", ""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", ApiOptions.None));
            }
Ejemplo n.º 16
0
            public async Task RequestsCorrectValueForStatusCodeWithRepositoryId(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() == "repositories/1/assignees/cody"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new AssigneesClient(apiConnection);

                var result = await client.CheckAssignee(1, "cody");

                Assert.Equal(expected, result);
            }