public void StoreCategoryLinkThrowsExceptionWithInvalidCategoryNameTest(string categoryName)
        {
            var change = new CategoryLinkChange();

            var sut = new CategoryLinkStore(Config.Storage);

            Func <Task> action = async() => await sut
                                 .StoreCategoryLink(CategoryGroup.Gender, categoryName, change, CancellationToken.None)
                                 .ConfigureAwait(false);

            action.Should().Throw <ArgumentException>();
        }
        private async Task UpdateCategories(
            Profile profile,
            ProfileChangeResult changes,
            CancellationToken cancellationToken)
        {
            var cacheItemsToRemove = new List <ProfileFilter>();

            // Get the current categories
            var categories =
                (await _categoryStore.GetAllCategories(cancellationToken).ConfigureAwait(false)).FastToList();

            var categoryTasks = new List <Task>();

            // Write all category link changes
            foreach (var categoryChange in changes.CategoryChanges)
            {
                // Get the category
                var category = categories.FirstOrDefault(
                    x => x.Group == categoryChange.CategoryGroup && x.Name.Equals(
                        categoryChange.CategoryName,
                        StringComparison.OrdinalIgnoreCase));

                if (category == null)
                {
                    // We haven't seen this category before
                    category = new Category
                    {
                        Group     = categoryChange.CategoryGroup,
                        LinkCount = 0,
                        Name      = categoryChange.CategoryName,
                        Reviewed  = false,
                        Visible   = false
                    };

                    // Trigger a notification that a new category is being added to the system
                    var newCategoryTriggerTask = _eventTrigger.NewCategory(category, cancellationToken);

                    categoryTasks.Add(newCategoryTriggerTask);

                    categories.Add(category);
                }

                if (categoryChange.ChangeType == CategoryLinkChangeType.Add)
                {
                    // This is a new link between the profile and the category
                    category.LinkCount++;
                }
                else
                {
                    // We are removing the link between the profile and the category
                    category.LinkCount--;
                }

                var change = new CategoryLinkChange
                {
                    ChangeType = categoryChange.ChangeType,
                    ProfileId  = profile.Id
                };

                // Store the link update
                var categoryLinkTask = _linkStore.StoreCategoryLink(
                    category.Group,
                    category.Name,
                    change,
                    cancellationToken);

                categoryTasks.Add(categoryLinkTask);

                var filter = new ProfileFilter
                {
                    CategoryGroup = category.Group,
                    CategoryName  = category.Name
                };

                cacheItemsToRemove.Add(filter);

                // Update the category data
                var categoryTask = _categoryStore.StoreCategory(category, cancellationToken);

                categoryTasks.Add(categoryTask);
            }

            // Run all the category task changes together
            await Task.WhenAll(categoryTasks).ConfigureAwait(false);

            UpdateCacheStore(categories, cacheItemsToRemove);
        }