From 28a6776dd150ecb8e5e04b3a7e8bb3fb47e4aca5 Mon Sep 17 00:00:00 2001 From: zenden231 Date: Wed, 29 Sep 2021 13:30:19 +0300 Subject: [PATCH 1/3] =?UTF-8?q?#132,#56=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D1=8B=20RP=20=D0=B2=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B8=D0=B9=20appsettings=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/ConfigOptionsFactory.cs | 19 +++++ src/Molder.ReportPortal/Hooks/Hooks.cs | 84 +++++++++++++++++++ .../Infrastructures/Constants.cs | 17 ++++ .../Models/Settings/Interfaces/ISettings.cs | 9 ++ .../Models/Settings/ReportPortalSettings.cs | 21 +++++ .../Models/Settings/Settings.cs | 36 ++++++++ .../Molder.ReportPortal.csproj | 7 ++ .../ReportPortal.config.json | 8 ++ 8 files changed, 201 insertions(+) create mode 100644 src/Molder.ReportPortal/Helper/ConfigOptionsFactory.cs create mode 100644 src/Molder.ReportPortal/Hooks/Hooks.cs create mode 100644 src/Molder.ReportPortal/Infrastructures/Constants.cs create mode 100644 src/Molder.ReportPortal/Models/Settings/Interfaces/ISettings.cs create mode 100644 src/Molder.ReportPortal/Models/Settings/ReportPortalSettings.cs create mode 100644 src/Molder.ReportPortal/Models/Settings/Settings.cs create mode 100644 src/Molder.ReportPortal/ReportPortal.config.json diff --git a/src/Molder.ReportPortal/Helper/ConfigOptionsFactory.cs b/src/Molder.ReportPortal/Helper/ConfigOptionsFactory.cs new file mode 100644 index 00000000..d5eb23d8 --- /dev/null +++ b/src/Molder.ReportPortal/Helper/ConfigOptionsFactory.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Molder.ReportPortal.Infrastructures; +using Molder.ReportPortal.Models.Settings; +using System.IO; +using System.Runtime.CompilerServices; + +namespace Molder.ReportPortal.Helper +{ + public class ConfigOptionsFactory + { + public static IOptions Create(IConfiguration configuration) + { + var blc = configuration.GetSection(Constants.CONFIG_BLOCK).GetSection(Constants.SETTINGS_BLOCK); + var settings = blc.Get(); + return Options.Create(settings); + } + } +} diff --git a/src/Molder.ReportPortal/Hooks/Hooks.cs b/src/Molder.ReportPortal/Hooks/Hooks.cs new file mode 100644 index 00000000..8ef84b15 --- /dev/null +++ b/src/Molder.ReportPortal/Hooks/Hooks.cs @@ -0,0 +1,84 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Molder.Helpers; +using Molder.Models.Configuration; +using Molder.ReportPortal.Helper; +using Molder.ReportPortal.Infrastructures; +using Molder.ReportPortal.Models.Settings; +using ReportPortal.Client; +using ReportPortal.Client.Abstractions.Models; +using ReportPortal.SpecFlowPlugin; +using ReportPortal.SpecFlowPlugin.EventArguments; +using System; +using TechTalk.SpecFlow; + +namespace Molder.ReportPortal.Hooks +{ + [Binding] + class Hooks : Steps + { + [BeforeTestRun(Order = -9000000)] + + public static void InitializeConfiguration() + { + var settings = ConfigOptionsFactory.Create(ConfigurationExtension.Instance.Configuration); + + if (settings.Value is null) + { + Log.Logger().LogInformation($@"appsettings is not contains {Constants.CONFIG_BLOCK} block."); + } + else + { + Log.Logger().LogInformation($@"appsettings contains {Constants.CONFIG_BLOCK} block. Settings selected."); + ReportPortalSettings.Settings = settings.Value; + AddCustomHandlers(); + } + } + + private static void AddCustomHandlers() + { + if (ReportPortalSettings.Settings.Enabled) + { + ReportPortalAddin.Initializing += ReportPortalAddin_Initializing; + ReportPortalAddin.BeforeRunStarted += ReportPortalAddin_BeforeRunStarted; + } + } + + /// + /// set up RP server properties + /// + /// + /// + private static void ReportPortalAddin_Initializing(object sender, InitializingEventArgs e) + { + e.Service = new Service( + new Uri(ReportPortalSettings.Settings.ServerSettings.Url), + ReportPortalSettings.Settings.ServerSettings.Project, + ReportPortalSettings.Settings.ServerSettings.Token); + } + + /// + /// set up RP launch properties + /// + /// + /// + private static void ReportPortalAddin_BeforeRunStarted(object sender, RunStartedEventArgs e) + { + e.StartLaunchRequest.Description = ReportPortalSettings.Settings.LaunchSettings.Description; + e.StartLaunchRequest.Name = ReportPortalSettings.Settings.LaunchSettings.Name; + e.StartLaunchRequest.IsRerun = ReportPortalSettings.Settings.LaunchSettings.IsRerun; + e.StartLaunchRequest.RerunOfLaunchUuid = ReportPortalSettings.Settings.LaunchSettings.RerunOfLaunchUuid; + e.StartLaunchRequest.StartTime = ReportPortalSettings.Settings.LaunchSettings.StartTime; + +#if DEBUG + e.StartLaunchRequest.Mode = LaunchMode.Debug; +#else + e.StartLaunchRequest.Mode = LaunchMode.Default; +#endif + ReportPortalSettings.Settings.LaunchSettings.Tags.ForEach(t => + e.StartLaunchRequest.Attributes.Add(new ItemAttribute { Value = t })); + } + + + } +} diff --git a/src/Molder.ReportPortal/Infrastructures/Constants.cs b/src/Molder.ReportPortal/Infrastructures/Constants.cs new file mode 100644 index 00000000..ff482539 --- /dev/null +++ b/src/Molder.ReportPortal/Infrastructures/Constants.cs @@ -0,0 +1,17 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Molder.ReportPortal.Infrastructures +{ + [ExcludeFromCodeCoverage] + public static class Constants + { + #region Configuration constants + public const string CONFIG_BLOCK = "Molder.ReportPortal"; + public const string SETTINGS_BLOCK = "Settings"; + #endregion + + public const bool ENABLE_RP_REPORT = false; + + public const string DEFAULT_RP_CONFIG = "{\"$schema\": \"https://raw.githubusercontent.com/reportportal/agent-net-specflow/master/ReportPortal.SpecFlowPlugin/ReportPortal.config.schema\",\"enabled\":true,\"server\":{\"url\":\"\",\"project\":\"\",\"authentication\":{\"uuid\":\"\"}}}"; + } +} diff --git a/src/Molder.ReportPortal/Models/Settings/Interfaces/ISettings.cs b/src/Molder.ReportPortal/Models/Settings/Interfaces/ISettings.cs new file mode 100644 index 00000000..9ace54ca --- /dev/null +++ b/src/Molder.ReportPortal/Models/Settings/Interfaces/ISettings.cs @@ -0,0 +1,9 @@ +namespace Molder.ReportPortal.Models.Settings.Interfaces +{ + public interface ISettings + { + bool IsEnabled(); + bool CheckServerSettings(); + bool CheckLaunchSettings(); + } +} diff --git a/src/Molder.ReportPortal/Models/Settings/ReportPortalSettings.cs b/src/Molder.ReportPortal/Models/Settings/ReportPortalSettings.cs new file mode 100644 index 00000000..c39db908 --- /dev/null +++ b/src/Molder.ReportPortal/Models/Settings/ReportPortalSettings.cs @@ -0,0 +1,21 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Molder.ReportPortal.Models.Settings +{ + [ExcludeFromCodeCoverage] + public class ReportPortalSettings + { + private ReportPortalSettings() { } + + private static Lazy _settings = new(() => null); + public static Settings Settings + { + get => _settings.Value; + set + { + _settings = new Lazy(() => value); + } + } + } +} diff --git a/src/Molder.ReportPortal/Models/Settings/Settings.cs b/src/Molder.ReportPortal/Models/Settings/Settings.cs new file mode 100644 index 00000000..dcd56816 --- /dev/null +++ b/src/Molder.ReportPortal/Models/Settings/Settings.cs @@ -0,0 +1,36 @@ +using Molder.ReportPortal.Models.Settings.Interfaces; +using System; +using System.Collections.Generic; + +namespace Molder.ReportPortal.Models.Settings +{ + public class Settings : ISettings + { + public bool Enabled { get; set; } = false; + public LaunchSettings LaunchSettings { get; set; } + public ServerSettings ServerSettings { get; set; } + + public bool IsEnabled() => Enabled; + public bool CheckServerSettings() => !String.IsNullOrEmpty(ServerSettings.Project) || + !String.IsNullOrEmpty(ServerSettings.Url) || + !String.IsNullOrEmpty(ServerSettings.Token); + public bool CheckLaunchSettings() => !String.IsNullOrEmpty(LaunchSettings.Name); + } + + public class LaunchSettings + { + public string Name { get; set; } + public string Description { get; set; } + public bool IsRerun { get; set; } = false; + public string RerunOfLaunchUuid { get; set; } + public DateTime StartTime { get; set; } = DateTime.UtcNow; + public List Tags { get; set; } + } + + public class ServerSettings + { + public string Project { get; set; } + public string Url { get; set; } + public string Token { get; set; } + } +} diff --git a/src/Molder.ReportPortal/Molder.ReportPortal.csproj b/src/Molder.ReportPortal/Molder.ReportPortal.csproj index 578b644c..199dc629 100644 --- a/src/Molder.ReportPortal/Molder.ReportPortal.csproj +++ b/src/Molder.ReportPortal/Molder.ReportPortal.csproj @@ -27,6 +27,7 @@ + @@ -36,5 +37,11 @@ + + + + Always + + diff --git a/src/Molder.ReportPortal/ReportPortal.config.json b/src/Molder.ReportPortal/ReportPortal.config.json new file mode 100644 index 00000000..271c5520 --- /dev/null +++ b/src/Molder.ReportPortal/ReportPortal.config.json @@ -0,0 +1,8 @@ +{ + "enabled": true, + "server": { + "url": "", + "project": "", + "authentication": { "uuid": "" } + } +} \ No newline at end of file From 10a7ce47eac3c323d8c15159e0c0da2760b7b28c Mon Sep 17 00:00:00 2001 From: zenden231 Date: Wed, 29 Sep 2021 13:33:06 +0300 Subject: [PATCH 2/3] =?UTF-8?q?Molder.ReportPortal:=20=D0=A3=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=BB=20=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D1=83?= =?UTF-8?q?=D1=8E=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Molder.ReportPortal/Infrastructures/Constants.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Molder.ReportPortal/Infrastructures/Constants.cs b/src/Molder.ReportPortal/Infrastructures/Constants.cs index ff482539..6324365f 100644 --- a/src/Molder.ReportPortal/Infrastructures/Constants.cs +++ b/src/Molder.ReportPortal/Infrastructures/Constants.cs @@ -11,7 +11,5 @@ public static class Constants #endregion public const bool ENABLE_RP_REPORT = false; - - public const string DEFAULT_RP_CONFIG = "{\"$schema\": \"https://raw.githubusercontent.com/reportportal/agent-net-specflow/master/ReportPortal.SpecFlowPlugin/ReportPortal.config.schema\",\"enabled\":true,\"server\":{\"url\":\"\",\"project\":\"\",\"authentication\":{\"uuid\":\"\"}}}"; } } From 73a3a77247bd61b82b4c3a42211cad89245d611c Mon Sep 17 00:00:00 2001 From: zenden231 Date: Thu, 30 Sep 2021 21:07:12 +0300 Subject: [PATCH 3/3] Molder.ReportPortal lib version UP --- src/Molder.ReportPortal/Molder.ReportPortal.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Molder.ReportPortal/Molder.ReportPortal.csproj b/src/Molder.ReportPortal/Molder.ReportPortal.csproj index 199dc629..d94d4627 100644 --- a/src/Molder.ReportPortal/Molder.ReportPortal.csproj +++ b/src/Molder.ReportPortal/Molder.ReportPortal.csproj @@ -11,7 +11,7 @@ true Library for adding report portal log 9 - 2.0.0 + 2.1.0 $(PackageVersion) disable