public async Task EnrolCourse_EnrolingCourse_CourseEnrolled() { var serviceList = new List <Service> { new Service { id = 1 } }; var serviceData = serviceList.AsQueryable(); var serviceMockSet = new Mock <DbSet <Service> >(); serviceMockSet.As <IDbAsyncEnumerable <Service> >() .Setup(m => m.GetAsyncEnumerator()) .Returns(new TestDbAsyncEnumerator <Service>(serviceData.GetEnumerator())); serviceMockSet.As <IQueryable <Service> >() .Setup(m => m.Provider) .Returns(new TestDbAsyncQueryProvider <Service>(serviceData.Provider)); serviceMockSet.As <IQueryable <Service> >().Setup(m => m.Expression).Returns(serviceData.Expression); var customerList = new List <Customer> { new Customer { id = 1 } }; var customerData = customerList.AsQueryable(); var customerMockSet = new Mock <DbSet <Customer> >(); customerMockSet.As <IDbAsyncEnumerable <Customer> >() .Setup(m => m.GetAsyncEnumerator()) .Returns(new TestDbAsyncEnumerator <Customer>(customerData.GetEnumerator())); customerMockSet.As <IQueryable <Customer> >() .Setup(m => m.Provider) .Returns(new TestDbAsyncQueryProvider <Customer>(customerData.Provider)); customerMockSet.As <IQueryable <Customer> >().Setup(m => m.Expression).Returns(customerData.Expression); var mockContext = new Mock <ExtremeSportDBEntities>(); mockContext.Setup(m => m.Service).Returns(serviceMockSet.Object); mockContext.Setup(m => m.Customer).Returns(customerMockSet.Object); var serviceLogic = new ServiceLogic { Context = mockContext.Object }; var b = await serviceLogic.EnrolCourse(1, 1); Assert.AreEqual(b, true); mockContext.Verify(m => m.SaveChangesAsync(), Times.Once()); }