public async Task CategoryEntities_GetCategoriesIdsByEntityId_ShouldReturnExpectedCategoryIds()
        {
            var content = await JohnApi.GetData($"/api/categoryentities/entities/{FileId}/categories");

            var categoriesIds = await content.Content.ReadAsJArrayAsync();

            categoriesIds.Any(x => x.Value <string>() == CategoryId.ToString()).Should().BeTrue();
        }
Пример #2
0
        public async Task AddOneCategoryToEntity()
        {
            var nodesRequest = await JohnApi.GetData($"/api/categoryentities/categories/{CategoryId}");

            var nodes = await nodesRequest.Content.ReadAsJArrayAsync();

            nodes.Count.Should().Be(1);
            nodes[0].Value <string>("id").Should().Be(FileNodeId.ToString());
        }
Пример #3
0
        public async Task AddCategory_AddingCategoryToEntity_CategoryIdShouldAppearInCategoriesListForEntity()
        {
            var elasticSearchNodesRequest = await JohnApi.GetData($"/api/categoryentities/categories/{TreeId}");

            var elasticSearchNodes = await elasticSearchNodesRequest.Content.ReadAsJArrayAsync();

            elasticSearchNodes.Count.Should().Be(1);
            elasticSearchNodes.Single().Value <string>("id").Should().Be(FileId.ToString());
        }
Пример #4
0
        public async Task CategoryTreeOperations_DeleteCategoryTree_ExpectedUpdatedCategory()
        {
            var response = await JohnApi.DeleteData($"/api/categorytrees/tree/{CategoryId}");

            response.EnsureSuccessStatusCode();
            Harness.WaitWhileCategoryTreeDeletePersisted(CategoryId);

            response = await JohnApi.GetData($"/api/categorytrees/tree/{CategoryId}");

            response.StatusCode.Should().Be(System.Net.HttpStatusCode.NotFound);
        }
Пример #5
0
        public async Task EntityCategories_GetCategoriesIdsByEntityId_ShouldReturnEntityWithExpectedId()
        {
            var entitiesRequest = await JohnApi.GetData($"/api/categoryentities/categories/{CategoryId}");

            var entities = await entitiesRequest.Content.ReadAsJArrayAsync();

            entities.Should().HaveCount(1);
            var entity = entities.Single();

            entity["id"].Value <string>().Should().Be(FileId.ToString());
        }
Пример #6
0
        private async Task <JToken> GetNodeByCategoryId(string categoryId)
        {
            var nodesResponseContent = await JohnApi.GetData($"/api/categoryentities/categories/{categoryId}");

            var elasticSearchNodes = await nodesResponseContent.Content.ReadAsJArrayAsync();

            if (elasticSearchNodes.Count() != 0)
            {
                return(elasticSearchNodes.First());
            }

            return(null);
        }
        public async Task CategoryTreeOperations_DeleteCategoryTree_ExpectedUpdatedCategory()
        {
            var url  = $"/api/categorytrees/tree/{CategoryId}";
            var data = $"[{{'op':'replace','path':'isDeleted','value':true}}]";

            var response = await JohnApi.PatchData(url, data);

            response.EnsureSuccessStatusCode();
            Harness.WaitWhileCategoryTreeDeletePersisted(CategoryId);

            response = await JohnApi.GetData($"/api/categorytrees/tree/{CategoryId}");

            response.StatusCode.Should().Be(System.Net.HttpStatusCode.NotFound);
        }
