Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions sdk/iot/Azure.Iot.Hub.Service/src/IoTHubServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ public class IoTHubServiceClient
/// <summary>
/// place holder for Devices
/// </summary>
public DevicesClient Devices { get; private set; }
public virtual DevicesClient Devices { get; private set; }

/// <summary>
/// place holder for Modules
/// </summary>
public ModulesClient Modules { get; private set; }
public virtual ModulesClient Modules { get; private set; }

/// <summary>
/// place holder for Statistics
/// </summary>
public StatisticsClient Statistics { get; private set; }
public virtual StatisticsClient Statistics { get; private set; }

/// <summary>
/// place holder for Messages
/// </summary>
public CloudToDeviceMessagesClient Messages { get; private set; }
public virtual CloudToDeviceMessagesClient Messages { get; private set; }

/// <summary>
/// place holder for Files
/// </summary>
public FilesClient Files { get; private set; }
public virtual FilesClient Files { get; private set; }

/// <summary>
/// place holder for Jobs
/// </summary>
public JobsClient Jobs { get; private set; }
public virtual JobsClient Jobs { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="IoTHubServiceClient"/> class.
Expand Down
68 changes: 68 additions & 0 deletions sdk/iot/Azure.Iot.Hub.Service/tests/DevicesClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Net;
using System.Threading.Tasks;
using Azure.Iot.Hub.Service.Models;
using FluentAssertions;
using NUnit.Framework;

namespace Azure.Iot.Hub.Service.Tests
{
public class DevicesClientTests : E2eTestBase
{
public DevicesClientTests(bool isAsync)
: base(isAsync)
{
}

[Test]
[Category("Live")]
public async Task Devices_Lifecycle()
{
// TODO: This is just a verification that tests run and it requires the tester to complete this test however they see fit.
string testDeviceName = $"testDevice{GetRandom()}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preferably the name of the test as a prefix. That way, it is easier to track back a device to the test that created it.


DeviceIdentity device = null;

IoTHubServiceClient client = GetClient();
try
{
try
{
device = (await client.Devices.GetIdentityAsync(testDeviceName).ConfigureAwait(false)).Value;
}
catch (RequestFailedException ex) when (ex.Status == (int)HttpStatusCode.NotFound)
{
// If the Device doesn't exist, we will create it.
device = (await client.Devices.CreateOrUpdateIdentityAsync(
new Models.DeviceIdentity
{
DeviceId = testDeviceName
}).ConfigureAwait(false)).Value;
}

// Perform another GET. We expect the device to exist.
Response<Models.DeviceIdentity> response = await client.Devices.GetIdentityAsync(testDeviceName).ConfigureAwait(false);
device = response.Value;
response.GetRawResponse().Status.Should().Be(200);
}
finally
{
// cleanup
try
{
if (device != null)
{
await client.Devices.DeleteIdentityAsync(device, IfMatchPrecondition.UnconditionalIfMatch).ConfigureAwait(false);
}
}
catch (Exception ex)
{
Assert.Fail($"Test clean up failed: {ex.Message}");
}
}
}
}
}
18 changes: 17 additions & 1 deletion sdk/iot/Azure.Iot.Hub.Service/tests/TestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TestSettings

// These environment variables are required to be set to run tests against the CI pipeline.
// If these environment variables exist in the environment, their values will replace (supersede) config.json values.
private static readonly string s_iotHubConnectionString = $"{IotHubServiceEnvironmentVariablesPrefix}_CONNECTION_STRING";
private static readonly string s_iotHubConnectionString = $"{IotHubServiceEnvironmentVariablesPrefix}_HUB_CONNECTION_STRING";

private static readonly string s_iotHubServiceTestMode = $"AZURE_IOT_TEST_MODE";

Expand Down Expand Up @@ -81,6 +81,22 @@ static TestSettings()
// These environment variables are required to be set to run tests against the CI pipeline.
private static void OverrideFromEnvVariables()
{
string iotHubConnectionString = Environment.GetEnvironmentVariable(s_iotHubConnectionString);
if (!string.IsNullOrWhiteSpace(iotHubConnectionString))
{
Instance.IotHubConnectionString = iotHubConnectionString;
}

string testMode = Environment.GetEnvironmentVariable(s_iotHubServiceTestMode);
if (!string.IsNullOrWhiteSpace(testMode))
{
// Enum.Parse<type>(value) cannot be used in net461 so using the type casting syntax.
Instance.TestMode = (RecordedTestMode)Enum.Parse(typeof(RecordedTestMode), testMode);
}
else
{
Environment.SetEnvironmentVariable(s_iotHubServiceTestMode, Instance.TestMode.ToString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if (-not $sp)
}

# Get test application OID from the service principal
$applicationOId = az ad sp show --id $sp --query "objectId" --output tsv
$applicationOId = az ad sp show --id $appId --query "objectId" --output tsv

$rgExists = az group exists --name $ResourceGroup
if ($rgExists -eq "False")
Expand Down