public void IoTCompanyMakeIoTDeviceThrowsExceptionCauseFailedEnrollmentGroupCreation() { // Arrange var mockProvisioningService = new Mock <IProvisioningService>(); mockProvisioningService .Setup( pS => pS.CleanUpAndCreateEnrollmentGroupAsync( It.IsAny <Attestation>())) .Returns(Task.FromResult(false)); var mockFactory = new Mock <IIoTHardwareIntegrator>(); mockFactory .Setup( f => f.ManufactureAsync(It.IsAny <string>(), It.IsAny <string>())) .Returns( Task.FromResult <IIoTDevice>(new Mock <IIoTDevice>().Object)); IIoTCompany company = new IoTCompany( this.config.Object, mockProvisioningService.Object, mockFactory.Object); // Act & Assert company.CleanUpAndCreateEnrollmentGroupAsync().GetAwaiter().GetResult(); Assert.Throws <InvalidOperationException>( () => company.MakeDeviceAsync().GetAwaiter().GetResult()); }
public void IoTCompanyMakeAnIoTDeviceSucessfully() { // Arrange var mockProvisioningService = new Mock <IProvisioningService>(); mockProvisioningService .Setup( pS => pS.CleanUpAndCreateEnrollmentGroupAsync( It.IsAny <Attestation>())) .Returns(Task.FromResult(true)); var mockFactory = new Mock <IIoTHardwareIntegrator>(); mockFactory .Setup( f => f.ManufactureAsync(It.IsAny <string>(), It.IsAny <string>())) .Returns( Task.FromResult <IIoTDevice>(new Mock <IIoTDevice>().Object)); IIoTCompany company = new IoTCompany( this.config.Object, mockProvisioningService.Object, mockFactory.Object); IIoTDevice brandNewIoTDevice = null; // Act company.CleanUpAndCreateEnrollmentGroupAsync().GetAwaiter().GetResult(); brandNewIoTDevice = company.MakeDeviceAsync().GetAwaiter().GetResult(); // Assert Assert.NotNull(brandNewIoTDevice); mockFactory.Verify(f => f.ManufactureAsync(It.IsAny <string>(), It.IsAny <string>())); }
private static async Task RunDeviceConnectivitySupplyChain() { using (var iotCompany = new IoTCompany( RuntimeConfig, ProvisioningService)) { // ******** Azure IoT Hub DPS Service ******** // 1. Create a Enrollment Group if not exists Console.Write($"\nCreating a new Enrollment Group: {RuntimeConfig.AzureDPSEnrollmentGroup}..."); await iotCompany.CleanUpAndCreateEnrollmentGroupAsync().ConfigureAwait(false); Console.Write($"OK!\n"); // 2. Go over the PoP await iotCompany.KickoffPoPAsync().ConfigureAwait(false); // ******** Azure IoT Hub DPS Service ******** // 3. Supply Chain with Device Provisioning Console.Write("\nMaking and provisioning a new IoT Device to IoT Hub..."); var brandNewIoTDevice = await iotCompany.MakeDeviceAsync().ConfigureAwait(false); Console.Write($"OK!\n"); // 4. Start sending telemetry Console.Write($"\nAuthenticating {brandNewIoTDevice.DeviceID} and send telemetry sample message..."); await brandNewIoTDevice.AuthNAndSendTelemetryAsync().ConfigureAwait(false); Console.Write($"OK!\n"); Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); } }