示例#1
0
        public async void CanDeleteAmenity()
        {
            Microsoft.EntityFrameworkCore.DbContextOptions <AsyncInnDbContext> options = new
                                                                                         DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase
                                                                                             ("CreateHotel").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext
                                                   (options))
            {
                //Arrange
                Amenities amenities = new Amenities();
                amenities.ID   = 1;
                amenities.Name = "Iron";

                //Act
                AmenityManagerService amenityService = new AmenityManagerService(context);
                await amenityService.CreateAmenity(amenities);

                await amenityService.DeleteAmenity(1);

                var result = await context.Amenities.FirstOrDefaultAsync(h => h.ID == amenities.ID);

                Assert.Null(result);
            }
        }
示例#2
0
        public async void CreateEmptyAmenityName()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("CreateEmptyAmenity").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                Amenities amenity = new Amenities();
                amenity.ID = 1;

                AmenityManagerService amenitiesService = new AmenityManagerService(context);
                await amenitiesService.CreateAmenity(amenity);

                Amenities result = await context.Amenities.FirstOrDefaultAsync(a => a.Name != null);

                Assert.NotEqual(amenity, result);
            }
        }