Skip to content

Commit

Permalink
Update backend to use database to manage device tags #1221 (#1222)
Browse files Browse the repository at this point in the history
* Update backend to use database to manage device tags #1221

* Add unit test on DeviceTagService.UpdateTags

* Remove unused constant

* Add unit test on DeviceTagRepository
  • Loading branch information
hocinehacherouf authored Sep 12, 2022
1 parent 2374916 commit e475af5
Show file tree
Hide file tree
Showing 39 changed files with 445 additions and 636 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.Infrastructure.Repositories
{
using AzureIoTHub.Portal.Domain.Repositories;
using Domain.Entities;

public class DeviceTagRepository : GenericRepository<DeviceTag>, IDeviceTagRepository
{
public DeviceTagRepository(PortalDbContext context) : base(context)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public IEnumerable<T> GetAll()
.ToList<T>();
}

public async Task<T> GetByIdAsync(object id)
public async Task<T?> GetByIdAsync(object id)
{
var t = await this.context.Set<T>().FindAsync(id);
return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void DeviceConfigurationDetailPageShouldRenderCorrectly()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

// Act
var cut = RenderComponent<CreateDeviceConfigurationsPage>();
Expand Down Expand Up @@ -84,7 +84,7 @@ public void DeviceConfigurationDetailShouldCreateConfiguration()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

_ = this.mockDeviceConfigurationsClientService.Setup(service =>
service.CreateDeviceConfiguration(It.Is<DeviceConfig>(config => configuration.Equals(config))))
Expand Down Expand Up @@ -120,7 +120,7 @@ public void DeviceConfigurationDetailShouldProcessProblemDetailsExceptionWhenIss

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

_ = this.mockDeviceConfigurationsClientService.Setup(service =>
service.CreateDeviceConfiguration(It.Is<DeviceConfig>(config => configuration.Equals(config))))
Expand Down Expand Up @@ -181,7 +181,7 @@ public void WhenClickToDeleteTagShouldRemoveTheSelectedTag()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new () { Name = "tag0" },
new () { Name = "tag1" }
Expand Down Expand Up @@ -228,7 +228,7 @@ public void WhenClickToAddTagShouldAddTheSelectedTag()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new () { Name = "tag0" },
new () { Name = "tag1" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void DeviceConfigurationDetailPageShouldRenderCorrectly()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

// Act
var cut = RenderComponent<DeviceConfigurationDetailPage>(ComponentParameter.CreateParameter("ConfigId", configurationId));
Expand Down Expand Up @@ -153,7 +153,7 @@ public void ClickOnDeleteDeviceConfigurationShouldShowDeleteDialog()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

var mockDialogReference = MockRepository.Create<IDialogReference>();
_ = mockDialogReference.Setup(c => c.Result).ReturnsAsync(DialogResult.Cancel());
Expand Down Expand Up @@ -217,7 +217,7 @@ public void DeviceConfigurationDetailPageShouldRenderCardCorrectly()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

// Act
var cut = RenderComponent<DeviceConfigurationDetailPage>(ComponentParameter.CreateParameter("ConfigId", configurationId));
Expand Down Expand Up @@ -280,7 +280,7 @@ public void DeviceConfigurationDetailPageShouldRenderTags()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new () { Name = "tag0" },
new () { Name = "tag1" }
Expand Down Expand Up @@ -337,7 +337,7 @@ public void WhenClickToDeleteTagShouldRemoveTheSelectedTag()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new () { Name = "tag0" },
new () { Name = "tag1" }
Expand Down Expand Up @@ -398,7 +398,7 @@ public void WhenClickToAddTagShouldAddTheSelectedTag()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new () { Name = "tag0" },
new () { Name = "tag1" }
Expand Down Expand Up @@ -490,7 +490,7 @@ public void DeviceConfigurationDetailPageShouldRenderProperties()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

// Act
var cut = RenderComponent<DeviceConfigurationDetailPage>(ComponentParameter.CreateParameter("ConfigId", configurationId));
Expand Down Expand Up @@ -574,7 +574,7 @@ public void WhenClickToDeletePropertyShouldRemoveTheSelectedProperty()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

var cut = RenderComponent<DeviceConfigurationDetailPage>(ComponentParameter.CreateParameter("ConfigId", configurationId));

Expand Down Expand Up @@ -656,7 +656,7 @@ public void WhenClickToAddPropertyShouldAddTheSelectedProperty()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

var cut = RenderComponent<DeviceConfigurationDetailPage>(ComponentParameter.CreateParameter("ConfigId", configurationId));

Expand Down Expand Up @@ -743,7 +743,7 @@ public void WhenClickToSaveShouldSendPutToTheEndpoint()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new () { Name = "tag0" },
new () { Name = "tag1" }
Expand Down Expand Up @@ -836,7 +836,7 @@ public void DeviceConfigurationDetailPageShouldProcessProblemDetailsExceptionWhe

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new () { Name = "tag0" },
new () { Name = "tag1" }
Expand Down Expand Up @@ -900,7 +900,7 @@ public void ReturnButtonMustNavigateToPreviousPage()

_ = this.mockDeviceTagSettingsClientService.Setup(service =>
service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

var cut = RenderComponent<DeviceConfigurationDetailPage>(ComponentParameter.CreateParameter("ConfigId", configurationId));
cut.WaitForAssertion(() => cut.Find("#returnButton"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task ClickOnSaveShouldPostDeviceDetailsAsync()
});

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new()
{
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task DeviceShouldNotBeCreatedWhenModelIsNotValid()
});

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new()
{
Expand Down Expand Up @@ -238,7 +238,7 @@ public async Task SaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnCreat
});

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new()
{
Expand Down Expand Up @@ -293,7 +293,7 @@ public async Task ChangeModelShouldProcessProblemDetailsExceptionWhenIssueOccurs
});

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new()
{
Expand Down Expand Up @@ -347,7 +347,7 @@ public async Task ClickOnSaveAndAddNewShouldCreateDeviceAndResetCreateDevicePage
});

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new()
{
Expand Down Expand Up @@ -423,7 +423,7 @@ public async Task ClickOnSaveAndDuplicateShouldCreateDeviceAndDuplicateDeviceDet
});

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void ShouldLoadDeviceDetails()
.ReturnsAsync(new DeviceModel());

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

