Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// --------------------------------------------------------------------------------------------------------
// <copyright file="CometConnectionTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2022 RHEA System S.A.
//
// Author: Antoine Théate, Sam Gerené, Alex Vorobiev, Alexander van Delft, Martin Risseeuw, Nabil Abbar
//
// This file is part of UI-DSM.
// The UI-DSM web application is used to review an ECSS-E-TM-10-25 model.
//
// The UI-DSM application is provided to the community under the Apache License 2.0.
// </copyright>
// --------------------------------------------------------------------------------------------------------

namespace UI_DSM.Client.Tests.Components.Administration.ModelManagement
{
using Bunit;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;

using Moq;

using NUnit.Framework;

using UI_DSM.Client.Components.Administration.ModelManagement;
using UI_DSM.Client.Services.Administration.CometService;
using UI_DSM.Client.Tests.Helpers;
using UI_DSM.Client.ViewModels.Components.Administration.ModelManagement;
using UI_DSM.Shared.DTO.CometData;

using TestContext = Bunit.TestContext;

[TestFixture]
public class CometConnectionTestFixture
{
private TestContext context;
private ICometConnectionViewModel viewModel;
private Mock<ICometService> cometService;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.context.ConfigureDevExpressBlazor();
this.cometService = new Mock<ICometService>();
this.viewModel = new CometConnectionViewModel(this.cometService.Object);
}

[TearDown]
public void Teardown()
{
this.context.CleanContext();
this.viewModel.Dispose();
}

[Test]
public async Task VerifyComponent()
{
var renderer = this.context.RenderComponent<CometConnection>(parameters =>
{
parameters.Add(p => p.ViewModel, this.viewModel);
});

this.viewModel.InitializeProperties();

var editForm = renderer.FindComponent<EditForm>();

this.viewModel.AuthenticationData.Url = "http://localhost";
this.viewModel.AuthenticationData.UserName = "admin";
this.viewModel.AuthenticationData.Password = "password";

this.cometService.Setup(x => x.Login(this.viewModel.AuthenticationData)).ReturnsAsync(new CometAuthenticationResponse()
{
IsRequestSuccessful = false
});

await renderer.InvokeAsync(editForm.Instance.OnValidSubmit.InvokeAsync);
Assert.That(renderer.Instance.ConnectButtonText, Is.EqualTo("Retry"));

var sessionId = Guid.NewGuid();

this.cometService.Setup(x => x.Login(this.viewModel.AuthenticationData)).ReturnsAsync(new CometAuthenticationResponse()
{
IsRequestSuccessful = true,
SessionId = sessionId
});

var modelGuid = Guid.NewGuid();
var iterationGuid = Guid.NewGuid();

var modelsData = new ModelsDataResponse()
{
ModelNames = new Dictionary<Guid, string>(),
AvailableModels = new Dictionary<Guid, List<Tuple<Guid, string>>>()
};

modelsData.ModelNames[modelGuid] = "LOFT";

modelsData.AvailableModels[modelGuid] = new List<Tuple<Guid, string>>
{
new (iterationGuid, "Iteration 1")
};

this.cometService.Setup(x => x.GetAvailableEngineeringModels(It.IsAny<Guid>()))
.ReturnsAsync(modelsData);

await renderer.InvokeAsync(editForm.Instance.OnValidSubmit.InvokeAsync);
Assert.That(this.viewModel.AuthenticationData.Password, Is.Empty);

this.viewModel.OnEventCallback = new EventCallbackFactory().Create(this.viewModel, async () =>
{
var upload = await this.cometService.Object.UploadIteration(sessionId, modelGuid, iterationGuid);

if(!upload.IsRequestSuccessful)
{
this.viewModel.HandleUploadFailure(upload);
}
else
{
await this.viewModel.CometLogout();
}
});

this.viewModel.SelectedEngineeringModelSetup = new Tuple<Guid, string>(modelGuid, "LOFT");

this.cometService.Setup(x => x.UploadIteration(sessionId, modelGuid, iterationGuid))
.ReturnsAsync(new ModelUploadResponse()
{
IsRequestSuccessful = false,
Errors = new List<string>{"Error during uploading"}
});

await renderer.InvokeAsync(this.viewModel.OnEventCallback.InvokeAsync);
Assert.That(renderer.Instance.UploadText, Is.EqualTo("Retry..."));

this.cometService.Setup(x => x.UploadIteration(sessionId, modelGuid, iterationGuid))
.ReturnsAsync(new ModelUploadResponse()
{
IsRequestSuccessful = true
});

await renderer.InvokeAsync(this.viewModel.OnEventCallback.InvokeAsync);
}
}
}
85 changes: 0 additions & 85 deletions UI_DSM/UI_DSM.Client.Tests/Helpers/JsonSerializerHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace UI_DSM.Client.Tests.Pages.Administration.ProjectPages
using UI_DSM.Client.Services.Administration.ParticipantService;
using UI_DSM.Client.Services.Administration.ProjectService;
using UI_DSM.Client.Services.Administration.RoleService;
using UI_DSM.Client.Services.ArtifactService;
using UI_DSM.Client.ViewModels.Components.Administration.ModelManagement;
using UI_DSM.Client.ViewModels.Pages.Administration.ProjectPages;
using UI_DSM.Shared.Models;
using UI_DSM.Shared.Types;
Expand All @@ -40,6 +42,8 @@ public class ProjectPageTestFixture
private Mock<IProjectService> projectService;
private Mock<IParticipantService> participantService;
private Mock<IRoleService> roleService;
private Mock<IArtifactService> artifactService;
private Mock<ICometConnectionViewModel> cometConnexionViewModel;

