public async Task GetCategoriesAsync_WithSomeCategories_ShouldReturnAll() { //Arrange this.DbContext.Categories.Add(new Category() { Id = 1, Name = "First category" }); this.DbContext.Categories.Add(new Category() { Id = 2, Name = "Second category" }); this.DbContext.Categories.Add(new Category() { Id = 3, Name = "Third category" }); this.DbContext.SaveChanges(); var service = new AdminCategoryService(this.DbContext, this.Mapper, null); //Act var categories = await service.GetCategoriesAsync(); //Assert Assert.IsNotNull(categories); Assert.AreEqual(3, categories.Count()); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, categories.Select(c => c.Id).ToArray()); }
public async Task GetCategoryAsync_WithAFewCategories_ShouldReturnAll() { //Arrange this.dbContext.Categories.Add(new Category() { Id = 1, Name = "First Category", CategoryPicUrl = this.picLink }); this.dbContext.Categories.Add(new Category() { Id = 2, Name = "Second Category", CategoryPicUrl = this.picLink }); this.dbContext.Categories.Add(new Category() { Id = 3, Name = "Third Category", CategoryPicUrl = this.picLink }); this.dbContext.SaveChanges(); //Act var categories = await service.GetCategoriesAsync(); //Assert Assert.IsNotNull(categories); Assert.AreEqual(3, categories.Count()); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, categories.Select(c => c.Id).ToArray()); }
public async Task GetCategoriesAsync_WithZeroCategories_ShouldReturnNone() { //Arrange var service = new AdminCategoryService(this.DbContext, this.Mapper, null); //Act var categories = await service.GetCategoriesAsync(); //Assert Assert.IsNotNull(categories); Assert.AreEqual(0, categories.Count()); }