Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disambiguate twin classes from hub and dps service clients #2910

Merged
merged 4 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 25 additions & 12 deletions SDK v2 migration guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,20 @@ but users are still encouraged to migrate to version 2 when they have the chance
| `Module.LastActivityTime` | `Module.LastActiveOnUtc` |
| `RegistryManager.GetTwinAsync(...)` | `IotHubServiceClient.Twins.GetAsync(...)` |
| `RegistryManager.UpdateTwinAsync(...)` | `IotHubServiceClient.Twins.UpdateAsync(...)` |
| `Twin.StatusUpdatedOn` | `Twin.StatusUpdatedOnUtc` |
| `Twin.LastActivityOn` | `Twin.LastActiveOnUtc` |
| `TwinCollection.GetLastUpdatedOn()` | `TwinCollection.GetLastUpdatedOnUtc()` |
| `TwinCollectionArray.GetLastUpdatedOn()` | `TwinCollectionArray.GetLastUpdatedOnUtc()` |
| `TwinCollectionValue.GetLastUpdatedOn()` | `TwinCollectionValue.GetLastUpdatedOnUtc()` |
| `Metadata.LastUpdatedOn` | `TwinMetadata.LastUpdatedOnUtc` |
| `Twin` | `ClientTwin` |
| `Twin.StatusUpdatedOn` | `ClientTwin.StatusUpdatedOnUtc` |
| `Twin.LastActivityOn` | `ClientTwin.LastActiveOnUtc` |
| `TwinCollection` | `ClientTwinProperties` |
| `TwinCollection.GetLastUpdatedOn()` | `ClientTwinProperties.GetLastUpdatedOnUtc()` |
| `TwinCollectionValue` | `ClientTwinPropertyValue` |
| `TwinCollectionValue.GetLastUpdatedOn()` | `ClientTwinPropertyValue.GetLastUpdatedOnUtc()` |
| `TwinCollectionArray` | `ClientTwinPropertyArray` |
| `TwinCollectionArray.GetLastUpdatedOn()` | `ClientTwinPropertiesArray.GetLastUpdatedOnUtc()` |
| `Metadata` | `ClientTwinMetadata` |
| `Metadata.LastUpdatedOn` | `ClientTwinMetadata.LastUpdatedOnUtc` |
| `AuthenticationType` | `ClientAuthenticationType` |
| `DeviceConnectionState` | `ClientConnectionState` |
| `DeviceStatus` | `ClientStatus` |
| `RegistryManager.CreateQuery(...)` | `IotHubServiceClient.Query.CreateAsync<T>(...)` |
| `RegistryManager.AddConfigurationAsync(...)` | `IotHubServiceClient.Configurations.CreateAsync(...)` |
| `RegistryManager.GetConfigurationsAsync(int maxCount)`| `IotHubServiceClient.Configurations.GetAsync(int maxCount)` |
Expand Down Expand Up @@ -292,17 +300,22 @@ but users are still encouraged to migrate to version 2 when they have the chance
| `EnrollmentGroup.LastUpdatedDateTimeUtc` | `EnrollmentGroup.LastUpdatedOnUtc` |
| `IndividualEnrollment.CreatedDateTimeUtc` | `IndividualEnrollment.CreatedOnUtc` |
| `IndividualEnrollment.LastUpdatedDateTimeUtc` | `IndividualEnrollment.LastUpdatedOnUtc` |
| `Twin.StatusUpdatedOn` | `Twin.StatusUpdatedOnUtc` |
| `Twin.LastActivityOn` | `Twin.LastActiveOnUtc` |
| `Twin` | `ProvisioningTwin` |
| `Twin.StatusUpdatedOn` | `ProvisioningTwin.StatusUpdatedOnUtc` |
| `Twin.LastActivityOn` | `ProvisioningTwin.LastActiveOnUtc` |
| `TwinCollection` | `ProvisioningTwinProperties` |
| `TwinCollection.GetLastUpdatedOn()` | `ProvisioningTwinProperties.GetLastUpdatedOnUtc()` |
| `TwinCollectionValue` | `ProvisioningTwinPropertyValue` |
| `TwinCollectionValue.GetLastUpdatedOn()` | `ProvisioningTwinPropertyValue.GetLastUpdatedOnUtc()` |
| `TwinCollectionArray` | `ProvisioningTwinPropertyArray` |
| `TwinCollectionArray.GetLastUpdatedOn()` | `ProvisioningTwinPropertyArray.GetLastUpdatedOnUtc()` |
| `Metadata` | `ProvisioningTwinMetadata` |
| `Metadata.LastUpdatedOn` | `ProvisioningTwinMetadata.LastUpdatedOnUtc` |
| `X509Attestation.CreateFromCAReferences(...)` | `X509Attestation.CreateFromCaReferences(...)` |
| `X509Attestation.CAReferences` | `X509Attestation.CaReferences` |
| `X509CAReferences` | `X509CaReferences` |
| `X509CertificateInfo.SHA1Thumbprint` | `X509CertificateInfo.Sha1Thumbprint` |
| `X509CertificateInfo.SHA256Thumbprint` | `X509CertificateInfo.Sha256Thumbprint` |
| `TwinCollection.GetLastUpdatedOn()` | `TwinCollection.GetLastUpdatedOnUtc()` |
| `TwinCollectionArray.GetLastUpdatedOn()` | `TwinCollectionArray.GetLastUpdatedOnUtc()` |
| `TwinCollectionValue.GetLastUpdatedOn()` | `TwinCollectionValue.GetLastUpdatedOnUtc()` |
| `Metadata.LastUpdatedOn` | `TwinMetadata.LastUpdatedOnUtc` |

