IEducationMaterialService GetEducationMaterialService() { var mockContext = new Mock <IUnitOfWork>(); var expectedEducationMaterial = new EducationMaterial() { EducationMaterialId = 1, Name = "testName", Content = "testContent" }; var mockDbSet = new Mock <IEducationMaterialRepository>(); mockDbSet.Setup(z => z.Find(It.IsAny <Func <EducationMaterial, bool> >(), It.IsAny <int>(), It.IsAny <int>())).Returns(new List <EducationMaterial>() { expectedEducationMaterial }); mockContext.Setup(context => context.EduMaterials).Returns(mockDbSet.Object); IEducationMaterialService educationMaterialService = new EducationMaterialService(mockContext.Object); return(educationMaterialService); }
public void Delete_InputId_CalledFindAndRemoveMethodsOfDBSetWithCorrectArg() { DbContextOptions opt = new DbContextOptionsBuilder <EduInfoSystemContext>().Options; var mockContext = new Mock <EduInfoSystemContext>(opt); var mockDbSet = new Mock <DbSet <EducationMaterial> >(); mockContext.Setup(context => context.Set <EducationMaterial>()).Returns(mockDbSet.Object); var repository = new TestEducationMaterialRepository(mockContext.Object); EducationMaterial expectedEducationMaterial = new EducationMaterial() { EducationMaterialId = 1 }; mockDbSet.Setup(mock => mock.Find(expectedEducationMaterial.EducationMaterialId)).Returns(expectedEducationMaterial); repository.Delete(expectedEducationMaterial.EducationMaterialId); mockDbSet.Verify(dbSet => dbSet.Find(expectedEducationMaterial.EducationMaterialId), Times.Once()); mockDbSet.Verify(dbSet => dbSet.Remove(expectedEducationMaterial), Times.Once()); }
public void Get_InputId_CalledFindMethodOfDBSetWithCorrectId() { DbContextOptions opt = new DbContextOptionsBuilder <EduInfoSystemContext>().Options; var mockContext = new Mock <EduInfoSystemContext>(opt); var mockDbSet = new Mock <DbSet <EducationMaterial> >(); mockContext.Setup(context => context.Set <EducationMaterial>()).Returns(mockDbSet.Object); EducationMaterial expectedEducationMaterial = new EducationMaterial() { EducationMaterialId = 1 }; mockDbSet.Setup(mock => mock.Find(expectedEducationMaterial.EducationMaterialId)).Returns(expectedEducationMaterial); var repository = new TestEducationMaterialRepository(mockContext.Object); var actualEducationMaterial = repository.Get(expectedEducationMaterial.EducationMaterialId); mockDbSet.Verify(dbSet => dbSet.Find(expectedEducationMaterial.EducationMaterialId), Times.Once()); Assert.Equal(expectedEducationMaterial, actualEducationMaterial); }
public MaterialSelectorItem(EducationMaterial educationMaterial, bool isSelected) { EducationMaterial = educationMaterial; }
public void Insert(EducationMaterial educationMaterial) => _materailsProvider.Create(educationMaterial);