public void CreateAsync_ReturnsCorrectReservationId() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; dbContext.Users.Add(user); dbContext.SaveChanges(); CreateReservationServiceModel reservation = new CreateReservationServiceModel { VehicleMake = "BMW", VehicleModel = "M5", LicenseNumber = "СА 1234 КР", PhoneNumber = "0897482124", ReservationDateTime = new DateTime(2020, 3, 21, 10, 30, 10), Username = user.UserName, }; var reservationsService = new ReservationsService(dbContext); var result = reservationsService.CreateAsync(reservation); var reservationObj = dbContext.Reservations.FirstOrDefaultAsync(); Assert.Equal(reservationObj.Result.Id, result.Result); } }
public async Task TestCreateReservation() { var reservations = new List <Reservation>(); var mockReservationRepo = new Mock <IDeletableEntityRepository <Reservation> >(); mockReservationRepo.Setup(x => x.All()).Returns(reservations.AsQueryable()); mockReservationRepo.Setup(x => x.AddAsync(It.IsAny <Reservation>())).Callback( (Reservation reservation) => reservations.Add(reservation)); var service = new ReservationsService(mockReservationRepo.Object); await service.CreateAsync("0888989844", Guid.NewGuid().ToString(), 1, DateTime.UtcNow, DateTime.UtcNow, 2, 0, "Petar", "Stoqnov", null, 10.00M, true, false, false); Assert.Single(reservations); }