예제 #1
0
        public void UpdateTag_DuplicitName_ThrowsException()
        {
            // Arrange
            var tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag1Color
            };

            PostAndMarkForDelete(tagPostModel);
            tagPostModel = new TagPostModel
            {
                Name  = Tag2Color,
                Color = Tag2Color
            };
            var id            = PostAndMarkForDelete(tagPostModel);
            var tagPatchModel = new TagPatchModel
            {
                Id   = id,
                Name = Tag1Name
            };

            // Act
            var result = TagClient.Update(tagPatchModel);

            // Assert
            Assert.False(result.IsSuccess);
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
예제 #2
0
        private int PostAndMarkForDelete(TagPostModel tagPostModel)
        {
            var tagGetModel = TagClient.Post(tagPostModel).AssertResult();

            MarkForDelete(tagGetModel.Id);
            return(tagGetModel.Id);
        }
예제 #3
0
 public void TearDown()
 {
     foreach (var id in _tagIdsToDelete)
     {
         TagClient.Delete(id);
     }
 }
예제 #4
0
        public void Get_WithFilter_ReturnsFilteredList()
        {
            // Arrange
            var tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag1Color
            };

            PostAndMarkForDelete(tagPostModel);
            tagPostModel = new TagPostModel
            {
                Name  = Tag2Name,
                Color = Tag2Color
            };
            var id = PostAndMarkForDelete(tagPostModel);

            // Act
            var data = TagClient.List()
                       .Filter(t => t.Name.IsEqual(Tag2Name))
                       .Get().AssertResult();

            // Assert
            Assert.AreEqual(1, data.TotalItems);
            Assert.AreEqual(1, data.TotalPages);
            Assert.NotNull(data.Items);
            Assert.NotZero(data.Items.Count());
            var tag = data.Items.First(t => t.Id == id);

            Assert.AreEqual(id, tag.Id);
            Assert.AreEqual(tagPostModel.Color, tag.Color);
            Assert.AreEqual(tagPostModel.Name, tag.Name);
        }
예제 #5
0
        public async Task GetAsync()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new TagClient(apiConnection);

            await client.GetAsync();

            await apiConnection.Received().ExecutePaginationGetAsync <TagArticle>("tags", Arg.Any <PageQueryOption>());
        }
예제 #6
0
        public async Task DeleteTagAsync_NonExistingId_Fails()
        {
            // Arrange
            var tagId = 0;

            // Act
            var result = await TagClient.DeleteAsync(tagId);

            // Assert
            Assert.False(result.IsSuccess);
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
예제 #7
0
        public void DeleteTag_NonExistingId_Fails()
        {
            // Arrange
            var tagId = 0;

            // Act
            var result = TagClient.Delete(tagId);

            // Assert
            Assert.False(result.IsSuccess);
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
예제 #8
0
        public void UpdateTag_NonExistingId_ThrowsException()
        {
            // Arrange
            var tagId         = 0;
            var tagPatchModel = new TagPatchModel
            {
                Id = tagId
            };

            // Act
            var result = TagClient.Update(tagPatchModel);

            // Assert
            Assert.False(result.IsSuccess);
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
예제 #9
0
        public async Task DeleteTagAsync_SuccessfullyDeleted()
        {
            // Arrange
            var tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag1Color
            };
            var id = PostAndMarkForDelete(tagPostModel);

            // Act
            var result = (await TagClient.DeleteAsync(id)).AssertResult();

            // Assert
            Assert.True(result);
        }
예제 #10
0
        public void DeleteTag_SuccessfullyDeleted()
        {
            // Arrange
            var tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag1Color
            };
            var id = PostAndMarkForDelete(tagPostModel);

            // Act
            var result = TagClient.Delete(id).AssertResult();

            // Assert
            Assert.True(result);
        }
예제 #11
0
        public void AddTag_SuccessfullyAdded()
        {
            // Arrange
            var tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag1Color
            };

            // Act
            var tagGetModel = TagClient.Post(tagPostModel).AssertResult();

            MarkForDelete(tagGetModel.Id);

            // Assert
            Assert.NotZero(tagGetModel.Id);
            Assert.AreEqual(Lowercase(tagPostModel.Color), tagGetModel.Color);
            Assert.AreEqual(tagPostModel.Name, tagGetModel.Name);
        }
예제 #12
0
        public void AddTag_DuplicitName_Fails()
        {
            // Arrange
            var tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag1Color
            };

            PostAndMarkForDelete(tagPostModel);
            tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag2Color
            };

            // Act
            var result = TagClient.Post(tagPostModel);

            // Assert
            Assert.False(result.IsSuccess);
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
예제 #13
0
        public async Task UpdateTagAsync_ColorOnlyUpdate_SuccessfullyUpdated()
        {
            // Arrange
            var tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag1Color
            };
            var id            = PostAndMarkForDelete(tagPostModel);
            var tagPatchModel = new TagPatchModel
            {
                Id    = id,
                Color = Tag2Color
            };

            // Act
            var tagGetModel = (await TagClient.UpdateAsync(tagPatchModel)).AssertResult();

            // Assert
            Assert.NotZero(tagGetModel.Id);
            Assert.AreEqual(Lowercase(tagPatchModel.Color), tagGetModel.Color);
            Assert.AreEqual(tagPostModel.Name, tagGetModel.Name);
        }
예제 #14
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);
        }
예제 #15
0
        public void UpdateTag_NameOnlyUpdate_Name_SuccessfullyUpdated()
        {
            // Arrange
            var tagPostModel = new TagPostModel
            {
                Name  = Tag1Name,
                Color = Tag1Color
            };
            var id            = PostAndMarkForDelete(tagPostModel);
            var tagPatchModel = new TagPatchModel
            {
                Id   = id,
                Name = Tag2Name
            };

            // Act
            var tagGetModel = TagClient.Update(tagPatchModel).AssertResult();

            // Assert
            Assert.NotZero(tagGetModel.Id);
            Assert.AreEqual(Lowercase(tagPostModel.Color), tagGetModel.Color);
            Assert.AreEqual(tagPatchModel.Name, tagGetModel.Name);
        }
        public void TagsBaseUrlTest()
        {
            string baseUrl = TagClient.TagsBaseUrl(ProjectId);

            baseUrl.Should().Be("projects/" + ProjectId + "/repository/tags");
        }
예제 #17
0
 private void Update()
 {
     _instance    = instance;
     _localPlayer = localPlayer;
     _client      = client;
 }
예제 #18
0
 private void FindReferences()
 {
     client = GetComponent <TagClient>();
 }