Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 9 additions & 4 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 @@ -137,14 +139,17 @@ public static ReqnrollConfiguration GetDefault()

private ReqnrollConfiguration LoadJson(ReqnrollConfiguration reqnrollConfiguration)
{
var jsonContent = File.ReadAllText(_reqnrollJsonLocator.GetReqnrollJsonFilePath());
var jsonFilePath = _reqnrollJsonLocator.GetReqnrollJsonFilePath();

return LoadJson(reqnrollConfiguration, jsonContent);
return _msConfigurationLoader.Load(reqnrollConfiguration);
}

private ReqnrollConfiguration LoadJson(ReqnrollConfiguration reqnrollConfiguration, string jsonContent)
{
return _jsonConfigurationLoader.LoadJson(reqnrollConfiguration, jsonContent);
return LoadJson(reqnrollConfiguration);

// The above ignores the previously read configuration content and uses the MS.Extensions.Configuration library to read the config file
// return _jsonConfigurationLoader.LoadJson(reqnrollConfiguration, 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);

}
}
13 changes: 9 additions & 4 deletions Reqnroll/Configuration/JsonConfig/JsonConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public ReqnrollConfiguration LoadJson(ReqnrollConfiguration reqnrollConfiguratio

var jsonConfig = jsonContent.FromJson<JsonConfig>();

var configuration = ApplyJsonConfig(reqnrollConfiguration, jsonConfig);
configuration.ConfigSourceText = jsonContent;

return configuration;
}

public static ReqnrollConfiguration ApplyJsonConfig(ReqnrollConfiguration reqnrollConfiguration, JsonConfig jsonConfig)
{
var containerRegistrationCollection = reqnrollConfiguration.CustomDependencies;
var generatorContainerRegistrationCollection = reqnrollConfiguration.GeneratorCustomDependencies;
var featureLanguage = reqnrollConfiguration.FeatureLanguage;
Expand Down Expand Up @@ -122,10 +130,7 @@ public ReqnrollConfiguration LoadJson(ReqnrollConfiguration reqnrollConfiguratio
addNonParallelizableMarkerForTags,
obsoleteBehavior,
coloredOutput
)
{
ConfigSourceText = jsonContent
};
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using Reqnroll.Configuration.JsonConfig;
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)
{
if (configurationManager == null) throw new ArgumentNullException(nameof(configurationManager), "Microsoft.Extensions.Configuration configurationManager cannot be null.");

configurationManager.AddEnvironmentVariables("DOTNET_");
string envName = configurationManager["Environment"];

_jsonConfigurationFilePath = reqnrollJsonLocator.GetReqnrollJsonFilePath();


if (_jsonConfigurationFilePath != null)
{
var pathWithoutExt = Path.Combine(Path.GetDirectoryName(_jsonConfigurationFilePath),Path.GetFileNameWithoutExtension(_jsonConfigurationFilePath));
var envOverridePath = $"{pathWithoutExt}.{envName}.json";
configurationManager.AddJsonFile(_jsonConfigurationFilePath, optional: true, reloadOnChange: false);
configurationManager.AddJsonFile(envOverridePath, 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
4 changes: 4 additions & 0 deletions Reqnroll/Reqnroll.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

<!-- build time dependencies -->
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="MSBuild.AdditionalTasks" Version="0.1.36" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions Reqnroll/Reqnroll.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<dependency id="Gherkin" version="30.0.0"/>
<dependency id="Cucumber.CucumberExpressions" version="17.1.0"/>
<dependency id="Microsoft.Extensions.DependencyModel" version="8.0.2" />
<dependency id="Microsoft.Extensions.Configuration" version="8.0.0" />
<dependency id="Microsoft.Extensions.Configuration.Binder" version="8.0.2" />
<dependency id="Microsoft.Extensions.Configuration.EnvironmentVariables" version="8.0.0" />
<dependency id="Microsoft.Extensions.Configuration.Json" version="8.0.1" />
<dependency id="System.Runtime.Loader" version="4.3.0" />
<dependency id="SpecFlow.Internal.Json" version="1.0.8" />
</group>
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
@@ -0,0 +1,62 @@
using Reqnroll.Configuration.JsonConfig;
using Reqnroll.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Moq;
using FluentAssertions;
using System.IO;
using System.Reflection;
using Microsoft.Extensions.Configuration;

namespace Reqnroll.RuntimeTests.Configuration
{
public class MSEConfigurationLoaderTests
{
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 MicrosoftConfiguration_RuntimeConfigurationLoader(GetStubJsonLocator(), new Microsoft.Extensions.Configuration.ConfigurationManager())
.Load(ConfigurationLoader.GetDefault());
runtimeConfig.FeatureLanguage.TwoLetterISOLanguageName.Should().Be("hu");
}

[Fact]
public void Can_Read_EnvironmentDesignationFromEnvironment()
{
Environment.SetEnvironmentVariable("DOTNET_Environment", "Staging");
var runtimeConfig = new MicrosoftConfiguration_RuntimeConfigurationLoader(GetStubJsonLocator(), new Microsoft.Extensions.Configuration.ConfigurationManager())
.Load(ConfigurationLoader.GetDefault());
runtimeConfig.FeatureLanguage.TwoLetterISOLanguageName.Should().Be("fr");

Environment.SetEnvironmentVariable("DOTNET_Environment", null);

}
[Fact]
public void Can_Load_Override_From_Environment()
{
//string config = @"{
// ""language"": { ""feature"": ""de"" }
// }";
Environment.SetEnvironmentVariable("REQNROLL__language__feature", "de");
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);
}


}
}
Loading
Loading