public void Remove_Does_Nothing_If_Category_With_Given_Id_Is_Not_Found() { var contextMock = new Mock <ISupportAppContext>(); var categorySetMock = new Mock <DbSet <Category> >(); contextMock.Setup(c => c.Set <Category>()) .Returns(categorySetMock.Object); var sut = new CategoryModifier(contextMock.Object); contextMock.Setup(c => c.FindById <Category>(22)) .Returns((Category)null); //act sut.RemoveCategory(22); categorySetMock.Verify(c => c.Remove(It.IsAny <Category>()), Times.Never); contextMock.Verify(c => c.SaveChanges(), Times.Never); }
public void Remove_Removes_Category_From_Database_By_Id() { var fixture = new Fixture(); var contextMock = new Mock <ISupportAppContext>(); var categorySetMock = new Mock <DbSet <Category> >(); contextMock.Setup(c => c.Set <Category>()) .Returns(categorySetMock.Object); var sut = new CategoryModifier(contextMock.Object); var category = fixture.Create <Category>(); contextMock.Setup(c => c.FindById <Category>(category.Id)) .Returns(category); //act sut.RemoveCategory(category.Id); categorySetMock.Verify(c => c.Remove(category)); contextMock.Verify(c => c.SaveChanges()); }
public void Add_Inserts_New_Category_To_DataBase() { var fixture = new Fixture(); var contextMock = new Mock <ISupportAppContext>(); var categorySetMock = new Mock <DbSet <Category> >(); contextMock.Setup(c => c.Set <Category>()) .Returns(categorySetMock.Object); var sut = new CategoryModifier(contextMock.Object); var newCategory = fixture.Create <Category>(); //act var result = sut.Add(newCategory); //assert result.Should().Be(newCategory); categorySetMock.Verify(c => c.Add(newCategory), Times.Once); contextMock.Verify(c => c.SaveChanges()); }
public async Task CategoryServiceModifierTest() { await _categories.DeleteAllAsync(); var cat = new Category() { Name = "Category 1", ImageId = (int)ImageId.Fio }; await _categories.InsertAsync(false, cat); var modifier = new CategoryModifier() { IncludeImage = true }; var category = (await _categories.GetAllAsync(modifier)).Single(); Assert.IsNotNull(category.Image); Assert.AreEqual((int)ImageId.Fio, category.Image.Id); cat = new Category() { Name = "Category 2", Image = (await _images.GetAsync((int)ImageId.Fio)) }; await _categories.InsertAsync(false, cat); var filter = new CategoryFilter() { Name = "Category 2" }; category = (await _categories.GetAsync(filter, modifier)).Single(); Assert.IsNotNull(category.Image); Assert.AreEqual((int)ImageId.Fio, category.Image.Id); await _categories.DeleteAllAsync(); Assert.AreEqual(0, (await _categories.GetAllAsync()).Count); }
public async Task CategoryModifierTest() { await categories.DeleteAllAsync(); var cat1 = new Category() { Name = "Category 1", ImageId = (int)ImageId.Fio }; await categories.InsertAsync(cat1); var modifier = new CategoryModifier() { IncludeImage = true }; var category = (await categories.GetAllAsync(modifier)).Single(); Assert.IsNotNull(category.Image); Assert.AreEqual((int)ImageId.Fio, category.Image.Id); await categories.DeleteAllAsync(); Assert.AreEqual(0, (await categories.GetAllAsync()).Count); }