public void Add_SuccessfulWithFullInformation() { //Using dataset to insert var dbCategory = new Mock <DbSet <Category> >(); // Moq.Language.Flow.IReturnsResult<DbSet<Category>> returnsResult = dbCategory.Setup(x => x.Add(It.IsAny<Category>())).Returns(category); Mock <ApplicationDbContext> mockDbContext = new Mock <ApplicationDbContext>( ); mockDbContext.Setup(x => x.Set <Category>()).Returns(dbCategory.Object); CategoryRespository categoryRespository = new CategoryRespository(mockDbContext.Object); var category = new Category() { Id = 1, DisplayOrder = 1, Name = "Category 1", Description = "Initialized db" }; categoryRespository.Add(category); // Both must return the same value mockDbContext.Verify(x => x.Set <Category>()); dbCategory.Verify(x => x.Add(It.Is <Category>(y => y == category))); }
public void AddCategory(Category category) { categoryRespository.Add(category); }