public async Task SendTripRequestShouldAddEntityToDb() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "SendTripRequestDb").Options; var dbContext = new ApplicationDbContext(options); var tripReqeustRepository = new EfDeletableEntityRepository <TripRequest>(dbContext); var tripRepository = new EfDeletableEntityRepository <Trip>(dbContext); var destinationRepository = new EfRepository <Destination>(dbContext); var usersRepository = new EfDeletableEntityRepository <ApplicationUser>(dbContext); var userNotificationsRepository = new EfRepository <UserNotification>(dbContext); var notificationService = new NotificationService(usersRepository, userNotificationsRepository); var unitOfWork = new UnitOfWork(dbContext); var mockClientProxy = new Mock <IClientProxy>(); var mockClients = new Mock <IHubClients>(); mockClients.Setup(clients => clients.All).Returns(mockClientProxy.Object); mockClients.Setup(c => c.User("awe22")).Returns(mockClientProxy.Object); var hub = new Mock <IHubContext <NotificationHub> >(); hub.Setup(x => x.Clients).Returns(() => mockClients.Object); var tripService = new TripsService(unitOfWork); var service = new TripRequestsService(hub.Object, unitOfWork, notificationService); await dbContext.Trips.AddAsync(new Trip { Id = "123", FromDestinationName = "sofia", ToDestinationName = "Silistra", }); var sender = new ApplicationUser { Id = "awe12", UserName = "******", }; var owner = new ApplicationUser { Id = "awe22", UserName = "******", }; await dbContext.Users.AddRangeAsync(sender, owner); await dbContext.SaveChangesAsync(); using (dbContext) { var trip = await dbContext.Trips.FirstOrDefaultAsync(x => x.Id == "123"); var actual = await service.SendTripRequest(sender.UserName, trip, owner.Id); Assert.True(actual); } }
public async Task InitializeAsync() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; this.dbContext = new ApplicationDbContext(options); var unitOfWork = new UnitOfWork(this.dbContext); var mockHub = new Mock <IHubContext <NotificationHub> >().Object; var mockService = new Mock <INotificationService>().Object; this.tripRequestsService = new TripRequestsService(mockHub, unitOfWork, mockService); }