[SetUp]
public void Setup()
Expand All @@ -48,7 +52,12 @@ public void Setup()
this.projectService = new Mock<IProjectService>();
this.participantService = new Mock<IParticipantService>();
this.roleService = new Mock<IRoleService>();
this.viewModel = new ProjectPageViewModel(this.projectService.Object, this.participantService.Object, this.roleService.Object);
this.cometConnexionViewModel = new Mock<ICometConnectionViewModel>();
this.artifactService = new Mock<IArtifactService>();

this.viewModel = new ProjectPageViewModel(this.projectService.Object, this.participantService.Object, this.roleService.Object,
this.cometConnexionViewModel.Object, this.artifactService.Object);

this.context.Services.AddSingleton(this.viewModel);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// --------------------------------------------------------------------------------------------------------
// <copyright file="CometServiceTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2022 RHEA System S.A.
//
// Author: Antoine Théate, Sam Gerené, Alex Vorobiev, Alexander van Delft, Martin Risseeuw, Nabil Abbar
//
// This file is part of UI-DSM.
// The UI-DSM web application is used to review an ECSS-E-TM-10-25 model.
//
// The UI-DSM application is provided to the community under the Apache License 2.0.
// </copyright>
// --------------------------------------------------------------------------------------------------------

namespace UI_DSM.Client.Tests.Services.Administration.CometService
{
using System.Net;

using NUnit.Framework;

using RichardSzalay.MockHttp;

using UI_DSM.Client.Services;
using UI_DSM.Client.Services.Administration.CometService;
using UI_DSM.Client.Services.JsonDeserializerProvider;
using UI_DSM.Serializer.Json;
using UI_DSM.Shared.DTO.CometData;

[TestFixture]
public class CometServiceTestFixture
{
private CometService service;
private MockHttpMessageHandler httpMessageHandler;
private IJsonService jsonService;

[SetUp]
public void Setup()
{
this.httpMessageHandler = new MockHttpMessageHandler();
var httpClient = this.httpMessageHandler.ToHttpClient();
httpClient.BaseAddress = new Uri("http://localhost/api");

ServiceBase.RegisterService<CometService>();
this.jsonService = new JsonService(new JsonDeserializer(), new JsonSerializer());
this.service = new CometService(httpClient, this.jsonService);
}

[Test]
public async Task VerifyLogin()
{
var httpResponse = new HttpResponseMessage();
var request = this.httpMessageHandler.When(HttpMethod.Post, "/Comet/Login");

var cometAuthentication = new CometAuthenticationData();

request.Respond(_ => httpResponse);
Assert.That(async () => await this.service.Login(cometAuthentication), Throws.Exception);

httpResponse.Content = new StringContent(this.jsonService.Serialize(new CometAuthenticationResponse()
{
IsRequestSuccessful = false
}));

Assert.That((await this.service.Login(cometAuthentication)).IsRequestSuccessful, Is.False);

httpResponse.Content = new StringContent(this.jsonService.Serialize(new CometAuthenticationResponse()
{
SessionId = Guid.NewGuid(),
IsRequestSuccessful = true
}));

Assert.That((await this.service.Login(cometAuthentication)).IsRequestSuccessful, Is.True);
}

[Test]
public async Task VerifyLogout()
{
var sessionId = Guid.NewGuid();
var httpResponse = new HttpResponseMessage();
httpResponse.StatusCode = HttpStatusCode.NotFound;
var request = this.httpMessageHandler.When(HttpMethod.Delete, $"/Comet/{sessionId}");
request.Respond(_ => httpResponse);

Assert.That(await this.service.Logout(sessionId), Is.False);

httpResponse.StatusCode = HttpStatusCode.OK;
Assert.That(await this.service.Logout(sessionId), Is.True);
}

[Test]
public async Task VerifyGetAvailableEngineeringModels()
{
var sessionId = Guid.NewGuid();
var httpResponse = new HttpResponseMessage();
httpResponse.StatusCode = HttpStatusCode.NotFound;
var request = this.httpMessageHandler.When(HttpMethod.Get, $"/Comet/{sessionId}/Models");
request.Respond(_ => httpResponse);

Assert.That(async () => await this.service.GetAvailableEngineeringModels(sessionId), Throws.Exception);

httpResponse.StatusCode = HttpStatusCode.OK;

var modelDataResponse = new ModelsDataResponse()
{
IsRequestSuccessful = true,
};

httpResponse.Content = new StringContent(this.jsonService.Serialize(modelDataResponse));
Assert.That((await this.service.GetAvailableEngineeringModels(sessionId)).IsRequestSuccessful, Is.True);
}

[Test]
public async Task VerifyUploadIteration()
{
var sessionId = Guid.NewGuid();
var httpResponse = new HttpResponseMessage();
var request = this.httpMessageHandler.When(HttpMethod.Post, $"/Comet/{sessionId}/Models/Upload");
request.Respond(_ => httpResponse);

var modelUploadResponse = new ModelUploadResponse()
{
IsRequestSuccessful = true
};

httpResponse.Content = new StringContent(this.jsonService.Serialize(modelUploadResponse));
Assert.That((await this.service.UploadIteration(sessionId, Guid.NewGuid(),Guid.NewGuid())).IsRequestSuccessful, Is.True);
}
}
}
Loading