Ejemplo n.º 1
0
        public void CallContextCoursesOnce()
        {
            // Arrange
            var data = this.GetData();

            var mockedSet = new Mock <DbSet <Course> >();

            mockedSet.As <IQueryable <Course> >().Setup(m => m.Provider).Returns(data.Provider);
            mockedSet.As <IQueryable <Course> >().Setup(m => m.Expression).Returns(data.Expression);
            mockedSet.As <IQueryable <Course> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockedSet.As <IQueryable <Course> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var contextMock = new Mock <ApplicationDbContext>();

            contextMock.Setup(c => c.Courses).Returns(mockedSet.Object);

            var service = new AssignmentService(contextMock.Object);

            // Act
            service.GetAllCourses();

            // Assert
            contextMock.Verify(s => s.Courses, Times.Once);
        }