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

Enrollment group creation now based on device model id #435

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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