Exemplo n.º 1
0
        /// <summary>
        /// Override of <see cref="LoadAllAsync"/> to use <see cref="ReservationRepository"/> instead for including navigation properties
        /// </summary>
        /// <returns></returns>
        protected override async Task LoadAllAsync()
        {
            // Create factory, and get the instance
            RepositoryFactory <ReservationRepository, Reservation> reservationFactory = RepositoryFactory <ReservationRepository, Reservation> .GetInstance();

            // Create repository with the factory
            ReservationRepository reservationRepository = reservationFactory.Create();
            // Get all reservations
            IEnumerable <Reservation> reservations = await reservationRepository.GetAllAsync();

            // Replace collection
            Items.ReplaceWith(reservations);


            // Create factory, and get the instance
            RepositoryFactory <RepositoryBase <Court>, Court> courtFactory = RepositoryFactory <RepositoryBase <Court>, Court> .GetInstance();

            // Create repository with the factory
            RepositoryBase <Court> courtRepository = courtFactory.Create();
            // Get all reservations
            IEnumerable <Court> courts = await courtRepository.GetAllAsync();

            // Replace collection
            Courts.ReplaceWith(courts);


            // Create factory, and get the instance
            RepositoryFactory <RepositoryBase <Member>, Member> memberFactory = RepositoryFactory <RepositoryBase <Member>, Member> .GetInstance();

            // Create repository with the factory
            RepositoryBase <Member> memberRepository = memberFactory.Create();
            // Get all reservations
            IEnumerable <Member> members = await memberRepository.GetAllAsync();

            // Replace collection
            Members.ReplaceWith(members);
        }
 public async Task <IEnumerable <Reservation> > Handle(GetReservationsQuery request, CancellationToken cancellationToken)
 {
     return(await _repository.GetAllAsync());
 }
Exemplo n.º 3
0
        public override async Task GetAllWorksAsync()
        {
            List <Reservation> reservationList  = new List <Reservation>();
            Reservation        reservationSaved = null;
            Customer           customerSaved    = null;
            Room roomSaved = null;

            var options = new DbContextOptionsBuilder <Project15Context>()
                          .UseInMemoryDatabase("db_reservation_test_getall").Options;

            using (var db = new Project15Context(options));

            using (var db = new Project15Context(options))
            {
                var repo         = new ReservationRepository(db);
                var customerRepo = new CustomerRepository(db);
                var roomRepo     = new RoomRepository(db);

                //Create customer
                Customer customer = new Customer {
                    Name = "Axel", Address1 = "111 Address"
                };
                customer = await customerRepo.CreateAsync(customer);

                await customerRepo.SaveChangesAsync();

                // Create room
                Room room = new Room {
                    Beds = 1, Cost = 50, RoomType = "Standard"
                };
                room = await roomRepo.CreateAsync(room);

                await roomRepo.SaveChangesAsync();

                for (int i = 0; i < 5; i++)
                {
                    Reservation reservation = new Reservation
                    {
                        CustomerId = customer.Id,
                        RoomId     = room.Id,
                    };
                    reservationSaved = await repo.CreateAsync(reservation);

                    await repo.SaveChangesAsync();

                    reservationList.Add(reservationSaved);
                }

                roomSaved     = room;
                customerSaved = customer;
            }
            using (var db = new Project15Context(options))
            {
                var repo = new ReservationRepository(db);
                List <Reservation> list = (List <Reservation>) await repo.GetAllAsync();

                Assert.Equal(reservationList.Count, list.Count);

                for (int i = 0; i < 5; i++)
                {
                    Assert.Equal(reservationList[i].CustomerId, list[i].CustomerId);
                    Assert.Equal(reservationList[i].RoomId, list[i].RoomId);
                    Assert.NotEqual(0, list[i].Id);
                }
            }
        }