Пример #8
0
        public async Task DeleteOneCategoryToEntity()
        {
            var fileNodeResponse = await JohnApi.GetNodeById(FileId);

            var fileNode = await fileNodeResponse.Content.ReadAsJObjectAsync();

            var fileNodeId = Guid.Parse(fileNode.Value <string>("id"));

            var treeResponse = await JohnApi.GetData($"api/categorytrees/tree/{RootCategoryId}");

            var treeContent = await treeResponse.Content.ReadAsJObjectAsync();

            var categoryId1 = treeContent["nodes"][0]["children"][0]["id"].ToString();
            var categoryId2 = treeContent["nodes"][0]["children"][1]["id"].ToString();

            // add categories to entity
            await JohnApi.PostData($"/api/categoryentities/entities/{fileNodeId}/categories", new List <string> {
                categoryId1, categoryId2
            });

            WebFixture.WaitWhileCategoryIndexed(categoryId1.ToString());
            WebFixture.WaitWhileCategoryIndexed(categoryId2.ToString());
            // check if node exists by categoryId1
            var firstCategoryAddedNodeRequest = await JohnApi.GetData($"/api/categoryentities/categories/{categoryId1}");

            var firstCategoryAddedNode = await firstCategoryAddedNodeRequest.Content.ReadAsJArrayAsync();

            firstCategoryAddedNode.First().Value <string>("id").Should().Be(fileNodeId.ToString());

            // delete first category from node
            await JohnApi.DeleteData($"/api/categoryentities/entities/{fileNodeId}/categories/{categoryId1}");

            WebFixture.WaitWhileCategoryDeleted(categoryId1.ToString());
            // check if node contains categoryId1
            var firstCategoryDeletedNodeRequest = await JohnApi.GetData($"/api/categoryentities/categories/{categoryId1}");

            var firstCategoryDeletedNode = await firstCategoryDeletedNodeRequest.Content.ReadAsJArrayAsync();

            firstCategoryDeletedNode.Should().BeEmpty();

            var secondCategoryAddedNodeRequest = await JohnApi.GetData($"/api/categoryentities/categories/{categoryId2}");

            var secondCategoryAddedNode = await secondCategoryAddedNodeRequest.Content.ReadAsJArrayAsync();

            secondCategoryAddedNode.First().Value <string>("id").Should().Be(fileNodeId.ToString());
        }
