예제 #1
0
 public void GetAllCategories()
 {
     using (var dbContext = new CategoricalContext(GetContextOptions()))
     {
         var categoryService = new CategoryService(dbContext);
         categoryService.Create(new Category {
             Title = "Test"
         });
         Assert.Single(categoryService.GetAll());
     }
 }
예제 #2
0
 public void DeleteCategory()
 {
     using (var dbContext = new CategoricalContext(GetContextOptions()))
     {
         var      categoryService = new CategoryService(dbContext);
         Category category        = new Category {
             Title = "Test"
         };
         categoryService.Create(category);
         categoryService.Delete(category);
         Assert.Empty(categoryService.GetAll());
     }
 }
예제 #3
0
        public void GetById()
        {
            using (var dbContext = new CategoricalContext(GetContextOptions()))
            {
                var      categoryService = new CategoryService(dbContext);
                Category category        = new Category {
                    Title = "Test"
                };
                categoryService.Create(category);

                Assert.Equal(category.Id, categoryService.GetById(category.Id).Id);
                Assert.Equal("Test", categoryService.GetById(category.Id).Title);
            }
        }
예제 #4
0
        public void CreateNewCategoryWithNewId()
        {
            using (var dbContext = new CategoricalContext(GetContextOptions()))
            {
                var categoryService = new CategoryService(dbContext);
                var category        = new Category {
                    Title = "A test category"
                };
                categoryService.Create(category);

                Assert.Single(dbContext.Categories.ToList());
                Assert.Equal(1, category.Id);
            }
        }
예제 #5
0
        public void UpdateCategory()
        {
            using (var dbContext = new CategoricalContext(GetContextOptions()))
            {
                var      categoryService = new CategoryService(dbContext);
                Category category        = new Category {
                    Title = "Test"
                };
                categoryService.Create(category);
                category.Title = "Changed!";
                // categoryService.Update(category);

                Assert.Equal("Changed!", categoryService.GetById(category.Id).Title);
            }
        }
예제 #6
0
 public CategoryService(CategoricalContext dbContext)
 {
     this.dbContext = dbContext;
 }