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 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 PutUomGoodClaimsList() { var connection = new SqliteConnection("DataSource=devicedb;Mode=Memory;Cache=Shared"); try { new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData()); var testWriteClient = GetTestWriteClient(); var httpMessage = GetRequestWithToken(HttpMethod.Put, $"{EndpointBase}/lrp/uoms/2", GoodClaimsList); var uomToPut = new Uom(2, "NewName", "New Description"); httpMessage.Content = GetWriteContent(uomToPut); var response = await testWriteClient.SendAsync(httpMessage); Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); using (var context = GetPropertyContext(connection)) { var uoms = await context.Uoms.Where(u => u.Id == 2).ToListAsync(); Assert.NotNull(uoms); Assert.AreEqual(1, uoms.Count); Assert.True(UomEqual.Check(uomToPut, uoms[0])); } } finally { connection.Close(); } }
public async Task DeserializeSucceeds() { var expectedUom = new Uom().WithId(1).WithName("Uom").WithDescription("The Uom"); var uomJson = JsonConvert.SerializeObject(expectedUom); var httpContent = new StringContent(uomJson); var deserializer = new JsonContentDeserializer(); var actualUom = await deserializer.DeserializeAsync <Uom>(httpContent); Assert.True(UomEqual.Check(expectedUom, actualUom)); }
public async Task SerializeSucceeds() { var expectedItem = new Uom(1, "TheUom", "TheDescription"); var message = new HttpRequestMessage(); var serializer = new JsonContentSerializer(); serializer.Serialize <Uom>(message, expectedItem); var deserializer = new JsonContentDeserializer(); var actualItem = await deserializer.DeserializeAsync <Uom>(message.Content); Assert.True(UomEqual.Check(expectedItem, actualItem)); }
public async Task GetSingleUom() { var connection = new SqliteConnection("DataSource=:memory:"); try { var testData = UomTestData.GetUomsArray(); new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData()); using (var context = GetPropertyContext(connection)) { var uomRepository = new UomReadRepository(context); var uom = await uomRepository.GetAsync(1); Assert.NotNull(uom); Assert.True(UomEqual.Check(testData[0], uom)); } } finally { connection.Close(); } }
public async Task GetSingleUomGoodClaimsList() { var connection = new SqliteConnection("DataSource=devicedb;Mode=Memory;Cache=Shared"); try { var testData = UomTestData.GetUomsArray(); new DbInitializer().Initialize(connection, GetPropertyContext, UomTestData.GetInitialData()); var testReadClient = GetTestReadClient(); var httpMessage = GetRequestWithToken(HttpMethod.Get, $"{EndpointBase}/lrp/uoms/2", GoodClaimsList); var response = await testReadClient.SendAsync(httpMessage); Assert.True(response.IsSuccessStatusCode); var jsonString = await response.Content.ReadAsStringAsync(); var uomResult = JsonConvert.DeserializeObject <Uom>(jsonString); Assert.True(UomEqual.Check(testData[1], uomResult)); } finally { connection.Close(); } }