-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #481 from RHEAGROUP/Feat/move-bookconfiguration-to…
…-configurationservices Feat/add-namingconventions-service-and-cherrypick
- Loading branch information
Showing
12 changed files
with
802 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
COMET.Web.Common.Tests/Resources/configuration/naming_convention.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"TestValue1": "TestValue1", | ||
"TestValue2": "TestValue2" | ||
} |
73 changes: 73 additions & 0 deletions
73
...T.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="NamingConventionServiceTestFixture.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar | ||
// | ||
// This file is part of COMET WEB Community Edition | ||
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 | ||
// Annex A and Annex C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
namespace COMET.Web.Common.Tests.Services.NamingConventionService | ||
{ | ||
using COMET.Web.Common.Server.Services.NamingConventionService; | ||
using COMET.Web.Common.Services.NamingConventionService; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using Moq; | ||
|
||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class NamingConventionServiceTestFixture | ||
{ | ||
private NamingConventionService<NamingConventionKindTestEnum> service; | ||
private Mock<ILogger<INamingConventionService<NamingConventionKindTestEnum>>> logger; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.logger = new Mock<ILogger<INamingConventionService<NamingConventionKindTestEnum>>>(); | ||
this.service = new NamingConventionService<NamingConventionKindTestEnum>(this.logger.Object); | ||
} | ||
|
||
[Test] | ||
public async Task VerifyInitializationAndGetNamingConvention() | ||
{ | ||
await this.service.InitializeService(); | ||
var enumValues = Enum.GetValues<NamingConventionKindTestEnum>(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
foreach (var namingConventionKind in enumValues) | ||
{ | ||
Assert.That(this.service.GetNamingConventionValue(namingConventionKind), Is.Not.Empty); | ||
} | ||
}); | ||
} | ||
|
||
/// To be used for testing purposes only | ||
public enum NamingConventionKindTestEnum | ||
{ | ||
TestValue1, | ||
TestValue2 | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="CherryPickRunnerTestFixture.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar | ||
// | ||
// This file is part of COMET WEB Community Edition | ||
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 | ||
// Annex A and Annex C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
namespace COMET.Web.Common.Tests.Utilities.CherryPick | ||
{ | ||
using NUnit.Framework; | ||
|
||
using CDP4Common.SiteDirectoryData; | ||
|
||
using COMET.Web.Common.Services.SessionManagement; | ||
using COMET.Web.Common.Utilities.CherryPick; | ||
|
||
using Moq; | ||
|
||
[TestFixture] | ||
public class CherryPickRunnerTestFixture | ||
{ | ||
private CherryPickRunner viewModel; | ||
private Mock<ISessionService> sessionService; | ||
private Mock<INeedCherryPickedData> needCherryPickedData; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.sessionService = new Mock<ISessionService>(); | ||
this.needCherryPickedData = new Mock<INeedCherryPickedData>(); | ||
this.viewModel = new CherryPickRunner(this.sessionService.Object); | ||
} | ||
|
||
[Test] | ||
public async Task VerifyProperties() | ||
{ | ||
Assert.That(this.viewModel.IsCherryPicking, Is.False); | ||
this.viewModel.InitializeProperties(new List<INeedCherryPickedData> { this.needCherryPickedData.Object }); | ||
|
||
this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); | ||
|
||
var propertyInfo = typeof(CherryPickRunner).GetProperty("IsCherryPicking", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); | ||
|
||
propertyInfo?.SetValue(this.viewModel, true, null); | ||
await this.viewModel.RunCherryPick(); | ||
this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny<IEnumerable<IEnumerable<CDP4Common.DTO.Thing>>>()), Times.Never); | ||
|
||
propertyInfo?.SetValue(this.viewModel, false, null); | ||
await this.viewModel.RunCherryPick(); | ||
this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny<IEnumerable<IEnumerable<CDP4Common.DTO.Thing>>>()), Times.Once); | ||
} | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
....Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="NamingConventionServiceTestFixture.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar | ||
// | ||
// This file is part of COMET WEB Community Edition | ||
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 | ||
// Annex A and Annex C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace COMET.Web.Common.Tests.WebAssembly.Services.NamingConventionService | ||
{ | ||
using System.Net; | ||
|
||
using COMET.Web.Common.Services.NamingConventionService; | ||
using COMET.Web.Common.Test.Helpers; | ||
using COMET.Web.Common.WebAssembly.Services.NamingConventionService; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using Moq; | ||
|
||
using NUnit.Framework; | ||
|
||
using RichardSzalay.MockHttp; | ||
|
||
[TestFixture] | ||
public class NamingConventionServiceTestFixture | ||
{ | ||
private NamingConventionService<NamingConventionKindTestEnum> service; | ||
private MockHttpMessageHandler mockHttpMessageHandler; | ||
private Mock<ILogger<INamingConventionService<NamingConventionKindTestEnum>>> logger; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.mockHttpMessageHandler = new MockHttpMessageHandler(); | ||
var httpClient = this.mockHttpMessageHandler.ToHttpClient(); | ||
httpClient.BaseAddress = new Uri("http://localhost/"); | ||
this.logger = new Mock<ILogger<INamingConventionService<NamingConventionKindTestEnum>>>(); | ||
this.service = new NamingConventionService<NamingConventionKindTestEnum>(this.logger.Object, httpClient); | ||
} | ||
|
||
[Test] | ||
public async Task VerifyService() | ||
{ | ||
this.mockHttpMessageHandler.When(HttpMethod.Get, "/_content/CDP4.WEB.Common/naming_convention.json") | ||
.Throw(new Exception()); | ||
|
||
await this.service.InitializeService(); | ||
this.logger.Verify(LogLevel.Critical, o => o!.ToString()!.Contains("Exception has been raised"), Times.Once()); | ||
|
||
this.mockHttpMessageHandler.ResetBackendDefinitions(); | ||
|
||
var httpResponse = new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.InternalServerError | ||
}; | ||
|
||
this.mockHttpMessageHandler.When(HttpMethod.Get, "/_content/CDP4.WEB.Common/naming_convention.json") | ||
.Respond(_ => httpResponse); | ||
|
||
await this.service.InitializeService(); | ||
this.logger.Verify(LogLevel.Error, o => o!.ToString()!.Contains("Error fetching naming conventions. Status code:"), Times.Once()); | ||
|
||
httpResponse.StatusCode = HttpStatusCode.NotFound; | ||
|
||
await this.service.InitializeService(); | ||
this.logger.Verify(LogLevel.Error, o => o!.ToString()!.Contains("Naming conventions file not found at "), Times.Once()); | ||
|
||
httpResponse.StatusCode = HttpStatusCode.OK; | ||
|
||
var json = """ | ||
{ | ||
"TestValue1": "TestValue1", | ||
"TestValue2": "TestValue2" | ||
} | ||
"""; | ||
|
||
httpResponse.Content = new StringContent(json); | ||
await this.service.InitializeService(); | ||
|
||
var enumValues = Enum.GetValues<NamingConventionKindTestEnum>(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
foreach (var namingConventionKind in enumValues) | ||
{ | ||
Assert.That(this.service.GetNamingConventionValue(namingConventionKind), Is.Not.Empty); | ||
} | ||
}); | ||
} | ||
|
||
/// To be used for testing purposes only | ||
public enum NamingConventionKindTestEnum | ||
{ | ||
TestValue1, | ||
TestValue2 | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="NamingConventionService.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar | ||
// | ||
// This file is part of COMET WEB Community Edition | ||
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 | ||
// Annex A and Annex C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace COMET.Web.Common.Server.Services.NamingConventionService | ||
{ | ||
using System.Text.Json; | ||
|
||
using COMET.Web.Common.Services.NamingConventionService; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
/// <summary> | ||
/// The <see cref="NamingConventionService" /> provides static information based on defined naming convention, like for names of | ||
/// <see cref="Category" /> to use for example | ||
/// </summary> | ||
public class NamingConventionService<TEnum> : BaseNamingConventionService<TEnum> where TEnum : Enum | ||
{ | ||
/// <summary> | ||
/// The <see cref="ILogger{TCategoryName}" /> | ||
/// </summary> | ||
private readonly ILogger<INamingConventionService<TEnum>> logger; | ||
|
||
public NamingConventionService(ILogger<INamingConventionService<TEnum>> logger) : base(logger) | ||
{ | ||
this.logger = logger; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the naming convention configuration | ||
/// </summary> | ||
/// <returns>A <see cref="IReadOnlyDictionary{TKey,TValue}"/> of the naming convention configuration</returns> | ||
protected override async Task<IReadOnlyDictionary<string, string>> GetNamingConventionConfiguration() | ||
{ | ||
try | ||
{ | ||
var namingConvention = JsonSerializer.Deserialize<Dictionary<string, string>>(await File.ReadAllTextAsync(Path.Combine("Resources", "configuration", "naming_convention.json")))!; | ||
return new Dictionary<string, string>(namingConvention, StringComparer.OrdinalIgnoreCase); | ||
} | ||
catch (Exception e) | ||
{ | ||
this.logger.LogError(e, "Error while getting the naming convention configuration file."); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.