Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public MaterialSelectorItem(EducationMaterial educationMaterial, bool isSelected)
 {
     EducationMaterial = educationMaterial;
 }
Ejemplo n.º 5
0
 public void Insert(EducationMaterial educationMaterial) => _materailsProvider.Create(educationMaterial);