Пример #9
0
        public async Task DeleteCategory_DeleteOneCategoryFromEntity_CategoryIdShouldBeRemovedFromEntity()
        {
            var fileNodeResponse = await JohnApi.GetNodeById(FileId);

            var fileNode = await fileNodeResponse.Content.ReadAsJObjectAsync();

            var fileNodeId = Guid.Parse(fileNode.Value <string>("id"));

            var treeRequest = await JohnApi.GetData($"api/categorytrees/tree/{RootCategoryId}");

            var treeContent = await treeRequest.Content.ReadAsJObjectAsync();

            var categoryId1 = treeContent["nodes"][0]["children"][0]["id"].ToString();
            var categoryId2 = treeContent["nodes"][0]["children"][1]["id"].ToString();

            // add categories to entity
            await JohnApi.PostData($"/api/categoryentities/entities/{fileNodeId}/categories", new List <string> {
                categoryId1, categoryId2
            });

            WebFixture.WaitWhileCategoryIndexed(fileNodeId.ToString());

            var firstCategoryAddedNode = await GetNodeByCategoryId(categoryId1);

            firstCategoryAddedNode.Value <string>("id").Should().Be(fileNodeId.ToString());

            // delete first category from node
            await JohnApi.DeleteData($"/api/categoryentities/entities/{fileNodeId}/categories/{categoryId1}");

            // check if node contains categoryId
            WebFixture.WaitWhileCategoryDeleted(categoryId1);
            var firstCategoryDeletedNode = await GetNodeByCategoryId(categoryId1);

            firstCategoryDeletedNode.Should().BeNull();

            var entityCategoryIdsRequest = await JohnApi.GetData($"/api/categoryentities/entities/{fileNodeId}/categories");

            var entityCategoryIds = await entityCategoryIdsRequest.Content.ReadAsJArrayAsync();

            entityCategoryIds.Should().HaveCount(1);
            entityCategoryIds.Single().Value <string>("id").Should().Be(categoryId2);
        }
        public async Task GetCategoriesIdsByEntityIdTest()
        {
            var fileNodeResponse = await JohnApi.GetNodeById(FileId);

            var fileNode = await fileNodeResponse.Content.ReadAsJObjectAsync();

            var fileNodeId = Guid.Parse(fileNode.Value <string>("id"));

            await JohnApi.PostData($"/api/categoryentities/entities/{fileNodeId}/categories", new List <Guid> {
                CategoryId
            });

            WebFixture.WaitWhileCategoryIndexed(CategoryId.ToString());

            var response = await JohnApi.GetData($"/api/categoryentities/entities/{fileNodeId}/categories");

            var categoriesIds = await response.Content.ReadAsJArrayAsync();

            categoriesIds.Single().Value <string>().Should().Be(CategoryId.ToString());
        }
        public async Task CategoryTree_CreateNewCategoryTree_BuiltExpectedDocument()
        {
            var response = await JohnApi.GetData($"/api/categorytrees/tree/{CategoryId}");

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var jsonCategory = JToken.Parse(await response.Content.ReadAsStringAsync());

            jsonCategory.Should().ContainsJson($@"
            {{
                'id': '{CategoryId}',
                'createdBy': '{JohnId}',
                'createdDateTime': *EXIST*,
                'updatedBy': '{JohnId}',
                'updatedDateTime': *EXIST*,
                'version': 1,
                'nodes': *EXIST*
            }}");
        }
Пример #12
0
        public async Task CategoryTree_CreateNewCategoryTree_BuiltExpectedDocument()
        {
            var contentRequest = await JohnApi.GetData($"/api/categorytrees/tree/{CategoryId}");

            var jsonCategory = await contentRequest.Content.ReadAsJObjectAsync();

            jsonCategory.Should().HaveElement("id");
            jsonCategory["id"].Value <string>().Should().Be(CategoryId.ToString());

            jsonCategory.Should().HaveElement("createdBy");
            jsonCategory["createdBy"].Value <string>().Should().Be(JohnId.ToString());

            jsonCategory.Should().HaveElement("createdDateTime")
            .And.HaveElement("createdDateTime")
            .And.HaveElement("updatedDateTime");

            jsonCategory.Should().HaveElement("version");
            jsonCategory["version"].Value <int>().Should().Be(1);

            jsonCategory.Should().HaveElement("nodes");
            var treeNodes = jsonCategory["nodes"].Value <JArray>();

            treeNodes.Should().HaveCount(1);
            var mainNode = treeNodes.Single();

            mainNode.Should().HaveElement("title");
            mainNode["title"].Value <string>().Should().Be("Projects");
            var insideNodes = mainNode["children"].Value <JArray>();

            insideNodes.Should().HaveCount(2);
            var titles = insideNodes.Select(i => i["title"].Value <string>());

            titles.Should().Contain(new List <string> {
                "Projects One", "Projects Two"
            });
            insideNodes[0].Should().HaveElement("id");
            insideNodes[1].Should().HaveElement("id");
        }
Пример #13
0
        public async Task CategoryTree_UpdateCategoryTreeNode_UpdatedCategoryMayBeExpectedDocument()
        {
            var response = await JohnApi.PutData($"/api/categorytrees/tree/{CategoryId}/{NodeId}", Categories);

            Harness.WaitWhileCategoryTreeUpdatedPersisted(CategoryId);

            response = await JohnApi.GetData($"/api/categorytrees/tree/{CategoryId}");

            response.EnsureSuccessStatusCode();

            var jsonCategory = JToken.Parse(await response.Content.ReadAsStringAsync());

            jsonCategory.Should().ContainsJson($@"
            {{
                'id': '{CategoryId}',
                'createdBy': '{JohnId}',
                'createdDateTime': *EXIST*,
                'updatedBy': '{JohnId}',
                'updatedDateTime': *EXIST*,
                'version': 2,
                'nodes': *EXIST*
            }}");
        }
Пример #14
0
        public async Task CategoryTree_UpdateCategoryTreeNode_UpdatedCategoryMayBeExpectedDocument()
        {
            var json = $@"[
              {{
                'title': 'Level 0: Main Node 1',
                'children': [
                  {{ 'title': 'Level 1: Node 1' }},
                  {{ 'title': 'Level 1: Node 2' }}
                ]
              }}
            ]";

            var url  = $"/api/categorytrees/tree/{CategoryId}";
            var data = $"[{{'op':'replace','path':'nodes','value': {json} }}]";

            var response = await JohnApi.PatchData(url, data);

            Harness.WaitWhileCategoryTreeUpdatedPersisted(CategoryId);

            response = await JohnApi.GetData($"/api/categorytrees/tree/{CategoryId}");

            response.EnsureSuccessStatusCode();

            var jsonCategory = JToken.Parse(await response.Content.ReadAsStringAsync());

            jsonCategory.Should().ContainsJson($@"
            {{
                'id': '{CategoryId}',
                'createdBy': '{JohnId}',
                'createdDateTime': *EXIST*,
                'updatedBy': '{JohnId}',
                'updatedDateTime': *EXIST*,
                'version': 2,
                'nodes': *EXIST*
            }}");
        }
Пример #15
0
        public async Task CategoryTreeOperations_GetAllCategoryTrees_ExpectedListOfCategories()
        {
            var response = await JohnApi.GetData($"/api/categorytrees/tree");

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var jsonCategories = JArray.Parse(await response.Content.ReadAsStringAsync());

            jsonCategories.Should().NotBeEmpty();
            foreach (var category in jsonCategories.Children())
            {
                category.Should().ContainsJson($@"
                {{
                    'id': *EXIST*,
                    'createdBy': '{JohnId}',
                    'createdDateTime': *EXIST*,
                    'updatedBy': '{JohnId}',
                    'updatedDateTime': *EXIST*,
                    'version': *EXIST*
                }}");
            }
        }
Пример #16
0
        public async Task CategoryTree_UpdateExistantCategoryTree_BuiltExpectedDocument()
        {
            var contentRequest = await JohnApi.GetData($"/api/categorytrees/tree/{CategoryId}");

            var jsonCategory = await contentRequest.Content.ReadAsJObjectAsync();

            jsonCategory.Should().HaveElement("id");
            jsonCategory["id"].Value <string>().Should().Be(CategoryId.ToString());

            jsonCategory.Should().HaveElement("createdBy");
            jsonCategory["createdBy"].Value <string>().Should().Be(JohnId.ToString());

            jsonCategory.Should().HaveElement("createdDateTime")
            .And.HaveElement("createdDateTime")
            .And.HaveElement("updatedDateTime");

            jsonCategory.Should().HaveElement("version");
            jsonCategory["version"].Value <int>().Should().Be(2);

            jsonCategory.Should().HaveElement("nodes");
            var treeNodes = jsonCategory["nodes"].Value <JArray>();

            treeNodes.Should().HaveCount(6);
            treeNodes.Select(i => i.Should().HaveElement("id"));
            var titles = treeNodes.Select(i => i["title"].Value <string>());

            titles.Should().Contain(new List <string> {
                "Level 0: Main Node 1", "NoNameNode", "1", "2", "3", "4"
            });
            var firstNode = treeNodes.Where(i => i.Value <string>("title") == "Level 0: Main Node 1").SingleOrDefault();

            firstNode.Should().NotBeNull();
            firstNode.Should().HaveElement("title");
            var insideNodes = firstNode["children"].Value <JArray>();

            insideNodes.Should().HaveCount(2);
            var insideTitles = insideNodes.Select(i => i["title"].Value <string>());

            insideTitles.Should().Contain(new List <string> {
                "Level 1: Node 1", "Level 1: Node 2"
            });
            insideNodes.Select(i => i.Should().HaveElement("id"));

            var lastNode = treeNodes.Where(i => i.Value <string>("title") == "4").SingleOrDefault();

            lastNode.Should().NotBeNull();
            var lastNodeInsideNodes = lastNode["children"].Value <JArray>();

            lastNodeInsideNodes.Should().HaveCount(2);
            var lastNodeInsideTitles = lastNodeInsideNodes.Select(i => i["title"].Value <string>());

            lastNodeInsideTitles.Should().Contain(new List <string> {
                "4-1", "4-2"
            });
            lastNodeInsideNodes.Select(i => i.Should().HaveElement("id"));

            var lastNodeSubnode = lastNodeInsideNodes.Where(i => i.Value <string>("title") == "4-2").SingleOrDefault();

            lastNodeSubnode.Should().NotBeNull();
            var lastSubnodeChildren = lastNodeSubnode["children"].Value <JArray>();

            lastSubnodeChildren.Should().HaveCount(1);
            lastSubnodeChildren.Single().Should().HaveElement("id");
        }
        public async Task CategoryTree_GetNonExistantCategoryTree_ReturnsNotFoundCode()
        {
            var response = await JohnApi.GetData($"/api/categorytrees/tree/{Guid.NewGuid()}");

            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }