Skip to content

Commit

Permalink
Fix DuplicateSharedDevice when device is lorawan
Browse files Browse the repository at this point in the history
  • Loading branch information
hocinehacherouf committed Jul 29, 2022
1 parent df99826 commit ea45703
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Services
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Models.v10;
using Models.v10.LoRaWAN;
using NUnit.Framework;

[TestFixture]
Expand Down Expand Up @@ -63,6 +64,30 @@ public void DuplicateSharedDeviceShouldReturnDuplicatedDevice()
_ = result.DeviceName.Should().Be($"{deviceName} - copy");
}

[Test]
public void DuplicateSharedDeviceShouldReturnDuplicatedLoraWanDevice()
{
// Arrange
var deviceId = Fixture.Create<string>();
var deviceName = Fixture.Create<string>();
var appKey = Fixture.Create<string>();

// Act
var result = this.deviceLayoutService.DuplicateSharedDevice(new LoRaDeviceDetails
{
DeviceID = deviceId,
DeviceName = deviceName,
AppKey = appKey
});

// Assert
var loraWanDevice = (LoRaDeviceDetails) result;

_ = loraWanDevice.DeviceID.Should().BeEmpty();
_ = loraWanDevice.DeviceName.Should().Be($"{deviceName} - copy");
_ = loraWanDevice.AppKey.Should().BeEmpty();
}

[Test]
public void DuplicateSharedDeviceModelShouldReturnDuplicatedDeviceModel()
{
Expand All @@ -89,6 +114,26 @@ public void ResetSharedDeviceShouldReturnNewDevice()
_ = result.Should().BeEquivalentTo(expectedDevice);
}

[Test]
public void ResetSharedDeviceShouldReturnNewDeviceWithExpectedTags()
{
// Arrange
var expectedTags = Fixture.CreateMany<DeviceTag>(2).ToList();

var expectedDevice = new DeviceDetails();

foreach (var tag in expectedTags)
{
_ = expectedDevice.Tags.TryAdd(tag.Name, string.Empty);
}

// Act
var result = this.deviceLayoutService.ResetSharedDevice(expectedTags);

// Assert
_ = result.Should().BeEquivalentTo(expectedDevice);
}

[Test]
public void ResetSharedDeviceModelShouldReturnNewDeviceModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public DeviceDetails DuplicateSharedDevice(DeviceDetails deviceToDuplicate)
deviceToDuplicate.DeviceID = string.Empty;
deviceToDuplicate.DeviceName = $"{deviceToDuplicate.DeviceName} - copy";

if (this.sharedDevice.IsLoraWan)
if (deviceToDuplicate.IsLoraWan)
{
var loRaDeviceDetails = (LoRaDeviceDetails)deviceToDuplicate;
loRaDeviceDetails.AppKey = string.Empty;
Expand Down

0 comments on commit ea45703

Please sign in to comment.