예제 #1
0
        public void GetStudentsByCourseName_GivenValidCourseName_ShouldReturnStudents()
        {
            //Arrange
            var data = FakeData.FakeStudentData;

            var mockSet     = GetQueryableMockDbSet(data.ToArray());
            var mockContext = new Mock <IDbContext>();

            mockContext.Setup(con => con.Students).Returns(mockSet.Object);
            var classUnderTest = new MockEFService(mockContext.Object);

            //Act

            var resultMicro = classUnderTest.GetStudentsByCourseName("Microeconomics");
            var resultChem  = classUnderTest.GetStudentsByCourseName("Chemistry");
            var resultComp  = classUnderTest.GetStudentsByCourseName("Composition");

            //Assert

            resultMicro.Count().ShouldBe(2);
            resultMicro.All(s => s.Enrollments.Any(e => e.Course.Title == "Microeconomics")).ShouldBeTrue();
            resultChem.Count().ShouldBe(3);
            resultChem.All(s => s.Enrollments.Any(e => e.Course.Title == "Chemistry")).ShouldBeTrue();
            resultComp.Count().ShouldBe(1);
            resultComp.All(s => s.Enrollments.Any(e => e.Course.Title == "Composition")).ShouldBeTrue();
        }
예제 #2
0
        public void GetStudentsByCourseName_GivenValidCourseName_ShouldReturnNoStudents()
        {
            //Arrange
            var data = FakeData.FakeStudentData;

            var mockSet     = GetQueryableMockDbSet(data.ToArray());
            var mockContext = new Mock <IDbContext>();

            mockContext.Setup(con => con.Students).Returns(mockSet.Object);
            var classUnderTest = new MockEFService(mockContext.Object);

            //Act

            var result = classUnderTest.GetStudentsByCourseName("Invalid");

            //Assert

            result.ShouldBeEmpty();
        }