Skip to content

Commit

Permalink
update unit test device service
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeM-2ISA authored and kbeaugrand committed Mar 6, 2023
1 parent b6ba6fe commit 4fc479f
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace AzureIoTHub.Portal.Tests.Unit.Server.Services
using EntityFramework.Exceptions.Common;
using FluentAssertions;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Common.Exceptions;
using Microsoft.Azure.Devices.Shared;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -652,5 +653,37 @@ public async Task GetAvailableLabels_LabelsExists_LabelsReturned()
_ = result.Count().Should().Be(expectedLabels.Count);
MockRepository.VerifyAll();
}

[Test]
public async Task DeleteDevice_DeviceNotFoundOnAzure_DeviceDeletedInDatabase()
{
// Arrange
var deviceDto = new DeviceDetails
{
DeviceID = Fixture.Create<string>()
};

_ = this.mockExternalDevicesService.Setup(service => service.DeleteDevice(deviceDto.DeviceID))
.ThrowsAsync(new DeviceNotFoundException(deviceDto.DeviceID));

_ = this.mockDeviceRepository.Setup(repository => repository.GetByIdAsync(deviceDto.DeviceID, d => d.Tags, d => d.Labels))
.ReturnsAsync(new Device
{
Tags = new List<DeviceTagValue>(),
Labels = new List<Label>()
});

this.mockDeviceRepository.Setup(repository => repository.Delete(deviceDto.DeviceID))
.Verifiable();

_ = this.mockUnitOfWork.Setup(work => work.SaveAsync())
.Returns(Task.CompletedTask);

// Act
await this.deviceService.DeleteDevice(deviceDto.DeviceID);

// Assert
MockRepository.VerifyAll();
}
}
}

0 comments on commit 4fc479f

Please sign in to comment.