public async Task GetById_WithDeviceAvailable_ReturnsDevice() { CreateDeviceRequest deviceRequest = new CreateDeviceRequest { Name = "integrationTestName1", Location = "integrationTestLocation1" }; //Arrange var insertSqlString = $"Insert into Devices (Name, Location) values('{deviceRequest.Name}', '{deviceRequest.Location}')"; ExecuteNonQuery(insertSqlString); var selectSqlString = $"Select * from Devices WHERE Name = '{deviceRequest.Name}'"; var device = ExecuteDevicesQuery(selectSqlString); Assert.NotNull(device); string requestUri = $"Devices/{device.Device_id}"; // Act var response = await HttpClient.GetAsync(requestUri); var receivedDevice = await response.Content.ReadAsAsync <Device>(); //Assert response.StatusCode.Should().Be(HttpStatusCode.OK); Assert.True(DevicesComparer.CompareDeviceWithDeviceRequest(receivedDevice, deviceRequest), "The requested device was not found in the" + " device retrieved by the GetById."); //Clean Up var cleanUpSqlString = $"DELETE From Devices WHERE Name = '{deviceRequest.Name}'"; var cleanedUp = ExecuteNonQuery(cleanUpSqlString); Assert.True(cleanedUp, "It was not possible to clean up the database."); }
public async Task Update_WithValidParameters_DeviceWasUpdated() { //Arrange CreateDeviceRequest deviceCreateRequest = new CreateDeviceRequest { Name = "integrationTestName1", Location = "integrationTestLocation1" }; var insertSqlString = $"Insert into Devices (Name, Location) values('{deviceCreateRequest.Name}', '{deviceCreateRequest.Location}')"; ExecuteNonQuery(insertSqlString); var selectSqlString = $"Select * from Devices WHERE Name = '{deviceCreateRequest.Name}'"; var device = ExecuteDevicesQuery(selectSqlString); Assert.NotNull(device); UpdateDeviceRequest deviceUpdateRequest = new UpdateDeviceRequest { Name = "integrationTestNameUpdated1", Location = "integrationTestLocationUpdated1" }; var updatePayload = JsonConvert.SerializeObject(deviceUpdateRequest); HttpContent updateContent = new StringContent(updatePayload, Encoding.UTF8, "application/json"); string requestUri = $"Devices/{device.Device_id}"; // Act var response = await HttpClient.PutAsync(requestUri, updateContent); //Assert response.StatusCode.Should().Be(HttpStatusCode.OK); selectSqlString = $"Select * from Devices WHERE Name = '{deviceUpdateRequest.Name}'"; var receivedUpdatedDevice = ExecuteDevicesQuery(selectSqlString); Assert.NotNull(receivedUpdatedDevice); Assert.True(DevicesComparer.CompareDeviceWithDeviceRequest(receivedUpdatedDevice, deviceUpdateRequest), "The device was not updated."); //Clean Up var cleanUpSqlString = $"DELETE FROM Devices WHERE Name = '{deviceUpdateRequest.Name}'"; var cleanedUp = ExecuteNonQuery(cleanUpSqlString); Assert.True(cleanedUp, "It was not possible to clean up the database."); }