コード例 #1
0
        public async void CanRead()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>
                    ().UseInMemoryDatabase("ReadAmenities").Options;

            using (AsyncInnDbContext _table = new AsyncInnDbContext(options))
            {
                Amenities amenity = new Amenities();
                amenity.ID   = 1;
                amenity.Name = "Trampoline";

                AmenitiesManagementService service = new AmenitiesManagementService(_table);

                await service.AddAmenity(amenity);

                Assert.Equal(1, amenity.ID);
            }
        }
コード例 #2
0
        public async void CanCreate()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>
                    ().UseInMemoryDatabase("CreateAmenities").Options;

            using (AsyncInnDbContext _table = new AsyncInnDbContext(options))
            {
                Amenities amenity = new Amenities();
                amenity.ID   = 1;
                amenity.Name = "Trampoline";

                AmenitiesManagementService service = new AmenitiesManagementService(_table);

                await service.AddAmenity(amenity);

                var created = _table.Amenities.FirstOrDefault(a => a.ID == amenity.ID);

                Assert.Equal(amenity, created);
            }
        }
コード例 #3
0
        public async void CanDestroy()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>
                    ().UseInMemoryDatabase("DeleteAmenities").Options;

            using (AsyncInnDbContext _table = new AsyncInnDbContext(options))
            {
                Amenities amenity = new Amenities();
                amenity.ID   = 1;
                amenity.Name = "Trampoline";

                AmenitiesManagementService service = new AmenitiesManagementService(_table);

                await service.AddAmenity(amenity);

                await service.DeleteAmenity(amenity.ID);

                var deletedAmenity = await _table.Amenities.FirstOrDefaultAsync(da => da.ID == amenity.ID);

                Assert.Null(deletedAmenity);
            }
        }