Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
Eliminated [Serializable] attributes in Generator classes as no longer needed.
  • Loading branch information
clrudolphi committed Nov 19, 2024
1 parent 7152987 commit 1629e73
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 93 deletions.
5 changes: 5 additions & 0 deletions Reqnroll.Generator/DefaultDependencyProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Configuration;
using Reqnroll.BoDi;
using Reqnroll.Configuration;
using Reqnroll.Generator.Configuration;
Expand All @@ -21,6 +22,10 @@ public virtual void RegisterDefaults(ObjectContainer container)
{
container.RegisterTypeAs<FileSystem, IFileSystem>();

container.RegisterTypeAs<ConfigurationManager, IConfigurationManager>();
container.RegisterTypeAs<MicrosoftConfiguration_RuntimeConfigurationLoader, IMS_ConfigurationLoader>();


container.RegisterTypeAs<GeneratorConfigurationProvider, IGeneratorConfigurationProvider>();
container.RegisterTypeAs<InProcGeneratorInfoProvider, IGeneratorInfoProvider>();
container.RegisterTypeAs<TestGenerator, ITestGenerator>();
Expand Down
10 changes: 0 additions & 10 deletions Reqnroll.Generator/Interfaces/FeatureFileInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization accross appdomains
///
///
/// <summary>
/// Represents the information related to a feature file as an input of the generation
/// </summary>
[Serializable]
public class FeatureFileInput
{
/// <summary>
Expand Down
10 changes: 0 additions & 10 deletions Reqnroll.Generator/Interfaces/GenerationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization accross appdomains
///
///
/// <summary>
/// Settings for test generation
/// </summary>
[Serializable]
public class GenerationSettings
{
/// <summary>
Expand Down
4 changes: 0 additions & 4 deletions Reqnroll.Generator/Interfaces/ITestGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization accross appdomains
public interface ITestGenerator : IDisposable
{
TestGeneratorResult GenerateTestFile(FeatureFileInput featureFileInput, GenerationSettings settings);
Expand Down
4 changes: 0 additions & 4 deletions Reqnroll.Generator/Interfaces/ITestGeneratorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization across AppDomains
public interface ITestGeneratorFactory
{
Version GetGeneratorVersion();
Expand Down
5 changes: 0 additions & 5 deletions Reqnroll.Generator/Interfaces/ProjectPlatformSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization across appdomains
[Serializable]
public class ProjectPlatformSettings
{
/// <summary>
Expand Down
5 changes: 0 additions & 5 deletions Reqnroll.Generator/Interfaces/ProjectSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization accross appdomains
[Serializable]
public class ProjectSettings
{
/// <summary>
Expand Down
5 changes: 0 additions & 5 deletions Reqnroll.Generator/Interfaces/ReqnrollConfigurationHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization accross appdomains
[Serializable]
public class ReqnrollConfigurationHolder : IReqnrollConfigurationHolder
{
private readonly string xmlString;
Expand Down
5 changes: 0 additions & 5 deletions Reqnroll.Generator/Interfaces/TestGenerationError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization accross appdomains
[Serializable]
public class TestGenerationError
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization accross appdomains
[AttributeUsage(AttributeTargets.Assembly)]
public class TestGeneratorFactoryAttribute : Attribute
{
Expand Down
5 changes: 0 additions & 5 deletions Reqnroll.Generator/Interfaces/TestGeneratorResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

namespace Reqnroll.Generator.Interfaces
{
/// IMPORTANT
/// This class is used for interop with the Visual Studio Extension
/// DO NOT REMOVE OR RENAME FIELDS!
/// This breaks binary serialization accross appdomains
[Serializable]
public class TestGeneratorResult
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Reqnroll.EnvironmentAccess;
using Reqnroll.Generator.Configuration;
using Reqnroll.Generator.Project;
using Microsoft.Extensions.Configuration;
using System.ComponentModel;

namespace Reqnroll.Tools.MsBuild.Generation
{
Expand Down Expand Up @@ -47,6 +49,10 @@ public IObjectContainer BuildRootContainer(
objectContainer.RegisterTypeAs<AppInsightsEventSerializer, IAppInsightsEventSerializer>();
objectContainer.RegisterTypeAs<HttpClientWrapper, HttpClientWrapper>();
objectContainer.RegisterTypeAs<AnalyticsEventProvider, IAnalyticsEventProvider>();

objectContainer.RegisterTypeAs<ConfigurationManager, IConfigurationManager>();
objectContainer.RegisterTypeAs<MicrosoftConfiguration_RuntimeConfigurationLoader, IMS_ConfigurationLoader>();

objectContainer.RegisterTypeAs<ConfigurationLoader, IConfigurationLoader>();
objectContainer.RegisterTypeAs<GeneratorConfigurationProvider, IGeneratorConfigurationProvider>();
objectContainer.RegisterTypeAs<ProjectReader, IReqnrollProjectReader>();
Expand Down
6 changes: 4 additions & 2 deletions Reqnroll/Configuration/ConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public class ConfigurationLoader : IConfigurationLoader
{
//private readonly ObjectContainer _objectContainer;
private readonly JsonConfigurationLoader _jsonConfigurationLoader;
private readonly IMS_ConfigurationLoader _msConfigurationLoader;
private readonly IReqnrollJsonLocator _reqnrollJsonLocator;

public ConfigurationLoader(IReqnrollJsonLocator reqnrollJsonLocator)
public ConfigurationLoader(IReqnrollJsonLocator reqnrollJsonLocator, IMS_ConfigurationLoader mS_ConfigurationLoader)
{
_reqnrollJsonLocator = reqnrollJsonLocator;
_jsonConfigurationLoader = new JsonConfigurationLoader();
_msConfigurationLoader = mS_ConfigurationLoader;
}

private static CultureInfo DefaultFeatureLanguage => CultureInfo.GetCultureInfo(ConfigDefaults.FeatureLanguage);
Expand Down Expand Up @@ -139,7 +141,7 @@ private ReqnrollConfiguration LoadJson(ReqnrollConfiguration reqnrollConfigurati
{
var jsonFilePath = _reqnrollJsonLocator.GetReqnrollJsonFilePath();

return new MSE_RuntimeConfigurationLoader().LoadConfiguration(reqnrollConfiguration, jsonFilePath);
return _msConfigurationLoader.Load(reqnrollConfiguration);
}

private ReqnrollConfiguration LoadJson(ReqnrollConfiguration reqnrollConfiguration, string jsonContent)
Expand Down
8 changes: 8 additions & 0 deletions Reqnroll/Configuration/IMS_ConfigurationLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Reqnroll.Configuration
{
public interface IMS_ConfigurationLoader
{
public ReqnrollConfiguration Load(ReqnrollConfiguration reqnrollConfiguration);

}
}
9 changes: 1 addition & 8 deletions Reqnroll/Configuration/JsonConfig/JsonConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ public ReqnrollConfiguration LoadJson(ReqnrollConfiguration reqnrollConfiguratio
return configuration;
}

public ReqnrollConfiguration LoadJson(ReqnrollConfiguration reqnrollConfiguration, JsonConfig jsonConfig)
{
var configuration = ApplyJsonConfig(reqnrollConfiguration, jsonConfig);
configuration.ConfigSourceText = jsonConfig.ToJson();
return configuration;

}
private static ReqnrollConfiguration ApplyJsonConfig(ReqnrollConfiguration reqnrollConfiguration, JsonConfig jsonConfig)
public static ReqnrollConfiguration ApplyJsonConfig(ReqnrollConfiguration reqnrollConfiguration, JsonConfig jsonConfig)
{
var containerRegistrationCollection = reqnrollConfiguration.CustomDependencies;
var generatorContainerRegistrationCollection = reqnrollConfiguration.GeneratorCustomDependencies;
Expand Down
22 changes: 0 additions & 22 deletions Reqnroll/Configuration/MSE_RuntimeConfigurationLoader.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Text;
using Microsoft.Extensions.Configuration;
using Reqnroll.Configuration.JsonConfig;
using Reqnroll.Tracing;
using SpecFlow.Internal.Json;

namespace Reqnroll.Configuration
{
public class MicrosoftConfiguration_RuntimeConfigurationLoader : IMS_ConfigurationLoader
{
private readonly string _jsonConfigurationFilePath;
private readonly IConfigurationManager _configurationManager;

public MicrosoftConfiguration_RuntimeConfigurationLoader(IReqnrollJsonLocator reqnrollJsonLocator, IConfigurationManager configurationManager)
{
_jsonConfigurationFilePath = reqnrollJsonLocator.GetReqnrollJsonFilePath();
if (_jsonConfigurationFilePath != null)
{
configurationManager.AddJsonFile(_jsonConfigurationFilePath, optional: true, reloadOnChange: false);
configurationManager.AddEnvironmentVariables(prefix: "REQNROLL__");
_configurationManager = configurationManager;
//configurationManager.Build();
// Build not necessary as IConfigurationManager automatically rebuilds when sources are changed
}

}


public ReqnrollConfiguration Load(ReqnrollConfiguration reqnrollConfiguration)
{
var config = _configurationManager.Get<JsonConfig.JsonConfig>();
var configuration = JsonConfigurationLoader.ApplyJsonConfig(reqnrollConfiguration, config);
configuration.ConfigSourceText = config.ToJson();
return configuration;
}

}
}
3 changes: 3 additions & 0 deletions Reqnroll/Infrastructure/DefaultDependencyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Reqnroll.Time;
using Reqnroll.Tracing;
using Reqnroll.PlatformCompatibility;
using Microsoft.Extensions.Configuration;

namespace Reqnroll.Infrastructure
{
Expand All @@ -27,6 +28,8 @@ public virtual void RegisterGlobalContainerDefaults(ObjectContainer container)
{
container.RegisterTypeAs<DefaultTestRunContext, ITestRunContext>();
container.RegisterTypeAs<DefaultRuntimeConfigurationProvider, IRuntimeConfigurationProvider>();
container.RegisterTypeAs<ConfigurationManager, IConfigurationManager>();
container.RegisterTypeAs<MicrosoftConfiguration_RuntimeConfigurationLoader, IMS_ConfigurationLoader>();

container.RegisterTypeAs<TestRunnerManager, ITestRunnerManager>();

Expand Down
3 changes: 2 additions & 1 deletion Tests/Reqnroll.GeneratorTests/MsBuildProjectReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ private void Should_parse_csproj_file_correctly(string csprojPath, string langua
string projectFilePath = Path.Combine(directoryName, csprojPath);

var reqnrollJsonLocatorMock = new Mock<IReqnrollJsonLocator>();
var microsoftExtensionsConfigurationLoaderMock = new Mock<IMS_ConfigurationLoader>();

var configurationLoader = new ConfigurationLoader(reqnrollJsonLocatorMock.Object);
var configurationLoader = new ConfigurationLoader(reqnrollJsonLocatorMock.Object, microsoftExtensionsConfigurationLoaderMock.Object);
var generatorConfigurationProvider = new GeneratorConfigurationProvider(configurationLoader);
var projectLanguageReader = new ProjectLanguageReader();
var reader = new ProjectReader(generatorConfigurationProvider, projectLanguageReader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Moq;
using FluentAssertions;
using System.IO;
using System.Reflection;
Expand All @@ -14,12 +15,19 @@ namespace Reqnroll.RuntimeTests.Configuration
{
public class MSEConfigurationLoaderTests
{
private string configFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Configuration\\reqnroll_config_test.json");
private IReqnrollJsonLocator GetStubJsonLocator()
{
var stubJsonLocatorMock = new Mock<IReqnrollJsonLocator>();
stubJsonLocatorMock.Setup(x => x.GetReqnrollJsonFilePath()).Returns(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Configuration\\reqnroll_config_test.json"));
return stubJsonLocatorMock.Object;
}
//private string configFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Configuration\\reqnroll_config_test.json");

[Fact]
public void Can_Load_From_JsonFile()
{
var runtimeConfig = new MSE_RuntimeConfigurationLoader().LoadConfiguration(ConfigurationLoader.GetDefault(), configFilePath);
var runtimeConfig = new MicrosoftConfiguration_RuntimeConfigurationLoader(GetStubJsonLocator(), new Microsoft.Extensions.Configuration.ConfigurationManager())
.Load(ConfigurationLoader.GetDefault());
runtimeConfig.FeatureLanguage.TwoLetterISOLanguageName.Should().Be("hu");
}
[Fact]
Expand All @@ -29,7 +37,8 @@ public void Can_Load_Override_From_Environment()
// ""language"": { ""feature"": ""de"" }
// }";
Environment.SetEnvironmentVariable("REQNROLL__language__feature", "de");
var runtimeConfig = new MSE_RuntimeConfigurationLoader().LoadConfiguration(ConfigurationLoader.GetDefault(), configFilePath);
var runtimeConfig = new MicrosoftConfiguration_RuntimeConfigurationLoader(GetStubJsonLocator(), new Microsoft.Extensions.Configuration.ConfigurationManager())
.Load(ConfigurationLoader.GetDefault());

runtimeConfig.FeatureLanguage.TwoLetterISOLanguageName.Should().Be("de");
Environment.SetEnvironmentVariable("REQNROLL__language__feature", null);
Expand Down

0 comments on commit 1629e73

Please sign in to comment.