Skip to content

Commit

Permalink
Updating to dryioc preview (#1230)
Browse files Browse the repository at this point in the history
* Updating to dryioc preview

* Automatically linting code

---------

Co-authored-by: Rocket Understudy <[email protected]>
  • Loading branch information
david-driscoll and rsg-bot authored Apr 28, 2024
1 parent 36d6592 commit 2698732
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 214 deletions.
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<PackageVersion Include="System.Reactive" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="DryIoc.dll" Version="5.4.3" />
<PackageVersion Include="DryIoc.Microsoft.DependencyInjection" Version="6.2.0" />
<PackageVersion Include="DryIoc.dll" Version="6.0.0-preview-07" />
<PackageVersion Include="DryIoc.Microsoft.DependencyInjection" Version="8.0.0-preview-02" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FakeItEasy" Version="8.2.0" />
<PackageVersion Include="FakeItEasy.Analyzer.CSharp" Version="6.1.1" />
Expand Down
29 changes: 5 additions & 24 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
mode: ContinuousDelivery
workflow: GitHubFlow/v1
semantic-version-format: Loose

branches:
main:
label: beta
increment: Inherit
track-merge-target: false
regex: ^master$|^main$
source-branches:
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
pre-release-weight: 55000
- next
pull-request:
mode: ContinuousDelivery
label: pr
increment: Inherit
label-number-pattern: '[/-](?<number>\d+)'
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- main
- release
- feature
is-source-branch-for: []
pre-release-weight: 30000
next:
mode: ContinuousDelivery
regex: ^next$
increment: Major
label: next
track-merge-target: false
tracks-release-branches: false
is-release-branch: false
source-branches: ['main']
increment: Patch
source-branches: []
is-source-branch-for: []
ignore:
sha: []
28 changes: 14 additions & 14 deletions src/Testing.FakeItEasy/AutoFake.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using DryIoc;
using DryIoc.Microsoft.DependencyInjection;
using FakeItEasy.Creation;
using FakeItEasy.Sdk;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -23,10 +24,9 @@ public AutoFake(
Action<IFakeOptions>? fakeOptionsAction = null
)
{
Container = container ?? new Container();
if (fakeOptionsAction == null)
fakeOptionsAction = _ => { };
Container = Container
container ??= new Container();
fakeOptionsAction ??= _ => { };
container = container
.With(
rules => rules
.WithTestLoggerResolver(
Expand All @@ -40,13 +40,13 @@ public AutoFake(
.WithConcreteTypeDynamicRegistrations((_, _) => true, Reuse.Transient)
);
if (configureAction != null)
Container = configureAction.Invoke(Container);
DryIoc = configureAction.Invoke(container).WithDependencyInjectionAdapter();
}

/// <summary>
/// Gets the <see cref="IContainer" /> that handles the component resolution.
/// </summary>
public IContainer Container { get; }
public DryIocServiceProvider DryIoc { get; }

/// <summary>
/// Resolve the specified type in the container (register it if needed).
Expand All @@ -55,7 +55,7 @@ public AutoFake(
/// <returns>The service.</returns>
public T Resolve<T>()
{
return Container.Resolve<T>();
return DryIoc.Container.Resolve<T>();
}

/// <summary>
Expand All @@ -72,8 +72,8 @@ public T Resolve<T>()
public TService Provide<TService, TImplementation>()
where TImplementation : TService
{
Container.Register<TService, TImplementation>(Reuse.Singleton);
return Container.Resolve<TService>();
DryIoc.Container.Register<TService, TImplementation>(Reuse.Singleton);
return DryIoc.Container.Resolve<TService>();
}

/// <summary>
Expand All @@ -90,14 +90,14 @@ public TService Provide<TService, TImplementation>()
public TService Provide<TService>(TService instance)
where TService : class
{
Container.RegisterInstance(instance);
DryIoc.Container.RegisterInstance(instance);
return instance;
}

#pragma warning disable CA1063
#pragma warning disable CA1063
void IDisposable.Dispose()
#pragma warning restore CA1063
#pragma warning restore CA1063
{
Container.Dispose();
DryIoc.Dispose();
}
}
}
136 changes: 66 additions & 70 deletions src/Testing.FakeItEasy/AutoFakeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ namespace Rocket.Surgery.Extensions.Testing;
/// </summary>
public abstract class AutoFakeTest : LoggerTest
{
private static readonly IConfiguration ReadOnlyConfiguration = new ConfigurationBuilder().Build();
private static readonly IConfiguration _readOnlyConfiguration = new ConfigurationBuilder().Build();
private readonly Action<IFakeOptions>? _fakeOptionsAction;
private AutoFake? _autoFake;
private bool _building;

/// <summary>
/// The Configuration if defined otherwise empty.
/// </summary>
protected IConfiguration Configuration => Container.IsRegistered<IConfiguration>() ? Container.Resolve<IConfiguration>() : ReadOnlyConfiguration;
protected IConfiguration Configuration => Container.IsRegistered<IConfiguration>() ? Container.Resolve<IConfiguration>() : _readOnlyConfiguration;

/// <summary>
/// The AutoFake instance
Expand All @@ -39,10 +39,15 @@ public abstract class AutoFakeTest : LoggerTest
/// </summary>
protected IContainer Container
{
get => AutoFake.Container;
get => AutoFake.DryIoc.Container;
private set => _autoFake = Rebuild(value);
}

/// <summary>
/// The Service Provider
/// </summary>
protected IServiceProvider ServiceProvider => AutoFake.DryIoc;

/// <summary>
/// Force the container to rebuild from scratch
/// </summary>
Expand All @@ -58,75 +63,12 @@ protected AutoFake Rebuild(IContainer? container = null)
return autoFake;
}

/// <summary>
/// The Service Provider
/// </summary>
protected IServiceProvider ServiceProvider => AutoFake.Container;

#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
/// <summary>
/// The default constructor with available logging level
/// </summary>
/// <param name="outputHelper"></param>
/// <param name="logFormat"></param>
/// <param name="configureLogger"></param>
/// <param name="fakeOptionsAction"></param>
protected AutoFakeTest(
ITestOutputHelper outputHelper,
string? logFormat = null,
Action<LoggerConfiguration>? configureLogger = null,
Action<IFakeOptions>? fakeOptionsAction = null
)
: this(outputHelper, LogEventLevel.Information, logFormat, configureLogger, fakeOptionsAction)
{
}

/// <summary>
/// The default constructor with available logging level
/// </summary>
/// <param name="outputHelper"></param>
/// <param name="minLevel"></param>
/// <param name="logFormat"></param>
/// <param name="configureLogger"></param>
/// <param name="fakeOptionsAction"></param>
protected AutoFakeTest(
ITestOutputHelper outputHelper,
LogLevel minLevel,
string? logFormat = null,
Action<LoggerConfiguration>? configureLogger = null,
Action<IFakeOptions>? fakeOptionsAction = null
)
: this(outputHelper, LevelConvert.ToSerilogLevel(minLevel), logFormat, configureLogger, fakeOptionsAction)
{
}

/// <summary>
/// The default constructor with available logging level
/// </summary>
/// <param name="outputHelper"></param>
/// <param name="minLevel"></param>
/// <param name="logFormat"></param>
/// <param name="configureLogger"></param>
/// <param name="fakeOptionsAction"></param>
protected AutoFakeTest(
ITestOutputHelper outputHelper,
LogEventLevel minLevel,
string? logFormat = null,
Action<LoggerConfiguration>? configureLogger = null,
Action<IFakeOptions>? fakeOptionsAction = null
)
: base(outputHelper, minLevel, logFormat, configureLogger)
{
_fakeOptionsAction = fakeOptionsAction;
}
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters

private IContainer ConfigureContainer(IContainer container)
{
container.RegisterInstance(LoggerFactory);
container.RegisterInstance(Logger);
container.RegisterInstance(SerilogLogger);
return BuildContainer(container.WithDependencyInjectionAdapter());
return BuildContainer(container);
}

/// <summary>
Expand Down Expand Up @@ -182,10 +124,64 @@ protected override ILoggerFactory CreateLoggerFactory(
LoggerProviderCollection loggerProviderCollection
)
{
#pragma warning disable CA2000 // Dispose objects before losing scope
#pragma warning disable CA2000 // Dispose objects before losing scope
var factory =
new FakeItEasyLoggerFactory(new SerilogLoggerFactory(logger, false, loggerProviderCollection));
#pragma warning restore CA2000 // Dispose objects before losing scope
#pragma warning restore CA2000 // Dispose objects before losing scope
return A.Fake<ILoggerFactory>(l => l.Wrapping(factory));
}
}

#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
/// <summary>
/// The default constructor with available logging level
/// </summary>
/// <param name="outputHelper"></param>
/// <param name="logFormat"></param>
/// <param name="configureLogger"></param>
/// <param name="fakeOptionsAction"></param>
protected AutoFakeTest(
ITestOutputHelper outputHelper,
string? logFormat = null,
Action<LoggerConfiguration>? configureLogger = null,
Action<IFakeOptions>? fakeOptionsAction = null
)
: this(outputHelper, LogEventLevel.Information, logFormat, configureLogger, fakeOptionsAction) { }

/// <summary>
/// The default constructor with available logging level
/// </summary>
/// <param name="outputHelper"></param>
/// <param name="minLevel"></param>
/// <param name="logFormat"></param>
/// <param name="configureLogger"></param>
/// <param name="fakeOptionsAction"></param>
protected AutoFakeTest(
ITestOutputHelper outputHelper,
LogLevel minLevel,
string? logFormat = null,
Action<LoggerConfiguration>? configureLogger = null,
Action<IFakeOptions>? fakeOptionsAction = null
)
: this(outputHelper, LevelConvert.ToSerilogLevel(minLevel), logFormat, configureLogger, fakeOptionsAction) { }

/// <summary>
/// The default constructor with available logging level
/// </summary>
/// <param name="outputHelper"></param>
/// <param name="minLevel"></param>
/// <param name="logFormat"></param>
/// <param name="configureLogger"></param>
/// <param name="fakeOptionsAction"></param>
protected AutoFakeTest(
ITestOutputHelper outputHelper,
LogEventLevel minLevel,
string? logFormat = null,
Action<LoggerConfiguration>? configureLogger = null,
Action<IFakeOptions>? fakeOptionsAction = null
)
: base(outputHelper, minLevel, logFormat, configureLogger)
{
_fakeOptionsAction = fakeOptionsAction;
}
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
}
Loading

0 comments on commit 2698732

Please sign in to comment.