Ejemplo n.º 1
0
 /// <summary>
 /// Instantiate a new GitHub Activities API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public ActivitiesClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Events   = new EventsClient(apiConnection);
     Starring = new StarredClient(apiConnection);
     Watching = new WatchedClient(apiConnection);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Instantiate a new GitHub Activities API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public ActivitiesClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Events = new EventsClient(apiConnection);
     Starring = new StarredClient(apiConnection);
     Watching = new WatchedClient(apiConnection);
 }
Ejemplo n.º 3
0
 public async Task <bool> UnWatchRepository(long repositoryId, GitHubClient authorizedGitHubClient)
 {
     if (_watchedClient == null)
     {
         _watchedClient = new WatchedClient(new ApiConnection(authorizedGitHubClient.Connection));
     }
     return(await _watchedClient.UnwatchRepo(repositoryId));
 }
Ejemplo n.º 4
0
 public async Task <Subscription> WatchRepository(long repositoryId, NewSubscription subscription, GitHubClient authorizedGitHubClient)
 {
     if (_watchedClient == null)
     {
         _watchedClient = new WatchedClient(new ApiConnection(authorizedGitHubClient.Connection));
     }
     return(await _watchedClient.WatchRepo(repositoryId, subscription));
 }
 /// <summary>
 /// Instantiate a new GitHub Activities API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public ActivitiesClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Events        = new EventsClient(apiConnection);
     Starring      = new StarredClient(apiConnection);
     Watching      = new WatchedClient(apiConnection);
     Feeds         = new FeedsClient(apiConnection);
     Notifications = new NotificationsClient(apiConnection);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Instantiate a new GitHub Activities API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public ActivitiesClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Events = new EventsClient(apiConnection);
     Starring = new StarredClient(apiConnection);
     Watching = new WatchedClient(apiConnection);
     Feeds = new FeedsClient(apiConnection);
     Notifications = new NotificationsClient(apiConnection);
 }
Ejemplo n.º 7
0
            public async Task RequestsCorrectUrl()
            {
                var endpoint   = new Uri("user/subscriptions", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new WatchedClient(connection);

                await client.GetAllForCurrent();

                connection.Received().GetAll <Repository>(endpoint, Args.ApiOptions);
            }
Ejemplo n.º 8
0
            public async Task RequestsCorrectUrl()
            {
                var endpoint = new Uri("user/subscriptions", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new WatchedClient(connection);

                await client.GetAllForCurrent();

                connection.Received().GetAll<Repository>(endpoint, Args.ApiOptions);
            }
Ejemplo n.º 9
0
            public void RequestsCorrectUrl()
            {
                var endpoint = new Uri("users/banana/subscriptions", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new WatchedClient(connection);

                client.GetAllForUser("banana");

                connection.Received().GetAll<Repository>(endpoint);
            }
Ejemplo n.º 10
0
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var endpoint   = new Uri("repositories/1/subscribers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new WatchedClient(connection);

                await client.GetAllWatchers(1);

                connection.Received().GetAll <User>(endpoint, Args.ApiOptions);
            }
Ejemplo n.º 11
0
            public void RequestsCorrectUrl()
            {
                var endpoint = new Uri("repos/fight/club/subscribers", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new WatchedClient(connection);

                client.GetAllWatchers("fight", "club");

                connection.Received().GetAll<User>(endpoint);
            }
Ejemplo n.º 12
0
            public void RequestsCorrectUrl()
            {
                var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new WatchedClient(connection);

                var newSubscription = new NewSubscription();
                client.WatchRepo("fight", "club", newSubscription);

                connection.Received().Put<Subscription>(endpoint, newSubscription);
            }
Ejemplo n.º 13
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new WatchedClient(Substitute.For <IApiConnection>());

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

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

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

                await Assert.ThrowsAsync <ArgumentException>(() => client.UnwatchRepo("owner", ""));
            }
Ejemplo n.º 14
0
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var endpoint   = new Uri("repositories/1/subscription", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new WatchedClient(connection);

                var newSubscription = new NewSubscription();

                client.WatchRepo(1, newSubscription);

                connection.Received().Put <Subscription>(endpoint, newSubscription);
            }
Ejemplo n.º 15
0
            public async Task ReturnsTrueOnValidResult()
            {
                var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative);

                var connection = Substitute.For<IApiConnection>();
                connection.Get<Subscription>(endpoint).Returns(Task.FromResult(new Subscription()));

                var client = new WatchedClient(connection);

                var watched = await client.CheckWatched("fight", "club");

                Assert.True(watched);
            }
Ejemplo n.º 16
0
            public async Task ReturnsFalseOnNotFoundException()
            {
                 var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative);

                var connection = Substitute.For<IApiConnection>();
                var response = new ApiResponse<Subscription> { StatusCode = HttpStatusCode.NotFound };
                connection.Get<Subscription>(endpoint).Returns(x => { throw new NotFoundException(response); });

                var client = new WatchedClient(connection);

                var watched = await client.CheckWatched("fight", "club");

                Assert.False(watched);
            }
Ejemplo n.º 17
0
            public async Task ReturnsTrueOnValidResultWithRepositoryId()
            {
                var endpoint = new Uri("repositories/1/subscription", UriKind.Relative);

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

                connection.Get <Subscription>(endpoint).Returns(Task.FromResult(new Subscription(false, false, null, default(DateTimeOffset), null, null)));

                var client = new WatchedClient(connection);

                var watched = await client.CheckWatched(1);

                Assert.True(watched);
            }
Ejemplo n.º 18
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new WatchedClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser(null));

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

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser("user", null));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUser(""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUser("", ApiOptions.None));
            }
