Esempio n. 1
0
        public async Task UpdateAsync_UpdateListingNull_Throw()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new ListingClient(apiConnection);

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await client.UpdateAsync(1, null));

            await apiConnection.DidNotReceive().ExecutePutAsync <object, Listing>(Arg.Any <string>(), Arg.Any <object>());
        }
Esempio n. 2
0
        public async Task UpdateAsync()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new ListingClient(apiConnection);

            await client.UpdateAsync(1, new UpdateListing());

            await apiConnection.Received().ExecutePutAsync <object, Listing>("listings/1", Arg.Any <object>());
        }
Esempio n. 3
0
        public async Task GetByIdAsync_IdZero_Throw()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new ListingClient(apiConnection);

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await client.GetByIdAsync(0));

            await apiConnection.DidNotReceive().ExecuteGetAsync <Listing>(Arg.Any <string>());
        }
Esempio n. 4
0
        public async Task GetByIdAsync()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new ListingClient(apiConnection);

            await client.GetByIdAsync(1);

            await apiConnection.Received().ExecuteGetAsync <Listing>("listings/1");
        }
Esempio n. 5
0
        public async Task GetByCategoryAsync()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new ListingClient(apiConnection);

            await client.GetByCategoryAsync(CategoryListing.Events);

            await apiConnection.Received().ExecutePaginationGetAsync <Listing>("listings/category/events", Arg.Any <PageQueryOption>());
        }
Esempio n. 6
0
        /// <summary>
        /// API client
        /// </summary>
        /// <remarks>
        /// See the <a href="https://docs.dev.to/api/#section/Authentication/api_key">Authentication</a> for more information
        /// </remarks>
        /// <param name="apiUrl">API connection url</param>
        /// <param name="token">API key</param>
        public DevToClient(string apiUrl, string token)
        {
            var restClient = new RestClient(apiUrl);

            restClient.AddDefaultHeader("api-key", token);
            restClient.AddDefaultHeader("User-Agent", "DevToAPI-client-dotnet");
            var apiConnection = new ApiConnection(restClient);

            AdminConfigurations = new AdminConfigurationClient(apiConnection);
            Articles            = new ArticleClient(apiConnection);
            Comments            = new CommentClient(apiConnection);
            Followers           = new FollowerClient(apiConnection);
            Follows             = new FollowClient(apiConnection);
            Listings            = new ListingClient(apiConnection);
            Organizations       = new OrganizationClient(apiConnection);
            PodcastEpisodes     = new PodcastEpisodeClient(apiConnection);
            ReadingLists        = new ReadingListClient(apiConnection);
            Tags          = new TagClient(apiConnection);
            Users         = new UserClient(apiConnection);
            Videos        = new VideoClient(apiConnection);
            Webhooks      = new WebhookClient(apiConnection);
            ProfileImages = new ProfileImageClient(apiConnection);
        }