コード例 #1
0
        public void DeleteByIdTest()
        {
            var repository = CategoryRepository.Create();
            var category   = this.CreateArticle(repository, SeedCategory.Create());
            var service    = this.GetArticlesService(repository);
            var result     = service.DeleteById(category.Id);

            Assert.True(category.IsDeleted);
        }
コード例 #2
0
        public void GetAllCategoriesSingleResultTest()
        {
            var repository = CategoryRepository.Create();
            var category   = this.CreateArticle(repository, SeedCategory.Create());
            var service    = this.GetArticlesService(repository);
            var result     = service.GetAllCategories <CategoryDumyModel>();

            Assert.Single(result);
        }
コード例 #3
0
        public void HardDeleteByIdTest()
        {
            var repository = CategoryRepository.Create();
            var category   = this.CreateArticle(repository, SeedCategory.Create());
            var service    = this.GetArticlesService(repository);

            service.HardDeleteById(category.Id).GetAwaiter();

            Assert.Equal(0, repository.AllWithDeleted().Count());
        }
コード例 #4
0
        public void GetAllCategoriesWithAnySubCategoriesTest()
        {
            var repository     = CategoryRepository.Create();
            var category       = this.CreateArticle(repository, SeedCategory.Create());
            var secondCategory = this.CreateArticle(repository, SeedCategory.CreateSecond());
            var thirdCategory  = this.CreateArticle(repository, SeedCategory.CreateThird());
            var service        = this.GetArticlesService(repository);
            var result         = service.GetAllCategoriesWithAnySubCategories <CategoryDumyModel>();

            Assert.Single(result);
        }
コード例 #5
0
        public void GetCountOfDeletedCategories()
        {
            var repository     = CategoryRepository.Create();
            var category       = this.CreateArticle(repository, SeedCategory.Create());
            var secondCategory = this.CreateArticle(repository, SeedCategory.CreateSecond());
            var thirdCategory  = this.CreateArticle(repository, SeedCategory.CreateThird());
            var service        = this.GetArticlesService(repository);
            var result         = service.GetCountOfDeletedCategories();

            Assert.Equal(1, result);
        }
コード例 #6
0
        public void GetCategoryByIdTest()
        {
            var repository     = CategoryRepository.Create();
            var category       = this.CreateArticle(repository, SeedCategory.Create());
            var secondCategory = this.CreateArticle(repository, SeedCategory.CreateSecond());
            var thirdCategory  = this.CreateArticle(repository, SeedCategory.CreateThird());
            var service        = this.GetArticlesService(repository);
            var result         = service.GetCategoryById <CategoryDumyModel>(1).GetAwaiter().GetResult();

            Assert.Equal(category.Id, result.Id);
        }
コード例 #7
0
        public void GetCategoryByIdFakeTest()
        {
            var repository     = CategoryRepository.Create();
            var category       = this.CreateArticle(repository, SeedCategory.Create());
            var secondCategory = this.CreateArticle(repository, SeedCategory.CreateSecond());
            var thirdCategory  = this.CreateArticle(repository, SeedCategory.CreateThird());
            var service        = this.GetArticlesService(repository);
            var result         = service.GetCategoryById <CategoryDumyModel>(int.MaxValue).GetAwaiter().GetResult();

            Assert.Null(result);
        }
コード例 #8
0
        public void GetCategoryModelByFakeIdTest()
        {
            var repository     = CategoryRepository.Create();
            var category       = this.CreateArticle(repository, SeedCategory.Create());
            var secondCategory = this.CreateArticle(repository, SeedCategory.CreateSecond());
            var thirdCategory  = this.CreateArticle(repository, SeedCategory.CreateThird());
            var service        = this.GetArticlesService(repository);
            var result         = service.GetCategoryModelById(55).GetAwaiter().GetResult();

            Assert.Null(result);
        }
コード例 #9
0
        public void CategoryExistsByNameTrueTest()
        {
            var repository     = CategoryRepository.Create();
            var category       = this.CreateArticle(repository, SeedCategory.Create());
            var secondCategory = this.CreateArticle(repository, SeedCategory.CreateSecond());
            var thirdCategory  = this.CreateArticle(repository, SeedCategory.CreateThird());
            var service        = this.GetArticlesService(repository);
            var result         = service.CategoryExistsByName(category.Title).GetAwaiter().GetResult();

            Assert.True(result);
        }
コード例 #10
0
        public void CategoryExistsByNameFalseTest()
        {
            var name           = "someName";
            var repository     = CategoryRepository.Create();
            var category       = this.CreateArticle(repository, SeedCategory.Create());
            var secondCategory = this.CreateArticle(repository, SeedCategory.CreateSecond());
            var thirdCategory  = this.CreateArticle(repository, SeedCategory.CreateThird());
            var service        = this.GetArticlesService(repository);
            var result         = service.CategoryExistsByName(name).GetAwaiter().GetResult();

            Assert.False(result);
        }
コード例 #11
0
        public void CreateCategoryAsyncTest()
        {
            var repository = CategoryRepository.Create();
            var category   = this.CreateArticle(repository, SeedCategory.Create());
            var service    = this.GetArticlesService(repository);

            service.CreateCategoryAsync(new CategoryCreateInputModel {
                Title = "New category"
            }).GetAwaiter();

            Assert.Equal(2, repository.All().Count());
        }
コード例 #12
0
        public void UpdateCategoryTest()
        {
            string newName    = "New name";
            var    repository = CategoryRepository.Create();
            var    category   = this.CreateArticle(repository, SeedCategory.Create());
            var    service    = this.GetArticlesService(repository);

            category.Title = newName;

            var result = service.UpdateCategory(category);

            Assert.Equal(newName, category.Title);
        }
コード例 #13
0
        public void GetCategoryByNameOneResultTest()
        {
            string categoryName = "One";

            var repository     = CategoryRepository.Create();
            var category       = this.CreateArticle(repository, SeedCategory.Create());
            var secondCategory = this.CreateArticle(repository, SeedCategory.CreateSecond());
            var thirdCategory  = this.CreateArticle(repository, SeedCategory.CreateThird());
            var service        = this.GetArticlesService(repository);
            var result         = service.GetCategoryByName <CategoryDumyModel>(categoryName).GetAwaiter().GetResult();

            Assert.Equal(category.Title, result.Title);
        }
コード例 #14
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <BrokenAPIContext>();
                    context.Database.Migrate();
                    SeedCategory.Initialize(services);
                    SeedError.Initialize(services);
                }
                catch
                {
                }
            }

            host.Run();
        }
コード例 #15
0
 public int Save(SeedCategory seedCategory)
 {
     _context.SeedCategories.Add(seedCategory);
     return(_context.SaveChanges());
 }