public EventsController Arrange_Event_Controller() { var testEvent1 = new Event { Id = 1 }; var testEvent2 = new Event { Id = 2 }; var testUser = new SchedulerUser { Id = "99fd20b8-7194-31e1-945b-e6736c732499", Events = new List<Event> { testEvent1, testEvent2 } }; var users = new List<SchedulerUser> { testUser }.AsQueryable(); var service = new Service(); var mockSet = new Mock<DbSet<SchedulerUser>>(); mockSet.As<IQueryable<SchedulerUser>>().Setup(m => m.Provider).Returns(users.Provider); mockSet.As<IQueryable<SchedulerUser>>().Setup(m => m.Expression).Returns(users.Expression); mockSet.As<IQueryable<SchedulerUser>>().Setup(m => m.ElementType).Returns(users.ElementType); mockSet.As<IQueryable<SchedulerUser>>().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator); var context = new Mock<SchedulerDbContext>(); context.Setup(c => c.Users).Returns(mockSet.Object); var controller = new EventsController(context.Object, service) { ControllerContext = MockContext() }; return controller; }
public EventsController(SchedulerDbContext context, Service service) { _db = context; _service = service; }