Skip to content

Commit

Permalink
Enrollment group creation now based on device model id (#435)
Browse files Browse the repository at this point in the history
* CreateEnrollmentGroupFromModelAsync - Fixed typo in function name

* Enrollment group creation based on device ModelId instead of ModelName
  • Loading branch information
audserraCGI authored Mar 11, 2022
1 parent 16337df commit 77dd6ee
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public async Task PostShouldCreateANewEntity()
It.IsAny<DeviceModel>()))
.Returns(new Dictionary<string, object>());

_ = this.mockDeviceProvisioningServiceManager.Setup(c => c.CreateEnrollmentGroupFormModelAsync(
_ = this.mockDeviceProvisioningServiceManager.Setup(c => c.CreateEnrollmentGroupFromModelAsync(
It.IsAny<string>(),
It.Is<string>(x => x == requestModel.Name),
It.IsAny<TwinCollection>()))
Expand Down Expand Up @@ -400,7 +400,7 @@ public async Task WhenEmptyModelIdPostShouldCreateANewEntity()
_ = this.mockTableClientFactory.Setup(c => c.GetDeviceTemplates())
.Returns(mockDeviceTemplatesTableClient.Object);

_ = this.mockDeviceProvisioningServiceManager.Setup(c => c.CreateEnrollmentGroupFormModelAsync(
_ = this.mockDeviceProvisioningServiceManager.Setup(c => c.CreateEnrollmentGroupFromModelAsync(
It.IsAny<string>(),
It.Is<string>(x => x == requestModel.Name),
It.IsAny<TwinCollection>()))
Expand Down Expand Up @@ -476,7 +476,7 @@ public async Task PutShouldUpdateTheDeviceModel()
_ = this.mockTableClientFactory.Setup(c => c.GetDeviceTemplates())
.Returns(mockDeviceTemplatesTableClient.Object);

_ = this.mockDeviceProvisioningServiceManager.Setup(c => c.CreateEnrollmentGroupFormModelAsync(
_ = this.mockDeviceProvisioningServiceManager.Setup(c => c.CreateEnrollmentGroupFromModelAsync(
It.IsAny<string>(),
It.Is<string>(x => x == requestModel.Name),
It.IsAny<TwinCollection>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ public async Task WhenEnrollmentGroupAlreadyExistCreateEnrollmentGroupAsyncShoul
[TestCase("aaa", "aaa")]
[TestCase("AAA", "aaa")]
[TestCase("AAA AAA", "aaa-aaa")]
public async Task CreateEnrollmentGroupFormModelAsyncShouldCreateANewEnrollmentGroup(string modelName, string enrollmentGroupName)
public async Task CreateEnrollmentGroupFromModelAsyncShouldCreateANewEnrollmentGroup(string modelId, string enrollmentGroupName)
{
// Arrange
var manager = this.CreateManager();
var modelId = "bbb";
var modelName = "bbb";
var desiredProperties = new TwinCollection();
EnrollmentGroup enrollmentGroup = null;

Expand All @@ -143,7 +143,7 @@ public async Task CreateEnrollmentGroupFormModelAsyncShouldCreateANewEnrollmentG
});

// Act
var result = await manager.CreateEnrollmentGroupFormModelAsync(
var result = await manager.CreateEnrollmentGroupFromModelAsync(
modelId,
modelName,
desiredProperties);
Expand All @@ -163,11 +163,11 @@ public async Task CreateEnrollmentGroupFormModelAsyncShouldCreateANewEnrollmentG
[TestCase("aaa", "aaa")]
[TestCase("AAA", "aaa")]
[TestCase("AAA AAA", "aaa-aaa")]
public async Task WhenEnrollmentGroupExistCreateEnrollmentGroupFormModelAsyncShouldUpdate(string modelName, string enrollmentGroupName)
public async Task WhenEnrollmentGroupExistCreateEnrollmentGroupFromModelAsyncShouldUpdate(string modelId, string enrollmentGroupName)
{
// Arrange
var manager = this.CreateManager();
var modelId = "bbb";
var modelName = "bbb";
var desiredProperties = new TwinCollection();
EnrollmentGroup enrollmentGroup = null;

Expand All @@ -193,7 +193,7 @@ public async Task WhenEnrollmentGroupExistCreateEnrollmentGroupFormModelAsyncSho
});

// Act
var result = await manager.CreateEnrollmentGroupFormModelAsync(
var result = await manager.CreateEnrollmentGroupFromModelAsync(
modelId,
modelName,
desiredProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private async Task SaveEntity(TableEntity entity, TModel deviceModelObject)

var deviceModelTwin = new TwinCollection();

_ = await this.deviceProvisioningServiceManager.CreateEnrollmentGroupFormModelAsync(deviceModelObject.ModelId, deviceModelObject.Name, deviceModelTwin);
_ = await this.deviceProvisioningServiceManager.CreateEnrollmentGroupFromModelAsync(deviceModelObject.ModelId, deviceModelObject.Name, deviceModelTwin);

await this.configService.RolloutDeviceConfiguration(deviceModelObject.ModelId, deviceModelObject.Name, desiredProperties);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) CGI France. All rights reserved.
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Server.Managers
Expand Down Expand Up @@ -34,13 +34,13 @@ public async Task<EnrollmentGroup> CreateEnrollmentGroupAsync(string deviceType)
return await this.CreateNewEnrollmentGroup(deviceType, true, twinState);
}

public async Task<EnrollmentGroup> CreateEnrollmentGroupFormModelAsync(string modelId, string modelName, TwinCollection desiredProperties)
public async Task<EnrollmentGroup> CreateEnrollmentGroupFromModelAsync(string modelId, string modelName, TwinCollection desiredProperties)
{
var twinState = new TwinState(
tags: new TwinCollection($"{{ \"modelId\":\"{modelId}\" }}"),
desiredProperties: new TwinCollection());

return await this.CreateNewEnrollmentGroup(modelName, false, twinState);
return await this.CreateNewEnrollmentGroup(modelId, false, twinState);
}

private async Task<EnrollmentGroup> CreateNewEnrollmentGroup(string name, bool iotEdge, TwinState initialTwinState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) CGI France. All rights reserved.
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Server.Managers
Expand Down Expand Up @@ -31,7 +31,7 @@ public interface IDeviceProvisioningServiceManager
/// <param name="modelName">The model name.</param>
/// <param name="desiredProperties">The desired properties</param>
/// <returns></returns>
Task<EnrollmentGroup> CreateEnrollmentGroupFormModelAsync(string modelId, string modelName, TwinCollection desiredProperties);
Task<EnrollmentGroup> CreateEnrollmentGroupFromModelAsync(string modelId, string modelName, TwinCollection desiredProperties);

/// <summary>
/// Returns the device enrollment credentials.
Expand Down

0 comments on commit 77dd6ee

Please sign in to comment.