#### Other notable breaking changes

Expand Down
8 changes: 4 additions & 4 deletions e2e/test/iothub/ConnectionStatusChangeHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ await IotHubDeviceClient_Gives_ConnectionStatus_Disconnected_ChangeReason_Device
async (r, d) =>
{
Device device = await r.Devices.GetAsync(d).ConfigureAwait(false);
device.Status = DeviceStatus.Disabled;
device.Status = ClientStatus.Disabled;
await r.Devices.SetAsync(device).ConfigureAwait(false);
})
.ConfigureAwait(false);
Expand All @@ -67,7 +67,7 @@ await IotHubDeviceClient_Gives_ConnectionStatus_Disconnected_ChangeReason_Device
async (r, d) =>
{
Device device = await r.Devices.GetAsync(d).ConfigureAwait(false);
device.Status = DeviceStatus.Disabled;
device.Status = ClientStatus.Disabled;
await r.Devices.SetAsync(device).ConfigureAwait(false);
})
.ConfigureAwait(false);
Expand Down Expand Up @@ -126,7 +126,7 @@ void StatusChangeHandler(ConnectionStatusInfo c)

// Receiving the module twin should succeed right now.
VerboseTestLogger.WriteLine($"{nameof(IotHubDeviceClient_Gives_ConnectionStatus_Disconnected_ChangeReason_DeviceDisabled_Base)}: DeviceClient GetTwinAsync.");
ClientTwin twin = await deviceClient.GetTwinAsync().ConfigureAwait(false);
Client.ClientTwin twin = await deviceClient.GetTwinAsync().ConfigureAwait(false);
Assert.IsNotNull(twin);

// Delete/disable the device in IoT hub. This should trigger the ConnectionStatusChangeHandler.
Expand Down Expand Up @@ -179,7 +179,7 @@ void StatusChangeHandler(ConnectionStatusInfo c)

// Receiving the module twin should succeed right now.
VerboseTestLogger.WriteLine($"{nameof(IotHubModuleClient_Gives_ConnectionStatus_Disconnected_ChangeReason_DeviceDisabled_Base)}: ModuleClient GetTwinAsync.");
ClientTwin twin = await moduleClient.GetTwinAsync().ConfigureAwait(false);
Client.ClientTwin twin = await moduleClient.GetTwinAsync().ConfigureAwait(false);
Assert.IsNotNull(twin);

// Delete/disable the device in IoT hub.
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/SasCredentialAuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task JobClient_Http_SasCredentialAuth_Success()
string jobId = "JOBSAMPLE" + Guid.NewGuid().ToString();
string jobDeviceId = "JobsSample_Device";
string query = $"DeviceId IN ['{jobDeviceId}']";
var twin = new Twin(jobDeviceId);
var twin = new ClientTwin(jobDeviceId);

