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

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

            var reservationId = Guid.NewGuid().ToString();

            await reservationRepository.AddAsync(new Reservation
            {
                Id   = reservationId,
                Room = new Room
                {
                    Number  = "100",
                    HotelId = 1,
                },
                Creator = new ApplicationUser
                {
                    Id        = Guid.NewGuid().ToString(),
                    IsDeleted = true,
                },
            });

            await reservationRepository.AddAsync(new Reservation
            {
                Id   = Guid.NewGuid().ToString(),
                Room = new Room
                {
                    Number  = "300",
                    HotelId = 2,
                },
                Creator = new ApplicationUser
                {
                    Id        = Guid.NewGuid().ToString(),
                    IsDeleted = true,
                },
            });

            await reservationRepository.SaveChangesAsync();

            var reservationsService = new ReservationsService(reservationRepository);

            AutoMapperConfig.RegisterMappings(typeof(MyTestReservation).Assembly);
            var reservation = await reservationsService.GetDeletedByIdAsync <MyTestReservation>(reservationId);

            Assert.Equal("100", reservation.RoomNumber);
        }