示例#1
0
        public async Task TestGetAllReservationsFromHotel()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options));

            await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), Room = new Room {
                                                                       HotelId = 1
                                                                   } });

            await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), Room = new Room {
                                                                       HotelId = 1
                                                                   } });

            await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), Room = new Room {
                                                                       HotelId = 2
                                                                   } });

            await reservationRepository.SaveChangesAsync();

            var reservationsService = new ReservationsService(reservationRepository);

            AutoMapperConfig.RegisterMappings(typeof(MyTestReservation).Assembly);
            var reservations = reservationsService.GetAll <MyTestReservation>(1);

            Assert.Equal(2, reservations.Count());
        }
示例#2
0
        public async Task GetAll_ShouldReturnAllReservations()
        {
            // Arange
            List <Reservation> reservationsData = new()
            {
                Reservations.Reservation1User3Room1NoClient,
                Reservations.Reservation2User4Room2NoClient,
                Reservations.Reservation3User4Room2NoClient
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(reservationsData);

            SettingService settingService = new(context);

            var service = new ReservationsService(context, settingService);

            // Act
            var allReservations = await service.GetAll <ReservationViewModel>();

            // Assert
            Assert.AreEqual(context.Reservations.Count(), allReservations.Count());
        }
示例#3
0
        public IActionResult Index()
        {
            var model = service.GetAll();

            return(View(model));
        }