Skip to content

Commit

Permalink
Feature/dry ioc next (#1479)
Browse files Browse the repository at this point in the history
* Updating to dryioc preview (#1230)

* Updating to dryioc preview

* Automatically linting code

---------

Co-authored-by: Rocket Understudy <[email protected]>

* enable msdi rules (#1231)

* Update/next 2 (#1286)

* Update dependency Polyfill to v5.2.0

* Update dependency Polyfill to v5.2.1

* Update dependency Polyfill to v5.2.2

* Update dependency Rocket.Surgery.Nuke to v1.8.30

* Update planetscale/ghcommit-action action to v0.1.37

* Update actions/checkout digest to 44c2b7a

* Update codecov/codecov-action action to v4.3.1

* Update dependency Rocket.Surgery.Nuke to v1.8.31

* Automatically linting code

* Update dependency jetbrains.resharper.globaltools to v2024.1.2

* Update dependency Verify.Xunit to v24.2.0

* Update roslynator to v4.12.3

* Update dependency Rocket.Surgery.Nuke to v1.8.32

* Update planetscale/ghcommit-action action to v0.1.38

* Update codecov/codecov-action action to v4.4.0

* Update reportgenerator to v5.3.0

* Update dependency dotnet-outdated-tool to v4.6.2

* Update dependency dotnet-outdated-tool to v4.6.3

* Update actions/checkout digest to 24ed1a3

* Update actions/checkout digest to a5ac7e5

* Update dependency dotnet-outdated-tool to v4.6.4

* Update planetscale/ghcommit-action action to v0.1.39

* Update dependency Rocket.Surgery.Nuke to v1.8.33

* Update github actions

* Update dependency lint-staged to v15.2.4

* Update dependency Microsoft.NET.Test.Sdk to v17.10.0

* Update dependency System.Reactive to v6.0.1

* Update dependency Rocket.Surgery.Nuke to v1.8.34

* Automatically linting code

* Update gitversion to v6.0.0-rc.1

* Update dependency FluentAssertions.Analyzers to v0.32.0

* Update xunit

* Update dependency lint-staged to v15.2.5

* Update dependency NuGet.ProjectModel to v6.10.0 (#1256)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update reportgenerator to v5.3.4

* Update planetscale/ghcommit-action action to v0.1.40

* Update dependency Polyfill to v5.3.0

* Update planetscale/ghcommit-action action to v0.1.41

* Update dependency Verify.Xunit to v25

* Update reportgenerator to v5.3.5

* Update dependency prettier to v3.3.0

* Update roslynator to v4.12.4

* Update dependency Verify.Xunit to v25.0.1

* Update reportgenerator to v5.3.6

* Update dependency prettier to v3.3.1

* Update dependency jetbrains.resharper.globaltools to v2024.1.3

* Update planetscale/ghcommit-action action to v0.1.42

* Update dependency prettier to v3.3.2

* Update dependency Verify.Xunit to v25.0.2

* Update dependency lint-staged to v15.2.6

* Update actions/checkout digest to 6ccd57f

* Update dependency lint-staged to v15.2.7

* Update actions/checkout digest to 692973e

* Update codecov/codecov-action action to v4.5.0

* Update dependency Verify.Xunit to v25.0.3

* Update dependency Serilog to v4 (#1269)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency Buildalyzer to v7 (#1244)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Updating to dryioc preview (#1230)

* Updating to dryioc preview

* Automatically linting code

---------

Co-authored-by: Rocket Understudy <[email protected]>

* enable msdi rules (#1231)

* Dunno how gitversion got updated!

* Automatically linting code

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Rocket Understudy <[email protected]>

* next dryioc version

* Automatically linting code

---------

Co-authored-by: Rocket Understudy <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 17, 2024
1 parent 03e64c1 commit 36d3d50
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 90 deletions.
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<PackageVersion Include="System.Interactive" Version="6.0.1" />
<PackageVersion Include="System.Interactive.Async" Version="6.0.1" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<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-08" />
<PackageVersion Include="DryIoc.Microsoft.DependencyInjection" Version="8.0.0-preview-03" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FakeItEasy" Version="8.3.0" />
<PackageVersion Include="Autofac.Extras.FakeItEasy" Version="7.0.0" />
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: []
19 changes: 8 additions & 11 deletions src/Testing.FakeItEasy/AutoFake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,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 @@ -39,7 +38,8 @@ public AutoFake(
.WithConcreteTypeDynamicRegistrations((_, _) => true, Reuse.Transient)
);
if (configureAction != null)
Container = configureAction.Invoke(Container);
Container = configureAction.Invoke(container);
Container = container.With(rules => rules.WithBaseMicrosoftDependencyInjectionRules(null));
}

/// <summary>
Expand All @@ -52,10 +52,7 @@ public AutoFake(
/// </summary>
/// <typeparam name="T">The type of the service.</typeparam>
/// <returns>The service.</returns>
public T Resolve<T>()
{
return Container.Resolve<T>();
}
public T Resolve<T>() => Container.Resolve<T>();

/// <summary>
/// Resolve the specified type in the container (register it if needed).
Expand Down Expand Up @@ -93,9 +90,9 @@ public TService Provide<TService>(TService instance)
return instance;
}

#pragma warning disable CA1063
#pragma warning disable CA1063
void IDisposable.Dispose()
#pragma warning restore CA1063
#pragma warning restore CA1063
{
Container.Dispose();
}
Expand Down
21 changes: 14 additions & 7 deletions src/Testing.FakeItEasy/AutoFakeTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using DryIoc;
using DryIoc.Microsoft.DependencyInjection;
using FakeItEasy;
Expand Down Expand Up @@ -47,6 +46,11 @@ protected IContainer Container
private set => _autoFake = Rebuild(value);
}

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

/// <summary>
/// Force the container to rebuild from scratch
/// </summary>
Expand All @@ -62,10 +66,13 @@ protected AutoFake Rebuild(IContainer? container = null)
return autoFake;
}

/// <summary>
/// The Service Provider
/// </summary>
protected IServiceProvider ServiceProvider => AutoFake.Container;
protected override ILoggerFactory CreateLoggerFactory(LoggerProviderCollection? loggerProviderCollection = null)
{
#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
return A.Fake<ILoggerFactory>(l => l.Wrapping(factory));
}

private IContainer ConfigureContainer(IContainer container)
{
Expand All @@ -80,7 +87,7 @@ private IContainer ConfigureContainer(IContainer container)
);
container.RegisterDelegate(context => context.Resolve<ILoggerFactory>().CreateLogger("Test"));
container.RegisterInstance(Logger);
return BuildContainer(container.WithDependencyInjectionAdapter());
return BuildContainer(container);
}

/// <summary>
Expand All @@ -104,6 +111,6 @@ protected void Populate(IContainer container)
/// </summary>
protected virtual IContainer BuildContainer(IContainer container)
{
return container;
return container.With(rules => rules.WithBaseMicrosoftDependencyInjectionRules(null));
}
}
23 changes: 10 additions & 13 deletions src/Testing.Moq/AutoMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public AutoMock(
IContainer? container = null,
Func<IContainer, IContainer>? configureAction = null
)
: this(new MockRepository(behavior), container, configureAction)
{
}
: this(new MockRepository(behavior), container, configureAction) { }

/// <summary>
/// Create a container that automatically fakes unknown types
Expand All @@ -36,9 +34,9 @@ public AutoMock(
Func<IContainer, IContainer>? configureAction = null
)
{
Container = container ?? new Container();
container ??= new Container();

Container = Container.With(
container = container.With(
rules =>
{
var createMethod = typeof(MockRepository).GetMethod(nameof(MockRepository.Create), Array.Empty<Type>())!;
Expand All @@ -57,7 +55,8 @@ public AutoMock(
);

if (configureAction != null)
Container = configureAction.Invoke(Container);
Container = configureAction.Invoke(container);
Container = container.With(rules => rules.WithBaseMicrosoftDependencyInjectionRules(null));
}

/// <summary>
Expand All @@ -70,10 +69,7 @@ public AutoMock(
/// </summary>
/// <typeparam name="T">The type of the service.</typeparam>
/// <returns>The service.</returns>
public T Resolve<T>()
{
return Container.Resolve<T>();
}
public T Resolve<T>() => Container.Resolve<T>();

/// <summary>
/// Finds (creating if needed) the actual mock for the provided type.
Expand Down Expand Up @@ -112,7 +108,8 @@ public TService Provide<TService, TImplementation>()
/// <param name="instance">The instance to register if needed.</param>
/// <returns>The instance resolved from container.</returns>
[SuppressMessage(
"Microsoft.Reliability", "CA2000:Dispose objects before losing scope",
"Microsoft.Reliability",
"CA2000:Dispose objects before losing scope",
Justification = "The component registry is responsible for registration disposal."
)]
public TService Provide<TService>(TService instance)
Expand All @@ -122,9 +119,9 @@ public TService Provide<TService>(TService instance)
return instance;
}

#pragma warning disable CA1063
#pragma warning disable CA1063
void IDisposable.Dispose()
#pragma warning restore CA1063
#pragma warning restore CA1063
{
Container.Dispose();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Testing.Moq/AutoMockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ protected IContainer Container
private set => _autoMock = Rebuild(value);
}

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

/// <summary>
/// Force the container to rebuild from scratch
/// </summary>
Expand All @@ -59,11 +64,6 @@ protected AutoMock Rebuild(IContainer? container = null)
return autoFake;
}

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

private IContainer ConfigureContainer(IContainer container)
{
container.RegisterDelegate(
Expand All @@ -73,7 +73,7 @@ private IContainer ConfigureContainer(IContainer container)
);
container.RegisterDelegate(context => context.Resolve<ILoggerFactory>().CreateLogger("Test"));
container.RegisterInstance(Logger);
return BuildContainer(container.WithDependencyInjectionAdapter());
return BuildContainer(container);
}

/// <summary>
Expand All @@ -97,6 +97,6 @@ protected void Populate(IContainer container)
/// </summary>
protected virtual IContainer BuildContainer(IContainer container)
{
return container;
return container.With(rules => rules.WithBaseMicrosoftDependencyInjectionRules(null));
}
}
15 changes: 7 additions & 8 deletions src/Testing.NSubstitute/AutoSubstitute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public AutoSubstitute(
Func<IContainer, IContainer>? configureAction = null
)
{
Container = container ?? new Container();
container ??= new Container();

Container = Container
container = container
.With(
rules => rules
.WithTestLoggerResolver(
Expand All @@ -34,7 +34,9 @@ public AutoSubstitute(
.WithConcreteTypeDynamicRegistrations((_, _) => true, Reuse.Transient)
);

if (configureAction != null) Container = configureAction.Invoke(Container);
if (configureAction != null)
Container = configureAction.Invoke(container);
Container = container.With(rules => rules.WithBaseMicrosoftDependencyInjectionRules(null));
}

/// <summary>
Expand All @@ -47,10 +49,7 @@ public AutoSubstitute(
/// </summary>
/// <typeparam name="T">The type of the service.</typeparam>
/// <returns>The service.</returns>
public T Resolve<T>()
{
return Container.Resolve<T>();
}
public T Resolve<T>() => Container.Resolve<T>();

/// <summary>
/// Resolve the specified type in the container (register specified instance if needed).
Expand Down Expand Up @@ -93,4 +92,4 @@ void IDisposable.Dispose()
Container.Dispose();
}
#pragma warning restore CA1063
}
}
15 changes: 7 additions & 8 deletions src/Testing.NSubstitute/AutoSubstituteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using Serilog.Extensions.Logging;

namespace Rocket.Surgery.Extensions.Testing;
Expand Down Expand Up @@ -45,6 +44,11 @@ protected IContainer Container
private set => _autoSubstitute = Rebuild(value);
}

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

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

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

/// <summary>
/// A method that allows you to override and update the behavior of building the container
/// </summary>
protected virtual IContainer BuildContainer(IContainer container)
{
return container;
return container.With(rules => rules.WithBaseMicrosoftDependencyInjectionRules(null));
}

/// <summary>
Expand Down Expand Up @@ -97,6 +96,6 @@ private IContainer ConfigureContainer(IContainer container)
);
container.RegisterDelegate(context => context.Resolve<ILoggerFactory>().CreateLogger("Test"));
container.RegisterInstance(Logger);
return BuildContainer(container.WithDependencyInjectionAdapter());
return BuildContainer(container);
}
}
8 changes: 3 additions & 5 deletions src/Testing/LoggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Rocket.Surgery.Extensions.Testing;
public abstract class LoggerTest<TContext>(TContext testContext) : IDisposable where TContext : class, ILoggingTestContext
{
/// <summary>
/// The <see cref="TestContext" />
/// The <see cref="TestContext" />
/// </summary>
protected TContext TestContext => testContext;

Expand Down Expand Up @@ -68,10 +68,8 @@ protected IDisposable CaptureLogs(Func<LogEvent, bool> filterLogs, out IEnumerab
/// <summary>
/// Control the way that the serilog logger factory is created.
/// </summary>
protected ILoggerFactory CreateLoggerFactory(LoggerProviderCollection? loggerProviderCollection = null)
{
return new SerilogLoggerFactory(Logger, false, loggerProviderCollection);
}
protected virtual ILoggerFactory CreateLoggerFactory(LoggerProviderCollection? loggerProviderCollection = null) =>
new SerilogLoggerFactory(Logger, false, loggerProviderCollection);

/// <summary>
/// Filter a given source context from serilog
Expand Down
1 change: 1 addition & 0 deletions src/Testing/RocketSurgeonsTestingDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Rocket.Surgery.Extensions.Testing;
/// <summary>
/// Defaults to be configured globally for tests
/// </summary>
[PublicAPI]
public static class RocketSurgeonsTestingDefaults
{
/// <summary>
Expand Down
Loading

0 comments on commit 36d3d50

Please sign in to comment.