public async Task ProductCategoriesWorkflow()
        {
            using var client = await TestBootstrapper.CreateTestClientWithInMemoryDb();

            await TestRecordsCreator.CreateCategoryAsync(client, "stocks/Germany/Dax 30");

            var getCategoriesResponse = await client.GetAsync("/api/product-categories");

            var categories = (await getCategoriesResponse.Content.ReadAsStringAsync())
                             .DeserializeJson <GetProductCategoriesResponse>().ProductCategories;

            Assert.Equal(3, categories.Count);
            Assert.True(categories.First(c => c.Id == "stocks.germany.dax_30").IsLeaf);
            Assert.False(categories.First(c => c.Id == "stocks.germany").IsLeaf);
            Assert.False(categories.First(c => c.Id == "stocks").IsLeaf);

            var deleteRequest = new DeleteProductCategoryRequest()
            {
                UserName = "******",
            };

            var leafCategoryId = "stocks.germany.dax_30";

            await client.DeleteAsJsonAsync($"/api/product-categories/{leafCategoryId}", deleteRequest);

            getCategoriesResponse = await client.GetAsync("/api/product-categories");

            categories = (await getCategoriesResponse.Content.ReadAsStringAsync())
                         .DeserializeJson <GetProductCategoriesResponse>().ProductCategories;

            Assert.Equal(2, categories.Count);
            Assert.True(categories.First(c => c.Id == "stocks.germany").IsLeaf);
            Assert.False(categories.First(c => c.Id == "stocks").IsLeaf);
        }
        public async Task ProductCategories_ParentHasAttachedProducts_Workflow()
        {
            _underlyingsCacheMock.Setup(x => x.GetByMdsCode(It.IsAny <string>()))
            .Returns(new UnderlyingsCacheModel()
            {
                MdsCode         = "mds-code",
                TradingCurrency = "EUR",
            });

            _assetTypesRepositoryMock.Setup(x => x.ExistsAsync(It.IsAny <string>()))
            .ReturnsAsync(true);

            using var client = await TestBootstrapper.CreateTestClientWithInMemoryDb(builder =>
            {
                builder.RegisterInstance(_underlyingsCacheMock.Object).As <IUnderlyingsCache>().SingleInstance();
                builder.RegisterInstance(_assetTypesRepositoryMock.Object).As <IAssetTypesRepository>().SingleInstance();
            });

            var categoryWithProduct = "stocks/germany";
            var category            = "stocks/germany/dax 30";

            await TestRecordsCreator.CreateCurrencyAsync(client, "EUR");

            await TestRecordsCreator.CreateMarketSettings(client, "market");

            await TestRecordsCreator.CreateTickFormula(client, "tick_formula");

            // asset type is mocked
            await TestRecordsCreator.CreateProductAsync(client, "product1", categoryWithProduct);

            var errorCode = await TestRecordsCreator.CreateCategoryAsync(client, category);

            Assert.Equal(ProductCategoriesErrorCodesContract.ParentHasAttachedProducts, errorCode);

            var getCategoriesResponse = await client.GetAsync("/api/product-categories");

            var categories = (await getCategoriesResponse.Content.ReadAsStringAsync())
                             .DeserializeJson <GetProductCategoriesResponse>().ProductCategories;

            Assert.Collection(categories,
                              x => { Assert.Equal("stocks", x.Id); },
                              x1 => { Assert.Equal("stocks.germany", x1.Id); });
        }
        public async Task ProductCategories_CannotDeleteNonLeafCategory_Workflow()
        {
            using var client = await TestBootstrapper.CreateTestClientWithInMemoryDb();

            var notLeafCategory = "stocks";
            var category        = "stocks/germany";

            await TestRecordsCreator.CreateCategoryAsync(client, category);

            var getCategoriesResponse = await client.GetAsync("/api/product-categories");

            var categories = (await getCategoriesResponse.Content.ReadAsStringAsync())
                             .DeserializeJson <GetProductCategoriesResponse>().ProductCategories;

            Assert.Collection(categories,
                              x => { Assert.Equal("stocks", x.Id); },
                              x1 => { Assert.Equal("stocks.germany", x1.Id); });

            var deleteRequest = new DeleteProductCategoryRequest()
            {
                UserName = "******",
            };

            var deleteCategoryResponse =
                (await client.DeleteAsJsonAsync($"/api/product-categories/{notLeafCategory}", deleteRequest));
            var errorCode = (await deleteCategoryResponse.Content.ReadAsStringAsync())
                            .DeserializeJson <ErrorCodeResponse <ProductCategoriesErrorCodesContract> >().ErrorCode;

            Assert.Equal(ProductCategoriesErrorCodesContract.CannotDeleteNonLeafCategory, errorCode);

            getCategoriesResponse = await client.GetAsync("/api/product-categories");

            categories = (await getCategoriesResponse.Content.ReadAsStringAsync())
                         .DeserializeJson <GetProductCategoriesResponse>().ProductCategories;

            Assert.Collection(categories,
                              x => { Assert.Equal("stocks", x.Id); },
                              x1 => { Assert.Equal("stocks.germany", x1.Id); });
        }