// Act
var cut = RenderComponent<DeviceDetailPage>(ComponentParameter.CreateParameter("DeviceID", deviceId));
Expand Down Expand Up @@ -114,7 +114,7 @@ public void ShouldLoadLoRaDeviceDetails()
.ReturnsAsync(new List<DeviceModelCommand>());

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());

// Act
var cut = RenderComponent<DeviceDetailPage>(
Expand Down Expand Up @@ -145,7 +145,7 @@ public void ReturnButtonMustNavigateToPreviousPage()
.ReturnsAsync(new DeviceModel());

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>());
.ReturnsAsync(new List<DeviceTagDto>());


// Act
Expand All @@ -170,7 +170,7 @@ public void ClickOnSaveShouldPutDeviceDetails()
Name = Guid.NewGuid().ToString()
};

var mockTag = new DeviceTag
var mockTag = new DeviceTagDto
{
Label = Guid.NewGuid().ToString(),
Name = Guid.NewGuid().ToString(),
Expand Down Expand Up @@ -200,7 +200,7 @@ public void ClickOnSaveShouldPutDeviceDetails()
.ReturnsAsync(mockDeviceModel);

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
mockTag
});
Expand Down Expand Up @@ -238,7 +238,7 @@ public void SaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnUpdatingDev
Name = Guid.NewGuid().ToString()
};

var mockTag = new DeviceTag
var mockTag = new DeviceTagDto
{
Label = Guid.NewGuid().ToString(),
Name = Guid.NewGuid().ToString(),
Expand Down Expand Up @@ -268,7 +268,7 @@ public void SaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnUpdatingDev
.ReturnsAsync(mockDeviceModel);

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
mockTag
});
Expand Down Expand Up @@ -299,7 +299,7 @@ public void ClickOnSaveShouldDisplaySnackbarIfValidationError()
Name = Guid.NewGuid().ToString()
};

var mockTag = new DeviceTag
var mockTag = new DeviceTagDto
{
Label = Guid.NewGuid().ToString(),
Name = Guid.NewGuid().ToString(),
Expand All @@ -326,7 +326,7 @@ public void ClickOnSaveShouldDisplaySnackbarIfValidationError()
.ReturnsAsync(mockDeviceModel);

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
mockTag
});
Expand Down Expand Up @@ -359,7 +359,7 @@ public void ClickOnConnectShouldDisplayDeviceCredentials()
Name = Guid.NewGuid().ToString()
};

var mockTag = new DeviceTag
var mockTag = new DeviceTagDto
{
Label = Guid.NewGuid().ToString(),
Name = Guid.NewGuid().ToString(),
Expand All @@ -386,7 +386,7 @@ public void ClickOnConnectShouldDisplayDeviceCredentials()
.ReturnsAsync(mockDeviceModel);

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
mockTag
});
Expand Down Expand Up @@ -420,7 +420,7 @@ public void ClickOnDeleteShouldDisplayConfirmationDialogAndReturnIfAborted()
Name = Guid.NewGuid().ToString()
};

var mockTag = new DeviceTag
var mockTag = new DeviceTagDto
{
Label = Guid.NewGuid().ToString(),
Name = Guid.NewGuid().ToString(),
Expand All @@ -447,7 +447,7 @@ public void ClickOnDeleteShouldDisplayConfirmationDialogAndReturnIfAborted()
.ReturnsAsync(mockDeviceModel);

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
mockTag
});
Expand Down Expand Up @@ -482,7 +482,7 @@ public void ClickOnDeleteShouldDisplayConfirmationDialogAndRedirectIfConfirmed()
Name = Guid.NewGuid().ToString()
};

var mockTag = new DeviceTag
var mockTag = new DeviceTagDto
{
Label = Guid.NewGuid().ToString(),
Name = Guid.NewGuid().ToString(),
Expand All @@ -509,7 +509,7 @@ public void ClickOnDeleteShouldDisplayConfirmationDialogAndRedirectIfConfirmed()
.ReturnsAsync(mockDeviceModel);

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
mockTag
});
Expand Down Expand Up @@ -545,7 +545,7 @@ public void ClickOnDuplicateShouldDuplicateDeviceDetailAndRedirectToCreateDevice
Name = Guid.NewGuid().ToString()
};

var mockTag = new DeviceTag
var mockTag = new DeviceTagDto
{
Label = Guid.NewGuid().ToString(),
Name = Guid.NewGuid().ToString(),
Expand All @@ -572,7 +572,7 @@ public void ClickOnDuplicateShouldDuplicateDeviceDetailAndRedirectToCreateDevice
.ReturnsAsync(mockDeviceModel);

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
.ReturnsAsync(new List<DeviceTagDto>
{
mockTag
});
Expand Down
Loading

0 comments on commit e475af5

Please sign in to comment.