コード例 #1
0
        public async Task CategoriesCreated_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var parent = await userCategoryCollection.GetRandomUserCategoryAsync();

            var expectedName = await parent.GenerateNewCategoryNameAsync();

            var expectedPath = new CategoryName(parent.Path, expectedName);
            var actualName   = string.Empty;
            var actualPath   = string.Empty;
            await userCategoryCollection.AddCategoriesCreatedEventHandlerAsync(UserCategoryCollection_CategoriesCreated);

            var category1 = await parent.AddNewCategoryAsync(authentication, expectedName);

            Assert.AreEqual(expectedName, actualName);
            Assert.AreEqual(expectedPath, actualPath);
            await userCategoryCollection.RemoveCategoriesCreatedEventHandlerAsync(UserCategoryCollection_CategoriesCreated);

            var category2 = parent.GenerateUserCategoryAsync(authentication);

            Assert.AreEqual(expectedName, actualName);
            Assert.AreEqual(expectedPath, actualPath);

            void UserCategoryCollection_CategoriesCreated(object sender, ItemsCreatedEventArgs <IUserCategory> e)
            {
                var category = e.Items.Single();

                actualName = category.Name;
                actualPath = category.Path;
            }
        }
コード例 #2
0
        public static async Task <IUserCategory> GenerateCategoryAsync(this IUserCategoryCollection userCategoryCollection, Authentication authentication)
        {
            var category = RandomUtility.Within(50) == true ? userCategoryCollection.Root : await userCategoryCollection.GetRandomUserCategoryAsync();

            return(await category.AddNewCategoryAsync(authentication, RandomUtility.NextIdentifier()));
        }