try
{
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/TokenCredentialAuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task JobClient_Http_TokenCredentialAuth_Success()
string jobId = "JOBSAMPLE" + Guid.NewGuid().ToString();
string jobDeviceId = "JobsSample_Device";
string query = $"DeviceId IN ['{jobDeviceId}']";
var twin = new Twin(jobDeviceId);
var twin = new ClientTwin(jobDeviceId);

try
{
Expand Down
24 changes: 12 additions & 12 deletions e2e/test/iothub/service/BulkOperationsE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public async Task BulkOperations_UpdateTwins2Device_Ok()
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(DevicePrefix).ConfigureAwait(false);
using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString);

Twin twin = await serviceClient.Twins.GetAsync(testDevice.Id).ConfigureAwait(false);
ClientTwin twin = await serviceClient.Twins.GetAsync(testDevice.Id).ConfigureAwait(false);
twin.Tags[tagName] = tagValue;

BulkRegistryOperationResult result = await serviceClient.Twins.UpdateAsync(new List<Twin> { twin }, false).ConfigureAwait(false);
BulkRegistryOperationResult result = await serviceClient.Twins.UpdateAsync(new List<ClientTwin> { twin }, false).ConfigureAwait(false);
Assert.IsTrue(result.IsSuccessful, $"UpdateTwins2Async error:\n{ResultErrorsToString(result)}");

Twin twinUpd = await serviceClient.Twins.GetAsync(testDevice.Id).ConfigureAwait(false);
ClientTwin twinUpd = await serviceClient.Twins.GetAsync(testDevice.Id).ConfigureAwait(false);

Assert.AreEqual(twin.DeviceId, twinUpd.DeviceId, "Device ID changed");
Assert.IsNotNull(twinUpd.Tags, "Twin.Tags is null");
Expand All @@ -51,13 +51,13 @@ public async Task BulkOperations_UpdateTwins2DevicePatch_Ok()
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(DevicePrefix).ConfigureAwait(false);
using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString);

var twin = new Twin(testDevice.Id);
var twin = new ClientTwin(testDevice.Id);
twin.Tags[tagName] = tagValue;

BulkRegistryOperationResult result = await serviceClient.Twins.UpdateAsync(new List<Twin> { twin }, false).ConfigureAwait(false);
BulkRegistryOperationResult result = await serviceClient.Twins.UpdateAsync(new List<ClientTwin> { twin }, false).ConfigureAwait(false);
Assert.IsTrue(result.IsSuccessful, $"UpdateTwins2Async error:\n{ResultErrorsToString(result)}");

Twin twinUpd = await serviceClient.Twins.GetAsync(testDevice.Id).ConfigureAwait(false);
ClientTwin twinUpd = await serviceClient.Twins.GetAsync(testDevice.Id).ConfigureAwait(false);

Assert.AreEqual(twin.DeviceId, twinUpd.DeviceId, "Device ID changed");
Assert.IsNotNull(twinUpd.Tags, "Twin.Tags is null");
Expand All @@ -75,13 +75,13 @@ public async Task BulkOperations_UpdateTwins2Module_Ok()
TestModule testModule = await TestModule.GetTestModuleAsync(DevicePrefix, ModulePrefix).ConfigureAwait(false);
using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString);

Twin twin = await serviceClient.Twins.GetAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
ClientTwin twin = await serviceClient.Twins.GetAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
twin.Tags[tagName] = tagValue;

BulkRegistryOperationResult result = await serviceClient.Twins.UpdateAsync(new List<Twin> { twin }, false).ConfigureAwait(false);
BulkRegistryOperationResult result = await serviceClient.Twins.UpdateAsync(new List<ClientTwin> { twin }, false).ConfigureAwait(false);
Assert.IsTrue(result.IsSuccessful, $"UpdateTwins2Async error:\n{ResultErrorsToString(result)}");

Twin twinUpd = await serviceClient.Twins.GetAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
ClientTwin twinUpd = await serviceClient.Twins.GetAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);

Assert.AreEqual(twin.DeviceId, twinUpd.DeviceId, "Device ID changed");
Assert.AreEqual(twin.ModuleId, twinUpd.ModuleId, "Module ID changed");
Expand All @@ -100,16 +100,16 @@ public async Task BulkOperations_UpdateTwins2ModulePatch_Ok()
TestModule testModule = await TestModule.GetTestModuleAsync(DevicePrefix, ModulePrefix).ConfigureAwait(false);

using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString);
var twin = new Twin(testModule.DeviceId)
var twin = new ClientTwin(testModule.DeviceId)
{
ModuleId = testModule.Id
};
twin.Tags[tagName] = tagValue;

BulkRegistryOperationResult result = await serviceClient.Twins.UpdateAsync(new List<Twin> { twin }, false).ConfigureAwait(false);
BulkRegistryOperationResult result = await serviceClient.Twins.UpdateAsync(new List<ClientTwin> { twin }, false).ConfigureAwait(false);
Assert.IsTrue(result.IsSuccessful, $"UpdateTwins2Async error:\n{ResultErrorsToString(result)}");

Twin twinUpd = await serviceClient.Twins.GetAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
ClientTwin twinUpd = await serviceClient.Twins.GetAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);

