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; } }