Skip to content

Commit

Permalink
Modification device tag setting (#972)
Browse files Browse the repository at this point in the history
* Modification device tag setting

* Bloquage du bouton Validate

* test deviceTagsPage

Co-authored-by: crib <[email protected]>
  • Loading branch information
ChristopheRib63 and crib authored Jul 29, 2022
1 parent a5d6432 commit 81863e6
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.Settings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
//using System.Threading.Tasks;
using AutoFixture;
using AzureIoTHub.Portal.Client.Exceptions;
using AzureIoTHub.Portal.Client.Models;
Expand All @@ -19,6 +19,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.Settings
using Moq;
using MudBlazor;
using NUnit.Framework;
using System.Threading.Tasks;

[TestFixture]
public class DeviceTagsPageTests : BlazorUnitTest
Expand Down Expand Up @@ -125,33 +126,56 @@ public void OnInitializedAsyncShouldProcessProblemDetailsExceptionWhenIssueOccur


[Test]
public void ClickOnSaveShouldUpdateTagList()
public void ClickOnSaveShouldCreateUpdateTag()
{
var expectedTags = new List<DeviceTag>
{
new() {
Label = "Label",
Name = "Name",
Required = false,
Searchable = false
}
};

//Arrange
_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(expectedTags);

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.UpdateDeviceTags(It.IsAny<List<DeviceTag>>()))
.ReturnsAsync(new List<DeviceTag>
{
new()
{
Label = "tagLabel", Name = "tagName", Required = false,
Searchable = false
}
});
_ = this.mockDeviceTagSettingsClientService.Setup(service => service.CreateOrUpdateDeviceTag(It.IsAny<DeviceTag>()))
.Returns(Task.CompletedTask);

_ = this.mockSnackbarService.Setup(c => c.Add(It.IsAny<string>(), Severity.Success, null)).Returns((Snackbar)null);


var cut = RenderComponent<DeviceTagsPage>();
cut.WaitForAssertion(() => cut.Find("#saveButton"));
cut.WaitForAssertion(() => cut.Markup.Should().NotContain("Loading..."));

// Act
cut.Find("#saveButton").Click();
cut.WaitForElement("#saveButton").Click();

cut.WaitForAssertion(() => MockRepository.VerifyAll());
}

[Test]
public void ClickOnDeleteShouldDeleteTag()
{
//Arrange
const string deviceTagName = "tagName";

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTag>
{
new()
{
Label = "tagLabel", Name = deviceTagName, Required = false,
Searchable = false
}
});
_ = this.mockDeviceTagSettingsClientService.Setup(service => service.DeleteDeviceTagByName(deviceTagName))
.Returns(Task.CompletedTask);

var cut = RenderComponent<DeviceTagsPage>();
cut.WaitForAssertion(() => cut.Markup.Should().NotContain("Loading..."));

// Act
cut.WaitForElement("#deleteButton").Click();

cut.WaitForAssertion(() => MockRepository.VerifyAll());
}
Expand Down Expand Up @@ -232,7 +256,7 @@ public void ClickOnSaveShouldProcessProblemDetailsExceptionIfIssueOccursWhenUpda
new () { Label = "Label", Name = "Name", Required = false, Searchable = false }
});

_ = this.mockDeviceTagSettingsClientService.Setup(service => service.UpdateDeviceTags(It.IsAny<List<DeviceTag>>()))
_ = this.mockDeviceTagSettingsClientService.Setup(service => service.CreateOrUpdateDeviceTag(It.IsAny<DeviceTag>()))
.ThrowsAsync(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails()));

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace AzureIoTHub.Portal.Server.Tests.Unit.Services
{
using System.Collections.Generic;
//using System.Collections.Generic;
using System.Linq;
using System.Net;
//using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using AutoFixture;
Expand Down Expand Up @@ -49,28 +49,28 @@ public async Task GetDeviceTagsShouldReturnDeviceTags()
MockHttpClient.VerifyNoOutstandingExpectation();
}

[Test]
public async Task UpdateDeviceTagsShouldUpdateDeviceTags()
{
// Arrange
var expectedDeviceTags = Fixture.Build<DeviceTag>().CreateMany(3).ToList();
//[Test]
//public async Task UpdateDeviceTagsShouldUpdateDeviceTags()
//{
// // Arrange
// var expectedDeviceTags = Fixture.Build<DeviceTag>().CreateMany(3).ToList();

_ = MockHttpClient.When(HttpMethod.Post, "/api/settings/device-tags")
.With(m =>
{
_ = m.Content.Should().BeAssignableTo<ObjectContent<IList<DeviceTag>>>();
var tags = m.Content as ObjectContent<IList<DeviceTag>>;
_ = tags.Value.Should().BeEquivalentTo(expectedDeviceTags);
return true;
})
.Respond(HttpStatusCode.Created);
// _ = MockHttpClient.When(HttpMethod.Post, "/api/settings/device-tags")
// .With(m =>
// {
// _ = m.Content.Should().BeAssignableTo<ObjectContent<IList<DeviceTag>>>();
// var tags = m.Content as ObjectContent<IList<DeviceTag>>;
// _ = tags.Value.Should().BeEquivalentTo(expectedDeviceTags);
// return true;
// })
// .Respond(HttpStatusCode.Created);

// Act
await this.deviceTagSettingsClientService.UpdateDeviceTags(expectedDeviceTags);
// // Act
// await this.deviceTagSettingsClientService.UpdateDeviceTags(expectedDeviceTags);

// Assert
MockHttpClient.VerifyNoOutstandingRequest();
MockHttpClient.VerifyNoOutstandingExpectation();
}
// // Assert
// MockHttpClient.VerifyNoOutstandingRequest();
// MockHttpClient.VerifyNoOutstandingExpectation();
//}
}
}
Loading

0 comments on commit 81863e6

Please sign in to comment.