public async Task PutItem() { var connection = new SqliteConnection("DataSource=:memory:"); try { new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData()); using (var context = GetPropertyContext(connection)) { var uomRepository = new UomWriteRepository(context); var itemToPut = new Uom(3, "cubits", "The description"); await uomRepository.PutAsync(itemToPut); var uoms = await context.Uoms.OrderBy(u => u.Name).ToListAsync(); Assert.NotNull(uoms); Assert.AreEqual(UomTestData.GetUomsArray().Length, uoms.Count); Assert.True(UomEqual.Check(itemToPut, uoms[0])); } } finally { connection.Close(); } }
public async Task PostItem() { var connection = new SqliteConnection("DataSource=:memory:"); try { new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData()); using (var context = GetPropertyContext(connection)) { var uomRepository = new UomWriteRepository(context); var newUom = new Uom(0, "Cubits", "The description"); var postedItem = await uomRepository.PostAsync(newUom); Assert.NotNull(postedItem); Assert.True(UomEqual.Check(newUom, postedItem)); var uoms = await context.Uoms.ToListAsync(); Assert.NotNull(uoms); Assert.AreEqual(UomTestData.GetUomsArray().Length + 1, uoms.Count); var resultUoms = await context.Uoms.Where(u => u.Name == "Cubits").ToListAsync(); Assert.NotNull(resultUoms); Assert.AreEqual(1, resultUoms.Count); Assert.True(UomEqual.Check(postedItem, resultUoms[0])); } } finally { connection.Close(); } }
public void PostNullItem() { var connection = new SqliteConnection("DataSource=:memory:"); try { new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData()); using (var context = GetPropertyContext(connection)) { var uomRepository = new UomWriteRepository(context); Assert.ThrowsAsync <ArgumentNullException> ( async() => await uomRepository.PostAsync(null) ); } } finally { connection.Close(); } }
public async Task PostDuplicate() { var connection = new SqliteConnection("DataSource=:memory:"); try { new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData()); using (var context = GetPropertyContext(connection)) { var uomRepository = new UomWriteRepository(context); var newUom = new Uom(0, "mg/dL", "Errant duplicate"); var exception = Assert.ThrowsAsync <DbUpdateException>(async() => await uomRepository.PostAsync(newUom)); var message = exception.InnerException.Message; Assert.True(message.Contains("SQLite Error 19")); } } finally { connection.Close(); } }
public async Task DeleteItem() { var connection = new SqliteConnection("DataSource=:memory:"); try { new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData()); using (var context = GetPropertyContext(connection)) { var uomRepository = new UomWriteRepository(context); await uomRepository.DeleteAsync(2); var uoms = await context.Uoms.Where(u => u.Name == "in").ToListAsync(); Assert.AreEqual(0, uoms.Count); } } finally { connection.Close(); } }