Assert.AreEqual(twin.DeviceId, twinUpd.DeviceId, "Device ID changed");
Assert.AreEqual(twin.ModuleId, twinUpd.ModuleId, "Module ID changed");
Expand Down
6 changes: 3 additions & 3 deletions e2e/test/iothub/service/ExportDevicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public async Task DevicesClient_ExportDevices(StorageAuthenticationType storageA
Device edge1 = await serviceClient.Devices.CreateAsync(
new Device(edgeId1)
{
Authentication = new AuthenticationMechanism { Type = AuthenticationType.Sas },
Authentication = new AuthenticationMechanism { Type = ClientAuthenticationType.Sas },
Capabilities = new DeviceCapabilities { IsIotEdge = true },
})
.ConfigureAwait(false);

Device edge2 = await serviceClient.Devices.CreateAsync(
new Device(edgeId2)
{
Authentication = new AuthenticationMechanism { Type = AuthenticationType.Sas },
Authentication = new AuthenticationMechanism { Type = ClientAuthenticationType.Sas },
Capabilities = new DeviceCapabilities { IsIotEdge = true },
ParentScopes = { edge1.Scope },
})
Expand All @@ -87,7 +87,7 @@ public async Task DevicesClient_ExportDevices(StorageAuthenticationType storageA
Device device = await serviceClient.Devices.CreateAsync(
new Device(deviceId)
{
Authentication = new AuthenticationMechanism { Type = AuthenticationType.Sas },
Authentication = new AuthenticationMechanism { Type = ClientAuthenticationType.Sas },
Scope = edge1.Scope,
})
.ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/service/ImportDevicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task DevicesClient_ImportDevices(StorageAuthenticationType storageA
new ExportImportDevice(
new Device(deviceId)
{
Authentication = new AuthenticationMechanism { Type = AuthenticationType.Sas }
Authentication = new AuthenticationMechanism { Type = ClientAuthenticationType.Sas }
},
ImportMode.Create),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task ServiceClient_QueryDevicesInvalidServiceCertificateHttp_Fails(
{
using var sc = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionStringInvalidServiceCertificate);
var exception = await Assert.ThrowsExceptionAsync<IotHubServiceException>(
() => sc.Query.CreateAsync<Twin>("select * from devices")).ConfigureAwait(false);
() => sc.Query.CreateAsync<ClientTwin>("select * from devices")).ConfigureAwait(false);

#if NET472
Assert.IsInstanceOfType(exception.InnerException.InnerException.InnerException, typeof(AuthenticationException));
Expand Down Expand Up @@ -76,7 +76,7 @@ public async Task JobClient_ScheduleTwinUpdateInvalidServiceCertificateHttp_Fail
var exception = await Assert.ThrowsExceptionAsync<IotHubServiceException>(
() => sc.ScheduledJobs.ScheduleTwinUpdateAsync(
"DeviceId IN ['testDevice']",
new Twin(),
new ClientTwin(),
DateTimeOffset.UtcNow,
ScheduledTwinUpdateOptions))
.ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/service/IoTHubServiceProxyE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task JobClient_ScheduleAndRunTwinJob_WithProxy()
};
using var sc = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString, options);

var twin = new Twin(JobDeviceId)
var twin = new ClientTwin(JobDeviceId)
{
Tags = { { JobTestTagName, JobDeviceId } },
};
Expand Down
6 changes: 3 additions & 3 deletions e2e/test/iothub/service/PnpServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task DeviceTwin_Contains_ModelId()

// Get device twin.
using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString);
Twin twin = await serviceClient.Twins.GetAsync(testDevice.Device.Id).ConfigureAwait(false);
ClientTwin twin = await serviceClient.Twins.GetAsync(testDevice.Device.Id).ConfigureAwait(false);

// Assert
twin.ModelId.Should().Be(TestModelId, "because the device was created as plug and play");
Expand Down Expand Up @@ -75,7 +75,7 @@ public async Task DeviceTwin_Contains_ModelId_X509()

// Get device twin.
using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString);
Twin twin = await serviceClient.Twins.GetAsync(testDevice.Device.Id).ConfigureAwait(false);
ClientTwin twin = await serviceClient.Twins.GetAsync(testDevice.Device.Id).ConfigureAwait(false);

// Assert
twin.ModelId.Should().Be(TestModelId, "because the device was created as plug and play");
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task ModuleTwin_Contains_ModelId()

// Get module twin.
using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString);
Twin twin = await serviceClient.Twins.GetAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
ClientTwin twin = await serviceClient.Twins.GetAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);

// Assert
twin.ModelId.Should().Be(TestModelId, "because the module was created as plug and play");
Expand Down
Loading