From b8c333cb035cb5618dad9ae1c10bc60d312be23f Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:07:02 +0100 Subject: [PATCH 01/13] Create the CherryPickRunner on the common lib --- .../CherryPick/CherryPickRunnerTestFixture.cs | 66 +++++++++++ .../Utilities/CherryPick/CherryPickRunner.cs | 110 ++++++++++++++++++ .../Utilities/CherryPick/ICherryPickRunner.cs | 50 ++++++++ .../CherryPick/INeedCherryPickedData.cs | 54 +++++++++ 4 files changed, 280 insertions(+) create mode 100644 COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs create mode 100644 COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs create mode 100644 COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs create mode 100644 COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs diff --git a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs new file mode 100644 index 00000000..1ea7499b --- /dev/null +++ b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs @@ -0,0 +1,66 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// 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. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.Utilities.CherryPick; + +using NUnit.Framework; + +using CDP4Common.SiteDirectoryData; + +using Moq; + +[TestFixture] +public class CherryPickRunnerTestFixture +{ + private Common.Utilities.CherryPick.CherryPickRunner viewModel; + private Mock sessionService; + private Mock needCherryPickedData; + + [SetUp] + public void Setup() + { + this.sessionService = new Mock(); + this.needCherryPickedData = new Mock(); + this.viewModel = new Common.Utilities.CherryPick.CherryPickRunner(this.sessionService.Object); + } + + [Test] + public async Task VerifyProperties() + { + Assert.That(this.viewModel.IsCherryPicking, Is.False); + this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); + + this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); + + var propertyInfo = typeof(Common.Utilities.CherryPick.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>>()), Times.Never); + + propertyInfo?.SetValue(this.viewModel, false, null); + await this.viewModel.RunCherryPick(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs b/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs new file mode 100644 index 00000000..c9bc990c --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs @@ -0,0 +1,110 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.Services.SessionManagement; + + /// + /// Utility class that could run CherryPick query for + /// + public class CherryPickRunner : ICherryPickRunner + { + /// + /// Gets the collection of + /// + private readonly List NeedCherryPicked = new(); + + /// + /// Gets the + /// + protected readonly ISessionService SessionService; + + /// + /// Initializes a new + /// + /// The + public CherryPickRunner(ISessionService sessionService) + { + this.SessionService = sessionService; + } + + /// + /// Asserts that the cherrypick feature is on going + /// + public bool IsCherryPicking { get; private set; } + + /// + /// Initializes the internal properties + /// + /// A collection of + public void InitializeProperties(IEnumerable needCherryPicked) + { + this.NeedCherryPicked.Clear(); + this.NeedCherryPicked.AddRange(needCherryPicked); + } + + /// + /// Runs the cherrypick features based on data required from + /// + /// A + public async Task RunCherryPick() + { + if (this.IsCherryPicking) + { + return; + } + + this.IsCherryPicking = true; + var classKinds = this.NeedCherryPicked.SelectMany(x => x.ClassKindsOfInterest).Distinct(); + var categoriesName = this.NeedCherryPicked.SelectMany(x => x.CategoriesOfInterest).Distinct(); + + var categories = new List(); + + foreach (var referenceDataLibrary in this.SessionService.Session.RetrieveSiteDirectory().AvailableReferenceDataLibraries()) + { + categories.AddRange(referenceDataLibrary.DefinedCategory + .Where(x => categoriesName.Contains(x.Name)) + .ToList()); + } + + var availableEngineeringModelSetups = this.SessionService.GetParticipantModels().ToList(); + + var cherryPicks = availableEngineeringModelSetups.Select(engineeringModelSetup => this.SessionService.Session.CherryPick(engineeringModelSetup.EngineeringModelIid, engineeringModelSetup.IterationSetup.Single(x => x.FrozenOn == null).IterationIid, classKinds, categories.Select(x => x.Iid))) + .ToList(); + + var results = (await Task.WhenAll(cherryPicks)).Where(x => x.Any()).ToList(); + + foreach (var needCherryPickedData in this.NeedCherryPicked) + { + needCherryPickedData.ProcessCherryPickedData(results); + } + + this.IsCherryPicking = false; + } + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs b/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs new file mode 100644 index 00000000..aa8c4e32 --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs @@ -0,0 +1,50 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + /// + /// Utility class that could run CherryPick query for + /// + public interface ICherryPickRunner + { + /// + /// Asserts that the cherrypick feature is on going + /// + bool IsCherryPicking { get; } + + /// + /// Initializes the internal properties + /// + /// A collection of + void InitializeProperties(IEnumerable needCherryPicked); + + /// + /// Runs the cherrypick features based on data required from + /// + /// A + Task RunCherryPick(); + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs b/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs new file mode 100644 index 00000000..44d012ef --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs @@ -0,0 +1,54 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + using CDP4Common.CommonData; + using CDP4Common.SiteDirectoryData; + + using Thing = CDP4Common.DTO.Thing; + + /// + /// Interface that define that an object needs data that comes from CherryPick feature + /// + public interface INeedCherryPickedData + { + /// + /// Gets the collection of name that this object is interested on + /// + public IReadOnlyCollection CategoriesOfInterest { get; } + + /// + /// Gets the collection of that this object is interested on + /// + public IReadOnlyCollection ClassKindsOfInterest { get; } + + /// + /// Process Cherry picked data + /// + /// A collection of collection of + public void ProcessCherryPickedData(IEnumerable> cherryPickedData); + } +} From d4d0c381c36e3bb46bb3ab8f2c4f36a7211af42c Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:07:20 +0100 Subject: [PATCH 02/13] Create the NamingConventionService on the common lib and adapt it so it can work for any type of enum that is provided via IOC --- .../COMET.Web.Common.Tests.csproj | 4 + .../configuration/naming_convention.json | 4 + .../NamingConventionServiceTestFixture.cs | 70 +++++++++++ .../INamingConventionService.cs | 52 +++++++++ .../NamingConventionService.cs | 109 ++++++++++++++++++ 5 files changed, 239 insertions(+) create mode 100644 COMET.Web.Common.Tests/Resources/configuration/naming_convention.json create mode 100644 COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs create mode 100644 COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs create mode 100644 COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs diff --git a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj index 00522345..04700911 100644 --- a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj +++ b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj @@ -35,6 +35,10 @@ true PreserveNewest + + + Always + diff --git a/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json b/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json new file mode 100644 index 00000000..5ee08a20 --- /dev/null +++ b/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json @@ -0,0 +1,4 @@ +{ + "TestValue1": "TestValue1", + "TestValue2": "TestValue2" +} \ No newline at end of file diff --git a/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs new file mode 100644 index 00000000..4582a397 --- /dev/null +++ b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs @@ -0,0 +1,70 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// 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. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.Services.NamingConventionService +{ + using COMET.Web.Common.Services.NamingConventionService; + + using Microsoft.Extensions.Logging; + + using Moq; + + using NUnit.Framework; + + [TestFixture] + public class NamingConventionServiceTestFixture + { + private NamingConventionService service; + private Mock>> logger; + + [SetUp] + public void Setup() + { + this.logger = new Mock>>(); + this.service = new NamingConventionService(this.logger.Object); + } + + [Test] + public async Task VerifyInitializationAndGetNamingConvention() + { + await this.service.InitializeService(); + var enumValues = Enum.GetValues(); + + foreach (var namingConventionKind in enumValues) + { + Assert.Multiple(() => + { + Assert.That(this.service.GetNamingConventionValue(namingConventionKind), Is.Not.Empty); + }); + } + } + + /// To be used for testing purposes only + public enum NamingConventionKindTestEnum + { + TestValue1, + TestValue2 + } + } +} diff --git a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs new file mode 100644 index 00000000..dc559dbe --- /dev/null +++ b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs @@ -0,0 +1,52 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// 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. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Services.NamingConventionService +{ + /// + /// The provides static information based on defined naming convention, like for names of to use for example + /// + public interface INamingConventionService where TEnum : Enum + { + /// + /// Initializes this service + /// + /// A + Task InitializeService(); + + /// + /// Gets the value for naming convention + /// + /// The naming convention key + /// The defined naming convention, if exists + string GetNamingConventionValue(string namingConventionKey); + + /// + /// Gets the value for naming convention + /// + /// The + /// The defined naming convention, if exists + string GetNamingConventionValue(TEnum namingConventionKind); + } +} diff --git a/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs new file mode 100644 index 00000000..bc6c2985 --- /dev/null +++ b/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs @@ -0,0 +1,109 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// 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. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Services.NamingConventionService +{ + using System.Text.Json; + + using Microsoft.Extensions.Logging; + + /// + /// The provides static information based on defined naming convention, like for names of + /// to use for example + /// + public class NamingConventionService : INamingConventionService where TEnum : Enum + { + /// + /// that holds the defined naming convention + /// + private readonly Dictionary definedNaming = new(StringComparer.OrdinalIgnoreCase); + + /// + /// The + /// + private readonly ILogger> logger; + + /// + /// Initializes a new instance of the class. + /// + /// The + public NamingConventionService(ILogger> logger) + { + this.logger = logger; + } + + /// + /// Initializes this service + /// + /// A + public async Task InitializeService() + { + Dictionary namingConvention; + + try + { + namingConvention = JsonSerializer.Deserialize>(await File.ReadAllTextAsync(Path.Combine("Resources", "configuration", "naming_convention.json")))!; + } + catch (Exception e) + { + this.logger.LogError(e, "Error while getting the naming convention configuration file."); + return; + } + + namingConvention = new Dictionary(namingConvention, StringComparer.OrdinalIgnoreCase); + + foreach (var namingConventionKind in Enum.GetValues(typeof(TEnum))) + { + if (namingConvention.TryGetValue(namingConventionKind.ToString(), out var namingConventionValue)) + { + this.definedNaming[namingConventionKind.ToString()] = namingConventionValue; + } + else + { + this.logger.LogWarning("{namingConventionKind} is missing from the Naming Convention configuration file", namingConventionKind.ToString()); + } + } + } + + /// + /// Gets the value for naming convention + /// + /// The naming convention key + /// The defined naming convention, if exists + public string GetNamingConventionValue(string namingConventionKey) + { + return this.definedNaming.TryGetValue(namingConventionKey, out var namingConventionValue) ? namingConventionValue : string.Empty; + } + + /// + /// Gets the value for naming convention + /// + /// The + /// The defined naming convention, if exists + public string GetNamingConventionValue(TEnum namingConventionKind) + { + return this.GetNamingConventionValue(namingConventionKind.ToString()); + } + } +} From 242dcdef9d450f589ea6fe69304a99e51a5cbaf8 Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:10:18 +0100 Subject: [PATCH 03/13] Update the namespace block for the cherry pick runner test fixture --- .../CherryPick/CherryPickRunnerTestFixture.cs | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs index 1ea7499b..5155be51 100644 --- a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs +++ b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs @@ -22,45 +22,46 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.Tests.Utilities.CherryPick; - -using NUnit.Framework; - -using CDP4Common.SiteDirectoryData; +namespace COMET.Web.Common.Tests.Utilities.CherryPick +{ + using NUnit.Framework; -using Moq; + using CDP4Common.SiteDirectoryData; -[TestFixture] -public class CherryPickRunnerTestFixture -{ - private Common.Utilities.CherryPick.CherryPickRunner viewModel; - private Mock sessionService; - private Mock needCherryPickedData; + using Moq; - [SetUp] - public void Setup() + [TestFixture] + public class CherryPickRunnerTestFixture { - this.sessionService = new Mock(); - this.needCherryPickedData = new Mock(); - this.viewModel = new Common.Utilities.CherryPick.CherryPickRunner(this.sessionService.Object); - } + private Common.Utilities.CherryPick.CherryPickRunner viewModel; + private Mock sessionService; + private Mock needCherryPickedData; - [Test] - public async Task VerifyProperties() - { - Assert.That(this.viewModel.IsCherryPicking, Is.False); - this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); + [SetUp] + public void Setup() + { + this.sessionService = new Mock(); + this.needCherryPickedData = new Mock(); + this.viewModel = new Common.Utilities.CherryPick.CherryPickRunner(this.sessionService.Object); + } + + [Test] + public async Task VerifyProperties() + { + Assert.That(this.viewModel.IsCherryPicking, Is.False); + this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); - this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); + this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); - var propertyInfo = typeof(Common.Utilities.CherryPick.CherryPickRunner).GetProperty("IsCherryPicking", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); + var propertyInfo = typeof(Common.Utilities.CherryPick.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>>()), Times.Never); + propertyInfo?.SetValue(this.viewModel, true, null); + await this.viewModel.RunCherryPick(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Never); - propertyInfo?.SetValue(this.viewModel, false, null); - await this.viewModel.RunCherryPick(); - this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + propertyInfo?.SetValue(this.viewModel, false, null); + await this.viewModel.RunCherryPick(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + } } } From 71a1f8f25d4571a509012aa4014d6796af7f6b1b Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:07:02 +0100 Subject: [PATCH 04/13] Create the CherryPickRunner on the common lib --- .../CherryPick/CherryPickRunnerTestFixture.cs | 66 +++++++++++ .../Utilities/CherryPick/CherryPickRunner.cs | 110 ++++++++++++++++++ .../Utilities/CherryPick/ICherryPickRunner.cs | 50 ++++++++ .../CherryPick/INeedCherryPickedData.cs | 54 +++++++++ 4 files changed, 280 insertions(+) create mode 100644 COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs create mode 100644 COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs create mode 100644 COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs create mode 100644 COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs diff --git a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs new file mode 100644 index 00000000..1ea7499b --- /dev/null +++ b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs @@ -0,0 +1,66 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// 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. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.Utilities.CherryPick; + +using NUnit.Framework; + +using CDP4Common.SiteDirectoryData; + +using Moq; + +[TestFixture] +public class CherryPickRunnerTestFixture +{ + private Common.Utilities.CherryPick.CherryPickRunner viewModel; + private Mock sessionService; + private Mock needCherryPickedData; + + [SetUp] + public void Setup() + { + this.sessionService = new Mock(); + this.needCherryPickedData = new Mock(); + this.viewModel = new Common.Utilities.CherryPick.CherryPickRunner(this.sessionService.Object); + } + + [Test] + public async Task VerifyProperties() + { + Assert.That(this.viewModel.IsCherryPicking, Is.False); + this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); + + this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); + + var propertyInfo = typeof(Common.Utilities.CherryPick.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>>()), Times.Never); + + propertyInfo?.SetValue(this.viewModel, false, null); + await this.viewModel.RunCherryPick(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs b/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs new file mode 100644 index 00000000..c9bc990c --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs @@ -0,0 +1,110 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.Services.SessionManagement; + + /// + /// Utility class that could run CherryPick query for + /// + public class CherryPickRunner : ICherryPickRunner + { + /// + /// Gets the collection of + /// + private readonly List NeedCherryPicked = new(); + + /// + /// Gets the + /// + protected readonly ISessionService SessionService; + + /// + /// Initializes a new + /// + /// The + public CherryPickRunner(ISessionService sessionService) + { + this.SessionService = sessionService; + } + + /// + /// Asserts that the cherrypick feature is on going + /// + public bool IsCherryPicking { get; private set; } + + /// + /// Initializes the internal properties + /// + /// A collection of + public void InitializeProperties(IEnumerable needCherryPicked) + { + this.NeedCherryPicked.Clear(); + this.NeedCherryPicked.AddRange(needCherryPicked); + } + + /// + /// Runs the cherrypick features based on data required from + /// + /// A + public async Task RunCherryPick() + { + if (this.IsCherryPicking) + { + return; + } + + this.IsCherryPicking = true; + var classKinds = this.NeedCherryPicked.SelectMany(x => x.ClassKindsOfInterest).Distinct(); + var categoriesName = this.NeedCherryPicked.SelectMany(x => x.CategoriesOfInterest).Distinct(); + + var categories = new List(); + + foreach (var referenceDataLibrary in this.SessionService.Session.RetrieveSiteDirectory().AvailableReferenceDataLibraries()) + { + categories.AddRange(referenceDataLibrary.DefinedCategory + .Where(x => categoriesName.Contains(x.Name)) + .ToList()); + } + + var availableEngineeringModelSetups = this.SessionService.GetParticipantModels().ToList(); + + var cherryPicks = availableEngineeringModelSetups.Select(engineeringModelSetup => this.SessionService.Session.CherryPick(engineeringModelSetup.EngineeringModelIid, engineeringModelSetup.IterationSetup.Single(x => x.FrozenOn == null).IterationIid, classKinds, categories.Select(x => x.Iid))) + .ToList(); + + var results = (await Task.WhenAll(cherryPicks)).Where(x => x.Any()).ToList(); + + foreach (var needCherryPickedData in this.NeedCherryPicked) + { + needCherryPickedData.ProcessCherryPickedData(results); + } + + this.IsCherryPicking = false; + } + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs b/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs new file mode 100644 index 00000000..aa8c4e32 --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs @@ -0,0 +1,50 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + /// + /// Utility class that could run CherryPick query for + /// + public interface ICherryPickRunner + { + /// + /// Asserts that the cherrypick feature is on going + /// + bool IsCherryPicking { get; } + + /// + /// Initializes the internal properties + /// + /// A collection of + void InitializeProperties(IEnumerable needCherryPicked); + + /// + /// Runs the cherrypick features based on data required from + /// + /// A + Task RunCherryPick(); + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs b/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs new file mode 100644 index 00000000..44d012ef --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs @@ -0,0 +1,54 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + using CDP4Common.CommonData; + using CDP4Common.SiteDirectoryData; + + using Thing = CDP4Common.DTO.Thing; + + /// + /// Interface that define that an object needs data that comes from CherryPick feature + /// + public interface INeedCherryPickedData + { + /// + /// Gets the collection of name that this object is interested on + /// + public IReadOnlyCollection CategoriesOfInterest { get; } + + /// + /// Gets the collection of that this object is interested on + /// + public IReadOnlyCollection ClassKindsOfInterest { get; } + + /// + /// Process Cherry picked data + /// + /// A collection of collection of + public void ProcessCherryPickedData(IEnumerable> cherryPickedData); + } +} From eab01052f2321ebc4fdc0a3e396933cb11682197 Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:07:20 +0100 Subject: [PATCH 05/13] Create the NamingConventionService on the common lib and adapt it so it can work for any type of enum that is provided via IOC --- .../COMET.Web.Common.Tests.csproj | 2 + .../configuration/naming_convention.json | 4 + .../NamingConventionServiceTestFixture.cs | 70 +++++++++++ .../INamingConventionService.cs | 52 +++++++++ .../NamingConventionService.cs | 109 ++++++++++++++++++ 5 files changed, 237 insertions(+) create mode 100644 COMET.Web.Common.Tests/Resources/configuration/naming_convention.json create mode 100644 COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs create mode 100644 COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs create mode 100644 COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs diff --git a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj index 1c357f38..deac5b67 100644 --- a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj +++ b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj @@ -37,6 +37,8 @@ + + Always diff --git a/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json b/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json new file mode 100644 index 00000000..5ee08a20 --- /dev/null +++ b/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json @@ -0,0 +1,4 @@ +{ + "TestValue1": "TestValue1", + "TestValue2": "TestValue2" +} \ No newline at end of file diff --git a/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs new file mode 100644 index 00000000..4582a397 --- /dev/null +++ b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs @@ -0,0 +1,70 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// 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. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.Services.NamingConventionService +{ + using COMET.Web.Common.Services.NamingConventionService; + + using Microsoft.Extensions.Logging; + + using Moq; + + using NUnit.Framework; + + [TestFixture] + public class NamingConventionServiceTestFixture + { + private NamingConventionService service; + private Mock>> logger; + + [SetUp] + public void Setup() + { + this.logger = new Mock>>(); + this.service = new NamingConventionService(this.logger.Object); + } + + [Test] + public async Task VerifyInitializationAndGetNamingConvention() + { + await this.service.InitializeService(); + var enumValues = Enum.GetValues(); + + foreach (var namingConventionKind in enumValues) + { + Assert.Multiple(() => + { + Assert.That(this.service.GetNamingConventionValue(namingConventionKind), Is.Not.Empty); + }); + } + } + + /// To be used for testing purposes only + public enum NamingConventionKindTestEnum + { + TestValue1, + TestValue2 + } + } +} diff --git a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs new file mode 100644 index 00000000..dc559dbe --- /dev/null +++ b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs @@ -0,0 +1,52 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// 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. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Services.NamingConventionService +{ + /// + /// The provides static information based on defined naming convention, like for names of to use for example + /// + public interface INamingConventionService where TEnum : Enum + { + /// + /// Initializes this service + /// + /// A + Task InitializeService(); + + /// + /// Gets the value for naming convention + /// + /// The naming convention key + /// The defined naming convention, if exists + string GetNamingConventionValue(string namingConventionKey); + + /// + /// Gets the value for naming convention + /// + /// The + /// The defined naming convention, if exists + string GetNamingConventionValue(TEnum namingConventionKind); + } +} diff --git a/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs new file mode 100644 index 00000000..bc6c2985 --- /dev/null +++ b/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs @@ -0,0 +1,109 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// 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. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Services.NamingConventionService +{ + using System.Text.Json; + + using Microsoft.Extensions.Logging; + + /// + /// The provides static information based on defined naming convention, like for names of + /// to use for example + /// + public class NamingConventionService : INamingConventionService where TEnum : Enum + { + /// + /// that holds the defined naming convention + /// + private readonly Dictionary definedNaming = new(StringComparer.OrdinalIgnoreCase); + + /// + /// The + /// + private readonly ILogger> logger; + + /// + /// Initializes a new instance of the class. + /// + /// The + public NamingConventionService(ILogger> logger) + { + this.logger = logger; + } + + /// + /// Initializes this service + /// + /// A + public async Task InitializeService() + { + Dictionary namingConvention; + + try + { + namingConvention = JsonSerializer.Deserialize>(await File.ReadAllTextAsync(Path.Combine("Resources", "configuration", "naming_convention.json")))!; + } + catch (Exception e) + { + this.logger.LogError(e, "Error while getting the naming convention configuration file."); + return; + } + + namingConvention = new Dictionary(namingConvention, StringComparer.OrdinalIgnoreCase); + + foreach (var namingConventionKind in Enum.GetValues(typeof(TEnum))) + { + if (namingConvention.TryGetValue(namingConventionKind.ToString(), out var namingConventionValue)) + { + this.definedNaming[namingConventionKind.ToString()] = namingConventionValue; + } + else + { + this.logger.LogWarning("{namingConventionKind} is missing from the Naming Convention configuration file", namingConventionKind.ToString()); + } + } + } + + /// + /// Gets the value for naming convention + /// + /// The naming convention key + /// The defined naming convention, if exists + public string GetNamingConventionValue(string namingConventionKey) + { + return this.definedNaming.TryGetValue(namingConventionKey, out var namingConventionValue) ? namingConventionValue : string.Empty; + } + + /// + /// Gets the value for naming convention + /// + /// The + /// The defined naming convention, if exists + public string GetNamingConventionValue(TEnum namingConventionKind) + { + return this.GetNamingConventionValue(namingConventionKind.ToString()); + } + } +} From ae34f8de7477aa7339b4b50806791f1ef65ae3d6 Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:10:18 +0100 Subject: [PATCH 06/13] Update the namespace block for the cherry pick runner test fixture --- .../CherryPick/CherryPickRunnerTestFixture.cs | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs index 1ea7499b..5155be51 100644 --- a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs +++ b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs @@ -22,45 +22,46 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.Tests.Utilities.CherryPick; - -using NUnit.Framework; - -using CDP4Common.SiteDirectoryData; +namespace COMET.Web.Common.Tests.Utilities.CherryPick +{ + using NUnit.Framework; -using Moq; + using CDP4Common.SiteDirectoryData; -[TestFixture] -public class CherryPickRunnerTestFixture -{ - private Common.Utilities.CherryPick.CherryPickRunner viewModel; - private Mock sessionService; - private Mock needCherryPickedData; + using Moq; - [SetUp] - public void Setup() + [TestFixture] + public class CherryPickRunnerTestFixture { - this.sessionService = new Mock(); - this.needCherryPickedData = new Mock(); - this.viewModel = new Common.Utilities.CherryPick.CherryPickRunner(this.sessionService.Object); - } + private Common.Utilities.CherryPick.CherryPickRunner viewModel; + private Mock sessionService; + private Mock needCherryPickedData; - [Test] - public async Task VerifyProperties() - { - Assert.That(this.viewModel.IsCherryPicking, Is.False); - this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); + [SetUp] + public void Setup() + { + this.sessionService = new Mock(); + this.needCherryPickedData = new Mock(); + this.viewModel = new Common.Utilities.CherryPick.CherryPickRunner(this.sessionService.Object); + } + + [Test] + public async Task VerifyProperties() + { + Assert.That(this.viewModel.IsCherryPicking, Is.False); + this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); - this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); + this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); - var propertyInfo = typeof(Common.Utilities.CherryPick.CherryPickRunner).GetProperty("IsCherryPicking", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); + var propertyInfo = typeof(Common.Utilities.CherryPick.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>>()), Times.Never); + propertyInfo?.SetValue(this.viewModel, true, null); + await this.viewModel.RunCherryPick(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Never); - propertyInfo?.SetValue(this.viewModel, false, null); - await this.viewModel.RunCherryPick(); - this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + propertyInfo?.SetValue(this.viewModel, false, null); + await this.viewModel.RunCherryPick(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + } } } From 49849fc915bc3d8ca7af90f89f6f9c8d85605c30 Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:12:45 +0100 Subject: [PATCH 07/13] Fix merge issue --- COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj index deac5b67..94032e25 100644 --- a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj +++ b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj @@ -35,9 +35,9 @@ true PreserveNewest - - - + + Always + Always From b4679e60e569f24db433c71d51a549ef7d93e90a Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:17:14 +0100 Subject: [PATCH 08/13] Fix the copyright on NamingConventionService --- .../INamingConventionService.cs | 31 ++++++++++--------- .../NamingConventionService.cs | 29 ++++++++--------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs index dc559dbe..f6bbb81c 100644 --- a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs +++ b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs @@ -1,24 +1,25 @@ // -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2023 RHEA System S.A. +// +// Copyright (c) 2023 RHEA System S.A. // -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// 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. +// 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. // -// The COMET WEB Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. +// 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 // -// The COMET WEB Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Affero General Public License for more details. +// 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. // -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . // // -------------------------------------------------------------------------------------------------------------------- diff --git a/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs index bc6c2985..bfa7258b 100644 --- a/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs +++ b/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs @@ -1,24 +1,25 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2023 RHEA System S.A. +// Copyright (c) 2023 RHEA System S.A. // -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// 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. +// 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. // -// The COMET WEB Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. +// 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 // -// The COMET WEB Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Affero General Public License for more details. +// 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. // -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . // // -------------------------------------------------------------------------------------------------------------------- From 78ea60dec493a625c70f46ca98c3761c7ad5c415 Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 15:17:57 +0100 Subject: [PATCH 09/13] Update the test fixtures copyright notice --- .../NamingConventionServiceTestFixture.cs | 30 ++++++++++--------- .../CherryPick/CherryPickRunnerTestFixture.cs | 30 ++++++++++--------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs index 4582a397..8fe89d61 100644 --- a/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs @@ -1,27 +1,29 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2023 RHEA System S.A. +// Copyright (c) 2023 RHEA System S.A. // -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// 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. +// 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. // -// The COMET WEB Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. +// 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 // -// The COMET WEB Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Affero General Public License for more details. +// 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. // -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . // // -------------------------------------------------------------------------------------------------------------------- + namespace COMET.Web.Common.Tests.Services.NamingConventionService { using COMET.Web.Common.Services.NamingConventionService; diff --git a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs index 5155be51..86cffdda 100644 --- a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs +++ b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs @@ -1,27 +1,29 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2023 RHEA System S.A. +// Copyright (c) 2023 RHEA System S.A. // -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// 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. +// 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. // -// The COMET WEB Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. +// 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 // -// The COMET WEB Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Affero General Public License for more details. +// 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. // -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . // // -------------------------------------------------------------------------------------------------------------------- + namespace COMET.Web.Common.Tests.Utilities.CherryPick { using NUnit.Framework; From 4c84a1103a7e87e1e39b98b51af99dd4a98db627 Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Wed, 18 Oct 2023 16:41:49 +0100 Subject: [PATCH 10/13] Refactor the NamingConventionService so that it works for both Server and WASM modes. Add new test fixtures for WASM mode. Add two loading types (file loading and via http request). --- .../NamingConventionServiceTestFixture.cs | 9 +- .../NamingConventionServiceTestFixture.cs | 115 ++++++++++++++++++ .../NamingConventionService.cs | 68 +++++++++++ .../BaseNamingConventionService.cs | 101 +++++++++++++++ .../INamingConventionService.cs | 4 +- .../NamingConventionService.cs | 110 ----------------- .../NamingConventionService.cs | 93 ++++++++++++++ 7 files changed, 385 insertions(+), 115 deletions(-) create mode 100644 COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs create mode 100644 COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs create mode 100644 COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs delete mode 100644 COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs create mode 100644 COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs diff --git a/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs index 8fe89d61..772f1b48 100644 --- a/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs @@ -26,6 +26,7 @@ namespace COMET.Web.Common.Tests.Services.NamingConventionService { + using COMET.Web.Common.Server.Services.NamingConventionService; using COMET.Web.Common.Services.NamingConventionService; using Microsoft.Extensions.Logging; @@ -53,13 +54,13 @@ public async Task VerifyInitializationAndGetNamingConvention() await this.service.InitializeService(); var enumValues = Enum.GetValues(); - foreach (var namingConventionKind in enumValues) + Assert.Multiple(() => { - Assert.Multiple(() => + foreach (var namingConventionKind in enumValues) { Assert.That(this.service.GetNamingConventionValue(namingConventionKind), Is.Not.Empty); - }); - } + } + }); } /// To be used for testing purposes only diff --git a/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs b/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs new file mode 100644 index 00000000..ed59625c --- /dev/null +++ b/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs @@ -0,0 +1,115 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +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 service; + private MockHttpMessageHandler mockHttpMessageHandler; + private Mock>> logger; + + [SetUp] + public void Setup() + { + this.mockHttpMessageHandler = new MockHttpMessageHandler(); + var httpClient = this.mockHttpMessageHandler.ToHttpClient(); + httpClient.BaseAddress = new Uri("http://localhost/"); + this.logger = new Mock>>(); + this.service = new NamingConventionService(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(); + + 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 + } +} diff --git a/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs new file mode 100644 index 00000000..f0f347b3 --- /dev/null +++ b/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs @@ -0,0 +1,68 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Server.Services.NamingConventionService +{ + using System.Text.Json; + + using COMET.Web.Common.Services.NamingConventionService; + + using Microsoft.Extensions.Logging; + + /// + /// The provides static information based on defined naming convention, like for names of + /// to use for example + /// + public class NamingConventionService : BaseNamingConventionService where TEnum : Enum + { + /// + /// The + /// + private readonly ILogger> logger; + + public NamingConventionService(ILogger> logger) : base(logger) + { + this.logger = logger; + } + + /// + /// Gets the naming convention configuration + /// + /// A of the naming convention configuration + public override async Task> GetNamingConventionConfiguration() + { + try + { + var namingConvention = JsonSerializer.Deserialize>(await File.ReadAllTextAsync(Path.Combine("Resources", "configuration", "naming_convention.json")))!; + return new Dictionary(namingConvention, StringComparer.OrdinalIgnoreCase); + } + catch (Exception e) + { + this.logger.LogError(e, "Error while getting the naming convention configuration file."); + throw; + } + } + } +} diff --git a/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs new file mode 100644 index 00000000..c473432c --- /dev/null +++ b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs @@ -0,0 +1,101 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Services.NamingConventionService; + +using Microsoft.Extensions.Logging; + +public class BaseNamingConventionService : INamingConventionService where TEnum : Enum +{ + /// + /// that holds the defined naming convention + /// + private readonly Dictionary definedNaming = new(StringComparer.OrdinalIgnoreCase); + + /// + /// The + /// + private readonly ILogger> logger; + + /// + /// Initializes a new instance of the class. + /// + /// The + protected BaseNamingConventionService(ILogger> logger) + { + this.logger = logger; + } + + /// + /// Initializes this service + /// + /// A + public async Task InitializeService() + { + var namingConvention = await this.GetNamingConventionConfiguration(); + + foreach (var namingConventionKind in Enum.GetValues(typeof(TEnum))) + { + if (namingConvention.TryGetValue(namingConventionKind.ToString(), out var namingConventionValue)) + { + this.definedNaming[namingConventionKind.ToString()] = namingConventionValue; + } + else + { + this.logger.LogWarning("{namingConventionKind} is missing from the Naming Convention configuration file", namingConventionKind.ToString()); + } + } + } + + /// + /// Gets the value for naming convention + /// + /// The naming convention key + /// The defined naming convention, if exists + public string GetNamingConventionValue(string namingConventionKey) + { + return this.definedNaming.TryGetValue(namingConventionKey, out var namingConventionValue) ? namingConventionValue : string.Empty; + } + + /// + /// Gets the value for naming convention + /// + /// The + /// The defined naming convention, if exists + public string GetNamingConventionValue(TEnum namingConventionKind) + { + return this.GetNamingConventionValue(namingConventionKind.ToString()); + } + + /// + /// Gets the naming convention configuration + /// + /// A of the naming convention configuration + /// + public virtual Task> GetNamingConventionConfiguration() + { + throw new NotImplementedException(); + } +} diff --git a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs index f6bbb81c..a44c69f6 100644 --- a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs +++ b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs @@ -28,7 +28,7 @@ namespace COMET.Web.Common.Services.NamingConventionService /// /// The provides static information based on defined naming convention, like for names of to use for example /// - public interface INamingConventionService where TEnum : Enum + public interface INamingConventionService where TEnum : Enum { /// /// Initializes this service @@ -49,5 +49,7 @@ public interface INamingConventionService where TEnum : Enum /// The /// The defined naming convention, if exists string GetNamingConventionValue(TEnum namingConventionKind); + + Task> GetNamingConventionConfiguration(); } } diff --git a/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs deleted file mode 100644 index bfa7258b..00000000 --- a/COMET.Web.Common/Services/NamingConventionService/NamingConventionService.cs +++ /dev/null @@ -1,110 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// 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. -// -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace COMET.Web.Common.Services.NamingConventionService -{ - using System.Text.Json; - - using Microsoft.Extensions.Logging; - - /// - /// The provides static information based on defined naming convention, like for names of - /// to use for example - /// - public class NamingConventionService : INamingConventionService where TEnum : Enum - { - /// - /// that holds the defined naming convention - /// - private readonly Dictionary definedNaming = new(StringComparer.OrdinalIgnoreCase); - - /// - /// The - /// - private readonly ILogger> logger; - - /// - /// Initializes a new instance of the class. - /// - /// The - public NamingConventionService(ILogger> logger) - { - this.logger = logger; - } - - /// - /// Initializes this service - /// - /// A - public async Task InitializeService() - { - Dictionary namingConvention; - - try - { - namingConvention = JsonSerializer.Deserialize>(await File.ReadAllTextAsync(Path.Combine("Resources", "configuration", "naming_convention.json")))!; - } - catch (Exception e) - { - this.logger.LogError(e, "Error while getting the naming convention configuration file."); - return; - } - - namingConvention = new Dictionary(namingConvention, StringComparer.OrdinalIgnoreCase); - - foreach (var namingConventionKind in Enum.GetValues(typeof(TEnum))) - { - if (namingConvention.TryGetValue(namingConventionKind.ToString(), out var namingConventionValue)) - { - this.definedNaming[namingConventionKind.ToString()] = namingConventionValue; - } - else - { - this.logger.LogWarning("{namingConventionKind} is missing from the Naming Convention configuration file", namingConventionKind.ToString()); - } - } - } - - /// - /// Gets the value for naming convention - /// - /// The naming convention key - /// The defined naming convention, if exists - public string GetNamingConventionValue(string namingConventionKey) - { - return this.definedNaming.TryGetValue(namingConventionKey, out var namingConventionValue) ? namingConventionValue : string.Empty; - } - - /// - /// Gets the value for naming convention - /// - /// The - /// The defined naming convention, if exists - public string GetNamingConventionValue(TEnum namingConventionKind) - { - return this.GetNamingConventionValue(namingConventionKind.ToString()); - } - } -} diff --git a/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs new file mode 100644 index 00000000..cb728b2e --- /dev/null +++ b/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs @@ -0,0 +1,93 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.WebAssembly.Services.NamingConventionService +{ + using System.Collections.Immutable; + using System.Net; + using System.Text.Json; + + using COMET.Web.Common.Services.NamingConventionService; + using COMET.Web.Common.Utilities; + + using Microsoft.Extensions.Logging; + + /// + /// The provides static information based on defined naming convention, like for names of + /// to use for example + /// + public class NamingConventionService : BaseNamingConventionService where TEnum : Enum + { + /// + /// The + /// + private readonly ILogger> logger; + + /// + /// The + /// + private readonly HttpClient httpClient; + + public NamingConventionService(ILogger> logger, HttpClient httpClient) : base(logger) + { + this.logger = logger; + this.httpClient = httpClient; + } + + /// + /// Gets the naming convention configuration + /// + /// A of the naming convention configuration + public override async Task> GetNamingConventionConfiguration() + { + try + { + var path = ContentPathBuilder.BuildPath("naming_convention.json"); + var response = await this.httpClient.GetAsync(path); + + if (response.IsSuccessStatusCode) + { + var jsonContent = await response.Content.ReadAsStreamAsync(); + var namingConvention = JsonSerializer.Deserialize>(jsonContent); + return new Dictionary(namingConvention, StringComparer.OrdinalIgnoreCase); + } + + if (response.StatusCode == HttpStatusCode.NotFound) + { + this.logger.LogError("Naming conventions file not found at {path}", path); + return ImmutableDictionary.Empty; + } + + this.logger.LogError("Error fetching naming conventions. Status code: {response}", response.StatusCode); + return ImmutableDictionary.Empty; + } + catch (Exception e) + { + this.logger.LogCritical("Exception has been raised : {message}", e.Message); + return ImmutableDictionary.Empty; + } + } + } +} From 30981949bab7f3a1de0bda1cddc30366ec736e4d Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Thu, 19 Oct 2023 09:57:22 +0100 Subject: [PATCH 11/13] Parse PR feedback: namespace blocks, remove namespace usage, add documentation --- .../CherryPick/CherryPickRunnerTestFixture.cs | 19 +-- .../NamingConventionServiceTestFixture.cs | 135 +++++++++--------- .../BaseNamingConventionService.cs | 126 ++++++++-------- .../INamingConventionService.cs | 6 + .../NamingConventionService.cs | 17 ++- 5 files changed, 159 insertions(+), 144 deletions(-) diff --git a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs index 86cffdda..1b460b8f 100644 --- a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs +++ b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs @@ -30,32 +30,35 @@ namespace COMET.Web.Common.Tests.Utilities.CherryPick using CDP4Common.SiteDirectoryData; + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.Utilities.CherryPick; + using Moq; [TestFixture] public class CherryPickRunnerTestFixture { - private Common.Utilities.CherryPick.CherryPickRunner viewModel; - private Mock sessionService; - private Mock needCherryPickedData; + private CherryPickRunner viewModel; + private Mock sessionService; + private Mock needCherryPickedData; [SetUp] public void Setup() { - this.sessionService = new Mock(); - this.needCherryPickedData = new Mock(); - this.viewModel = new Common.Utilities.CherryPick.CherryPickRunner(this.sessionService.Object); + this.sessionService = new Mock(); + this.needCherryPickedData = new Mock(); + this.viewModel = new CherryPickRunner(this.sessionService.Object); } [Test] public async Task VerifyProperties() { Assert.That(this.viewModel.IsCherryPicking, Is.False); - this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); + this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); - var propertyInfo = typeof(Common.Utilities.CherryPick.CherryPickRunner).GetProperty("IsCherryPicking", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); + var propertyInfo = typeof(CherryPickRunner).GetProperty("IsCherryPicking", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); propertyInfo?.SetValue(this.viewModel, true, null); await this.viewModel.RunCherryPick(); diff --git a/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs b/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs index ed59625c..344cf3fe 100644 --- a/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs @@ -23,93 +23,94 @@ // // -------------------------------------------------------------------------------------------------------------------- -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; +namespace COMET.Web.Common.Tests.WebAssembly.Services.NamingConventionService +{ + using System.Net; -using Microsoft.Extensions.Logging; + using COMET.Web.Common.Services.NamingConventionService; + using COMET.Web.Common.Test.Helpers; + using COMET.Web.Common.WebAssembly.Services.NamingConventionService; -using Moq; + using Microsoft.Extensions.Logging; -using NUnit.Framework; + using Moq; -using RichardSzalay.MockHttp; + using NUnit.Framework; -[TestFixture] -public class NamingConventionServiceTestFixture -{ - private NamingConventionService service; - private MockHttpMessageHandler mockHttpMessageHandler; - private Mock>> logger; + using RichardSzalay.MockHttp; - [SetUp] - public void Setup() + [TestFixture] + public class NamingConventionServiceTestFixture { - this.mockHttpMessageHandler = new MockHttpMessageHandler(); - var httpClient = this.mockHttpMessageHandler.ToHttpClient(); - httpClient.BaseAddress = new Uri("http://localhost/"); - this.logger = new Mock>>(); - this.service = new NamingConventionService(this.logger.Object, httpClient); - } + private NamingConventionService service; + private MockHttpMessageHandler mockHttpMessageHandler; + private Mock>> logger; - [Test] - public async Task VerifyService() - { - this.mockHttpMessageHandler.When(HttpMethod.Get, "/_content/CDP4.WEB.Common/naming_convention.json") - .Throw(new Exception()); + [SetUp] + public void Setup() + { + this.mockHttpMessageHandler = new MockHttpMessageHandler(); + var httpClient = this.mockHttpMessageHandler.ToHttpClient(); + httpClient.BaseAddress = new Uri("http://localhost/"); + this.logger = new Mock>>(); + this.service = new NamingConventionService(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()); + await this.service.InitializeService(); + this.logger.Verify(LogLevel.Critical, o => o!.ToString()!.Contains("Exception has been raised"), Times.Once()); - this.mockHttpMessageHandler.ResetBackendDefinitions(); + this.mockHttpMessageHandler.ResetBackendDefinitions(); - var httpResponse = new HttpResponseMessage() - { - StatusCode = HttpStatusCode.InternalServerError - }; + var httpResponse = new HttpResponseMessage() + { + StatusCode = HttpStatusCode.InternalServerError + }; - this.mockHttpMessageHandler.When(HttpMethod.Get, "/_content/CDP4.WEB.Common/naming_convention.json") - .Respond(_ => httpResponse); + 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()); + 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; + 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()); + 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; + httpResponse.StatusCode = HttpStatusCode.OK; - var json = """ - { - "TestValue1": "TestValue1", - "TestValue2": "TestValue2" - } - """; + var json = """ + { + "TestValue1": "TestValue1", + "TestValue2": "TestValue2" + } + """; - httpResponse.Content = new StringContent(json); - await this.service.InitializeService(); + httpResponse.Content = new StringContent(json); + await this.service.InitializeService(); - var enumValues = Enum.GetValues(); + var enumValues = Enum.GetValues(); - Assert.Multiple(() => - { - foreach (var namingConventionKind in enumValues) + Assert.Multiple(() => { - Assert.That(this.service.GetNamingConventionValue(namingConventionKind), Is.Not.Empty); - } - }); - } - - /// To be used for testing purposes only - public enum NamingConventionKindTestEnum - { - TestValue1, - TestValue2 + 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 + } } } diff --git a/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs index c473432c..6b60af21 100644 --- a/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs +++ b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs @@ -23,79 +23,85 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.Services.NamingConventionService; - -using Microsoft.Extensions.Logging; - -public class BaseNamingConventionService : INamingConventionService where TEnum : Enum +namespace COMET.Web.Common.Services.NamingConventionService { - /// - /// that holds the defined naming convention - /// - private readonly Dictionary definedNaming = new(StringComparer.OrdinalIgnoreCase); + using Microsoft.Extensions.Logging; /// - /// The + /// The provides static information based on defined naming convention, like for names of + /// to use for example /// - private readonly ILogger> logger; - - /// - /// Initializes a new instance of the class. - /// - /// The - protected BaseNamingConventionService(ILogger> logger) + /// Any type of enumeration that will contain the different types of naming conventions + public class BaseNamingConventionService : INamingConventionService where TEnum : Enum { - this.logger = logger; - } + /// + /// that holds the defined naming convention + /// + private readonly Dictionary definedNaming = new(StringComparer.OrdinalIgnoreCase); - /// - /// Initializes this service - /// - /// A - public async Task InitializeService() - { - var namingConvention = await this.GetNamingConventionConfiguration(); + /// + /// The + /// + protected readonly ILogger> Logger; - foreach (var namingConventionKind in Enum.GetValues(typeof(TEnum))) + /// + /// Initializes a new instance of the class. + /// + /// The + protected BaseNamingConventionService(ILogger> logger) { - if (namingConvention.TryGetValue(namingConventionKind.ToString(), out var namingConventionValue)) - { - this.definedNaming[namingConventionKind.ToString()] = namingConventionValue; - } - else + this.Logger = logger; + } + + /// + /// Initializes this service + /// + /// A + public async Task InitializeService() + { + var namingConvention = await this.GetNamingConventionConfiguration(); + + foreach (var namingConventionKind in Enum.GetValues(typeof(TEnum))) { - this.logger.LogWarning("{namingConventionKind} is missing from the Naming Convention configuration file", namingConventionKind.ToString()); + if (namingConvention.TryGetValue(namingConventionKind.ToString(), out var namingConventionValue)) + { + this.definedNaming[namingConventionKind.ToString()] = namingConventionValue; + } + else + { + this.Logger.LogWarning("{namingConventionKind} is missing from the Naming Convention configuration file", namingConventionKind.ToString()); + } } } - } - /// - /// Gets the value for naming convention - /// - /// The naming convention key - /// The defined naming convention, if exists - public string GetNamingConventionValue(string namingConventionKey) - { - return this.definedNaming.TryGetValue(namingConventionKey, out var namingConventionValue) ? namingConventionValue : string.Empty; - } + /// + /// Gets the value for naming convention + /// + /// The naming convention key + /// The defined naming convention, if exists + public string GetNamingConventionValue(string namingConventionKey) + { + return this.definedNaming.TryGetValue(namingConventionKey, out var namingConventionValue) ? namingConventionValue : string.Empty; + } - /// - /// Gets the value for naming convention - /// - /// The - /// The defined naming convention, if exists - public string GetNamingConventionValue(TEnum namingConventionKind) - { - return this.GetNamingConventionValue(namingConventionKind.ToString()); - } + /// + /// Gets the value for naming convention + /// + /// The enum that is used by the service + /// The defined naming convention, if exists + public string GetNamingConventionValue(TEnum namingConventionKind) + { + return this.GetNamingConventionValue(namingConventionKind.ToString()); + } - /// - /// Gets the naming convention configuration - /// - /// A of the naming convention configuration - /// - public virtual Task> GetNamingConventionConfiguration() - { - throw new NotImplementedException(); + /// + /// Gets the naming convention configuration + /// + /// A of the naming convention configuration + /// + public virtual Task> GetNamingConventionConfiguration() + { + throw new NotImplementedException(); + } } } diff --git a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs index a44c69f6..76edcc86 100644 --- a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs +++ b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs @@ -28,6 +28,7 @@ namespace COMET.Web.Common.Services.NamingConventionService /// /// The provides static information based on defined naming convention, like for names of to use for example /// + /// Any type of enumeration that will contain the different types of naming conventions public interface INamingConventionService where TEnum : Enum { /// @@ -50,6 +51,11 @@ public interface INamingConventionService where TEnum : Enum /// The defined naming convention, if exists string GetNamingConventionValue(TEnum namingConventionKind); + /// + /// Gets the naming convention configuration + /// + /// A of the naming convention configuration + /// Task> GetNamingConventionConfiguration(); } } diff --git a/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs index cb728b2e..24ac84ed 100644 --- a/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs +++ b/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs @@ -40,19 +40,18 @@ namespace COMET.Web.Common.WebAssembly.Services.NamingConventionService /// public class NamingConventionService : BaseNamingConventionService where TEnum : Enum { - /// - /// The - /// - private readonly ILogger> logger; - /// /// The /// private readonly HttpClient httpClient; + /// + /// Creates a new instance of type + /// + /// the + /// the public NamingConventionService(ILogger> logger, HttpClient httpClient) : base(logger) { - this.logger = logger; this.httpClient = httpClient; } @@ -76,16 +75,16 @@ public override async Task> GetNamingConvent if (response.StatusCode == HttpStatusCode.NotFound) { - this.logger.LogError("Naming conventions file not found at {path}", path); + this.Logger.LogError("Naming conventions file not found at {path}", path); return ImmutableDictionary.Empty; } - this.logger.LogError("Error fetching naming conventions. Status code: {response}", response.StatusCode); + this.Logger.LogError("Error fetching naming conventions. Status code: {response}", response.StatusCode); return ImmutableDictionary.Empty; } catch (Exception e) { - this.logger.LogCritical("Exception has been raised : {message}", e.Message); + this.Logger.LogCritical("Exception has been raised : {message}", e.Message); return ImmutableDictionary.Empty; } } From 39a15da598fbda098efc5a49393231acd06f0d12 Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Thu, 19 Oct 2023 10:04:50 +0100 Subject: [PATCH 12/13] Make the BaseNamingConventionService as an abstract class and set the GetNamingConventionConfiguration method as abstract too --- .../NamingConventionService/BaseNamingConventionService.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs index 6b60af21..7f15ddd7 100644 --- a/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs +++ b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs @@ -32,7 +32,7 @@ namespace COMET.Web.Common.Services.NamingConventionService /// to use for example /// /// Any type of enumeration that will contain the different types of naming conventions - public class BaseNamingConventionService : INamingConventionService where TEnum : Enum + public abstract class BaseNamingConventionService : INamingConventionService where TEnum : Enum { /// /// that holds the defined naming convention @@ -99,9 +99,6 @@ public string GetNamingConventionValue(TEnum namingConventionKind) /// /// A of the naming convention configuration /// - public virtual Task> GetNamingConventionConfiguration() - { - throw new NotImplementedException(); - } + public abstract Task> GetNamingConventionConfiguration(); } } From 168dcbcc40f9346e32b3b958e2101d4c5175d010 Mon Sep 17 00:00:00 2001 From: Roberto Alves Date: Thu, 19 Oct 2023 10:10:53 +0100 Subject: [PATCH 13/13] Make the GetNamingConventionConfiguration method protected as it should only be used and/or seen by the classes that implement the BaseNamingConventionService --- .../NamingConventionService/NamingConventionService.cs | 2 +- .../NamingConventionService/BaseNamingConventionService.cs | 2 +- .../NamingConventionService/INamingConventionService.cs | 7 ------- .../NamingConventionService/NamingConventionService.cs | 2 +- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs index f0f347b3..576f2837 100644 --- a/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs +++ b/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs @@ -51,7 +51,7 @@ public NamingConventionService(ILogger> logger) /// Gets the naming convention configuration /// /// A of the naming convention configuration - public override async Task> GetNamingConventionConfiguration() + protected override async Task> GetNamingConventionConfiguration() { try { diff --git a/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs index 7f15ddd7..aedf4fed 100644 --- a/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs +++ b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs @@ -99,6 +99,6 @@ public string GetNamingConventionValue(TEnum namingConventionKind) /// /// A of the naming convention configuration /// - public abstract Task> GetNamingConventionConfiguration(); + protected abstract Task> GetNamingConventionConfiguration(); } } diff --git a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs index 76edcc86..dd14eb1e 100644 --- a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs +++ b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs @@ -50,12 +50,5 @@ public interface INamingConventionService where TEnum : Enum /// The /// The defined naming convention, if exists string GetNamingConventionValue(TEnum namingConventionKind); - - /// - /// Gets the naming convention configuration - /// - /// A of the naming convention configuration - /// - Task> GetNamingConventionConfiguration(); } } diff --git a/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs index 24ac84ed..6a8bbc0e 100644 --- a/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs +++ b/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs @@ -59,7 +59,7 @@ public NamingConventionService(ILogger> logger, /// Gets the naming convention configuration /// /// A of the naming convention configuration - public override async Task> GetNamingConventionConfiguration() + protected override async Task> GetNamingConventionConfiguration() { try {