public void GetAllCategories() { using (var dbContext = new CategoricalContext(GetContextOptions())) { var categoryService = new CategoryService(dbContext); categoryService.Create(new Category { Title = "Test" }); Assert.Single(categoryService.GetAll()); } }
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()); } }
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); } }
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); } }
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); } }
public CategoryService(CategoricalContext dbContext) { this.dbContext = dbContext; }