Exemplo n.º 1
0
        public async Task AddBookingToPropertyShouldThrow()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db    = new ApplicationDbContext(options);
            var hotel = await db.Hotels.AddAsync(new Hotel { HotelId = "123", BookingsCount = 0 });

            await db.SaveChangesAsync();

            var service = new PropertiesService(db);

            var result = await service.AddBookingToProperty(hotel.Entity.HotelId);

            await Assert.ThrowsAnyAsync <Exception>(async() => await service.AddBookingToProperty("random id"));
        }
Exemplo n.º 2
0
        public async Task AddBookingToPropertyShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db    = new ApplicationDbContext(options);
            var hotel = await db.Hotels.AddAsync(new Hotel { HotelId = "123", BookingsCount = 0 });

            await db.SaveChangesAsync();

            var service = new PropertiesService(db);

            var result = await service.AddBookingToProperty(hotel.Entity.HotelId);

            Assert.Equal(1, result);
        }