public async Task ProductCategories_CannotDeleteCategoryWithAttachedProducts_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 category = "stocks";

            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", category);

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

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

            Assert.Single(categories);

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

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

            Assert.Equal(ProductCategoriesErrorCodesContract.CannotDeleteCategoryWithAttachedProducts, errorCode);

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

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

            Assert.Single(categories);
        }
        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); });
        }