public async Task EnsureNonNullArguments()
 {
     var connection = Substitute.For<IApiConnection>();
     var client = new FollowersClient(connection);
                     
     await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent(null));                
 }
Exemplo n.º 2
0
            public void EnsureNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                Assert.Throws<ArgumentNullException>(() => client.GetAll(null));
                Assert.Throws<ArgumentException>(() => client.GetAll(""));
            }
Exemplo n.º 3
0
            public void RequestsTheCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                client.GetFollowingForCurrent();

                connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "user/following"));
            }
            public void RequestsTheCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                client.GetAll("alfhenrik");

                connection.Received().GetAll<User>(
                    Arg.Is<Uri>(u => u.ToString() == "users/alfhenrik/followers"), Args.ApiOptions);
            }
            public void RequestsTheCorrectUrlWithApiOptions()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

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

                client.GetAllForCurrent(options);

                connection.Received().GetAll<User>(
                    Arg.Is<Uri>(u => u.ToString() == "user/followers"),options);
            }
Exemplo n.º 6
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.PutAsync <object>(Arg.Is <Uri>(u => u.ToString() == "user/following/alfhenrik"),
                                             Args.Object).Returns(response);
                var apiConnection = Substitute.For <IApiConnection>();

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

                var result = await client.Follow("alfhenrik");

                Assert.Equal(expected, result);
            }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GoodreadsClient"/> class.
        /// Use this constructor if you already have OAuth permissions for the user.
        /// </summary>
        /// <param name="apiKey">Your Goodreads API key.</param>
        /// <param name="apiSecret">Your Goodreads API secret.</param>
        /// <param name="accessToken">The user's OAuth access token.</param>
        /// <param name="accessSecret">The user's OAuth access secret.</param>
        public GoodreadsClient(string apiKey, string apiSecret, string accessToken, string accessSecret)
        {
            var client = new RestClient(new Uri(GoodreadsUrl))
            {
                UserAgent = "goodreads-dotnet"
            };

            client.AddDefaultParameter("key", apiKey, ParameterType.QueryString);
            client.AddDefaultParameter("format", "xml", ParameterType.QueryString);

            var apiCredentials = new ApiCredentials(client, apiKey, apiSecret, accessToken, accessSecret);

            // Setup the OAuth authenticator if they have passed on the appropriate tokens
            if (!string.IsNullOrWhiteSpace(accessToken) &&
                !string.IsNullOrWhiteSpace(accessSecret))
            {
                client.Authenticator = OAuth1Authenticator.ForProtectedResource(
                    apiKey, apiSecret, accessToken, accessSecret);
            }

            Connection       = new Connection(client, apiCredentials);
            Authors          = new AuthorsClient(Connection);
            Books            = new BooksClient(Connection);
            Shelves          = new ShelvesClient(Connection);
            Users            = new UsersClient(Connection);
            Reviews          = new ReviewsClient(Connection);
            Series           = new SeriesClient(Connection);
            AuthorsFollowing = new AuthorsFollowingClient(Connection);
            Events           = new EventsClient(Connection);
            Followers        = new FollowersClient(Connection);
            Friends          = new FriendsClient(Connection);
            Notifications    = new NotificationsClient(Connection);
            Groups           = new GroupClient(Connection);
            Quotes           = new QuotesClient(Connection);
            UserStatuses     = new UserStatusesClient(Connection);
            Updates          = new UpdatesClient(Connection);
            Recommendations  = new RecommendationsClient(Connection);
            ReadStatuses     = new ReadStatusesClient(Connection);
        }
            public void EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                AssertEx.Throws<ArgumentNullException>(async () => await client.GetFollowing(null));
                AssertEx.Throws<ArgumentException>(async () => await client.GetFollowing(""));
            }
Exemplo n.º 9
0
            public async Task EnsureNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                await AssertEx.Throws<ArgumentNullException>(async () => await client.Unfollow(null));
                await AssertEx.Throws<ArgumentException>(async () => await client.Unfollow(""));
            }
Exemplo n.º 10
0
            public void RequestsTheCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                client.Unfollow("alfhenrik");

                connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "user/following/alfhenrik"));
            }
Exemplo n.º 11
0
            public async Task ThrowsExceptionForInvalidStatusCode()
            {
                var response = Task.Factory.StartNew<IResponse<object>>(() =>
                    new ApiResponse<object> { StatusCode = HttpStatusCode.Conflict });
                var connection = Substitute.For<IConnection>();
                connection.PutAsync<object>(Arg.Is<Uri>(u => u.ToString() == "user/following/alfhenrik"),
                    new { }).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new FollowersClient(apiConnection);

                await AssertEx.Throws<ApiException>(() => client.Follow("alfhenrik"));
            }
Exemplo n.º 12
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.PutAsync<object>(Arg.Is<Uri>(u => u.ToString() == "user/following/alfhenrik"),
                    Args.Object).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new FollowersClient(apiConnection);

                var result = await client.Follow("alfhenrik");

                Assert.Equal(expected, result);
            }
Exemplo n.º 13
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                await AssertEx.Throws<ArgumentNullException>(() => client.IsFollowing(null,  "alfhenrik-test"));
                await AssertEx.Throws<ArgumentNullException>(() => client.IsFollowing("alfhenrik", null));
                await AssertEx.Throws<ArgumentException>(() => client.IsFollowing("", "alfhenrik-text"));
                await AssertEx.Throws<ArgumentException>(() => client.IsFollowing("alfhenrik", ""));
            }
Exemplo n.º 14
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                await AssertEx.Throws<ArgumentNullException>(() => client.IsFollowingForCurrent(null));
                await AssertEx.Throws<ArgumentException>(() => client.IsFollowingForCurrent(""));
            }
Exemplo n.º 15
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new FollowersClient(connection);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllFollowing(null));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllFollowing(""));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllFollowing("fake", null));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllFollowing("", ApiOptions.None));
            }
Exemplo n.º 16
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() == "users/alfhenrik/following/alfhenrik-test"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new FollowersClient(apiConnection);

                await Assert.ThrowsAsync<ApiException>(() => client.IsFollowing("alfhenrik", "alfhenrik-test"));
            }
Exemplo n.º 17
0
            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() == "users/alfhenrik/following/alfhenrik-test"),
                    null, null).Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);
                var client = new FollowersClient(apiConnection);

                var result = await client.IsFollowing("alfhenrik", "alfhenrik-test");

                Assert.Equal(expected, result);
            }