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); } }
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); } }
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); } }