Ejemplo n.º 19
0
            public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew<HttpStatusCode>(() => status);

                var connection = Substitute.For<IConnection>();
                connection.DeleteAsync(Arg.Is<Uri>(u => u.ToString() == "repos/yes/no/subscription"))
                    .Returns(response);

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

                var client = new WatchedClient(apiConnection);
                var result = await client.UnwatchRepo("yes", "no");

                Assert.Equal(expected, result);
            }
Ejemplo n.º 20
0
            public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions()
            {
                var endpoint   = new Uri("repositories/1/subscribers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new WatchedClient(connection);

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

                await client.GetAllWatchers(1, options);

                connection.Received().GetAll <User>(endpoint, options);
            }
Ejemplo n.º 21
0
            public void RequestsCorrectUrlWithApiOptions()
            {
                var endpoint   = new Uri("repos/fight/club/subscribers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new WatchedClient(connection);

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

                client.GetAllWatchers("fight", "club", options);

                connection.Received().GetAll <User>(endpoint, options);
            }
Ejemplo n.º 22
0
            public void RequestsCorrectUrlWithApiOptions()
            {
                var endpoint = new Uri("users/banana/subscriptions", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new WatchedClient(connection);

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

                client.GetAllForUser("banana", options);

                connection.Received().GetAll<Repository>(endpoint, options);
            }
Ejemplo n.º 23
0
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var endpoint   = new Uri("users/banana/subscriptions", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new WatchedClient(connection);

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

                await client.GetAllForUser("banana", options);

                connection.Received().GetAll <Repository>(endpoint, options);
            }
Ejemplo n.º 24
0
            public async Task ReturnsFalseOnNotFoundExceptionWithRepositoryId()
            {
                var endpoint = new Uri("repositories/1/subscription", UriKind.Relative);

                var connection = Substitute.For <IApiConnection>();
                var response   = CreateResponse(HttpStatusCode.NotFound);

                connection.Get <Subscription>(endpoint).Returns <Task <Subscription> >(x =>
                {
                    throw new NotFoundException(response);
                });

                var client = new WatchedClient(connection);

                var watched = await client.CheckWatched(1);

                Assert.False(watched);
            }
Ejemplo n.º 25
0
            public async Task ReturnsCorrectResultBasedOnStatusWithRepositoryId(HttpStatusCode status, bool expected)
            {
                var response = Task.FromResult(status);

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

                connection.Delete(Arg.Is <Uri>(u => u.ToString() == "repositories/1/subscription"))
                .Returns(response);

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

                apiConnection.Connection.Returns(connection);

                var client = new WatchedClient(apiConnection);
                var result = await client.UnwatchRepo(1);

                Assert.Equal(expected, result);
            }
Ejemplo n.º 26
0
            public async Task ReturnsFalseOnNotFoundException()
            {
                var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative);

                var connection = Substitute.For <IApiConnection>();
                var response   = new Response(HttpStatusCode.NotFound, null, new Dictionary <string, string>(), "application/json");

                connection.Get <Subscription>(endpoint).Returns <Task <Subscription> >(x =>
                {
                    throw new NotFoundException(response);
                });

                var client = new WatchedClient(connection);

                var watched = await client.CheckWatched("fight", "club");

                Assert.False(watched);
            }
Ejemplo n.º 27
0
            public async Task ReturnsFalseOnNotFoundException()
            {
                var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative);

                var connection = Substitute.For<IApiConnection>();
                var response = new Response(HttpStatusCode.NotFound, null, new Dictionary<string, string>(), "application/json");
                connection.Get<Subscription>(endpoint).Returns<Task<Subscription>>(x =>
                {
                    throw new NotFoundException(response);
                });

                var client = new WatchedClient(connection);

                var watched = await client.CheckWatched("fight", "club");

                Assert.False(watched);
            }
Ejemplo n.º 28
0
            public void RequestsCorrectUrlWithApiOptions()
            {
                var endpoint = new Uri("repos/fight/club/subscribers", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new WatchedClient(connection);

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

                client.GetAllWatchers("fight", "club", options);

                connection.Received().GetAll<User>(endpoint, options);
            }
Ejemplo n.º 29
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new WatchedClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent(null));
            }
Ejemplo n.º 30
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new WatchedClient(Substitute.For<IApiConnection>());

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

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

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrent(null));
            }