Skip to content
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: windows-2022

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
with:
fetch-depth: '0' # Use all history for gitversion, cf.: https://github.com/actions/checkout/issues/113

Expand All @@ -28,12 +28,12 @@ jobs:
# - https://itnext.io/how-to-support-multiple-net-sdks-in-github-actions-workflows-b988daa884e
# - https://github.com/actions/setup-dotnet
- name: Setup dotnet
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
8.0.x
10.0.x

- run: .\build.ps1 CiBuild
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
<Import Project="$(SolutionDir)\solution.targets"/>

<PropertyGroup>
<!-- xUnit does not support .NETStandardad, cf.: https://xunit.github.io/docs/why-no-netstandard -->
<!--<TargetFrameworks>net48;netstandard2.1;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>-->
<!-- skip other targets for testing (since all tests same) -->
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net47;net6.0;net8.0;net10.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<RootNamespace>FluentAssertions.Autofac</RootNamespace>

<CollectCoverage>true</CollectCoverage>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.3.0"/>
<PackageReference Include="FluentAssertions" Version="6.5.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0"/>
<PackageReference Include="NSubstitute" Version="4.3.0"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Autofac" Version="7.1.0"/>
<PackageReference Include="FluentAssertions" Version="8.10.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="NSubstitute" Version="5.3.0"/>
<PackageReference Include="xunit" Version="2.9.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 3 additions & 2 deletions FluentAssertions.Autofac/AutofacAssertionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Autofac;
using FluentAssertions.Execution;

namespace FluentAssertions.Autofac;

Expand All @@ -16,7 +17,7 @@ public static class AutofacAssertionExtensions
/// </summary>
public static ContainerAssertions Should(this IComponentContext container)
{
return new ContainerAssertions(container);
return new ContainerAssertions(container, AssertionChain.GetOrCreate());
}

/// <summary>
Expand All @@ -25,6 +26,6 @@ public static ContainerAssertions Should(this IComponentContext container)
/// </summary>
public static BuilderAssertions Should(this ContainerBuilder builder)
{
return new BuilderAssertions(builder);
return new BuilderAssertions(builder, AssertionChain.GetOrCreate());
}
}
6 changes: 4 additions & 2 deletions FluentAssertions.Autofac/BuilderAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public class BuilderAssertions : ReferenceTypeAssertions<ContainerBuilder, Build
/// Initializes a new instance of the <see cref="BuilderAssertions" /> class.
/// </summary>
/// <param name="subject"></param>
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
/// <exception cref="ArgumentNullException"></exception>
public BuilderAssertions(ContainerBuilder subject) : base(subject)
public BuilderAssertions(ContainerBuilder subject, AssertionChain assertionChain)
: base(subject, assertionChain)
{
}

Expand All @@ -56,7 +58,7 @@ public void RegisterModule(Type moduleType)
{
EnsureVisited();
var module = _modules.FirstOrDefault(m => m.GetType() == moduleType);
Execute.Assertion
CurrentAssertionChain
.ForCondition(module != null)
.FailWith($"Module '{moduleType}' should be registered but it was not.");
}
Expand Down
13 changes: 8 additions & 5 deletions FluentAssertions.Autofac/ContainerAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using Autofac;
using Autofac.Util;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;

namespace FluentAssertions.Autofac;
Expand All @@ -29,7 +30,9 @@ public class ContainerAssertions : ReferenceTypeAssertions<IComponentContext, Co
/// Initializes a new instance of the <see cref="ContainerAssertions" /> class.
/// </summary>
/// <param name="container">The subject</param>
public ContainerAssertions(IComponentContext container) : base(container)
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
public ContainerAssertions(IComponentContext container, AssertionChain assertionChain)
: base(container, assertionChain)
{
}

Expand All @@ -39,7 +42,7 @@ public ContainerAssertions(IComponentContext container) : base(container)
/// </summary>
public ContainerRegistrationAssertions Have()
{
return new ContainerRegistrationAssertions(Subject);
return new ContainerRegistrationAssertions(Subject, CurrentAssertionChain);
}

/// <summary>
Expand All @@ -48,7 +51,7 @@ public ContainerRegistrationAssertions Have()
/// </summary>
public ResolveAssertions Resolve(Type serviceType)
{
return new ResolveAssertions(Subject, serviceType);
return new ResolveAssertions(Subject, serviceType, CurrentAssertionChain);
}

/// <summary>
Expand Down Expand Up @@ -86,7 +89,7 @@ public void AutoActivate<TService>()
public TypeScanningAssertions RegisterAssemblyTypes(params Assembly[] assemblies)
{
var types = assemblies.SelectMany(assembly => assembly.GetLoadableTypes());
return new TypeScanningAssertions(Subject, types);
return new TypeScanningAssertions(Subject, types, CurrentAssertionChain);
}

/// <summary>
Expand All @@ -96,6 +99,6 @@ public TypeScanningAssertions RegisterAssemblyTypes(params Assembly[] assemblies
/// <param name="types"></param>
public TypeScanningAssertions RegisterTypes(IEnumerable<Type> types)
{
return new TypeScanningAssertions(Subject, types);
return new TypeScanningAssertions(Subject, types, CurrentAssertionChain);
}
}
13 changes: 8 additions & 5 deletions FluentAssertions.Autofac/ContainerRegistrationAssertions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Autofac;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;

namespace FluentAssertions.Autofac;
Expand All @@ -27,7 +28,9 @@ public class
/// Initializes a new instance of the <see cref="ContainerRegistrationAssertions" /> class.
/// </summary>
/// <param name="subject">The subject</param>
public ContainerRegistrationAssertions(IComponentContext subject) : base(subject)
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
public ContainerRegistrationAssertions(IComponentContext subject, AssertionChain assertionChain)
: base(subject, assertionChain)
{
}

Expand All @@ -37,7 +40,7 @@ public ContainerRegistrationAssertions(IComponentContext subject) : base(subject
/// </summary>
public RegisterAssertions Registered<TService>()
{
return new RegisterAssertions(Subject, typeof(TService));
return new RegisterAssertions(Subject, typeof(TService), CurrentAssertionChain);
}

/// <summary>
Expand All @@ -46,7 +49,7 @@ public RegisterAssertions Registered<TService>()
/// </summary>
public RegisterAssertions Registered(Type type)
{
return new RegisterAssertions(Subject, type);
return new RegisterAssertions(Subject, type, CurrentAssertionChain);
}

/// <summary>
Expand All @@ -58,7 +61,7 @@ public RegisterAssertions Registered(object instance)
if (instance == null)
throw new ArgumentNullException(nameof(instance));

return new RegisterAssertions(Subject, instance.GetType());
return new RegisterAssertions(Subject, instance.GetType(), CurrentAssertionChain);
}

/// <summary>
Expand Down Expand Up @@ -135,6 +138,6 @@ public void NotRegistered(object serviceKey, Type type)
/// </summary>
public RegisterGenericSourceAssertions RegisteredGeneric(Type genericComponentTypeDefinition)
{
return new RegisterGenericSourceAssertions(Subject, genericComponentTypeDefinition);
return new RegisterGenericSourceAssertions(Subject, genericComponentTypeDefinition, CurrentAssertionChain);
}
}
10 changes: 5 additions & 5 deletions FluentAssertions.Autofac/FluentAssertions.Autofac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
<Import Project="$(SolutionDir)\solution.targets"/>

<PropertyGroup>
<!-- https://docs.microsoft.com/en-us/dotnet/standard/frameworks#latest-target-framework-versions -->
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net48;net472;netstandard2.0;netstandard2.1</TargetFrameworks>
<!-- Match FluentAssertions 8.x supported target frameworks -->
<TargetFrameworks>net47;net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Mark the project as being a test project -->
<SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.3.0"/>
<PackageReference Include="FluentAssertions" Version="6.5.0"/>
<PackageReference Include="GitVersion.MsBuild" Version="5.8.1">
<PackageReference Include="Autofac" Version="7.1.0"/>
<PackageReference Include="FluentAssertions" Version="8.10.0"/>
<PackageReference Include="GitVersion.MsBuild" Version="6.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 5 additions & 2 deletions FluentAssertions.Autofac/RegisterAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using Autofac;
using FluentAssertions.Execution;

namespace FluentAssertions.Autofac;

Expand All @@ -19,7 +20,9 @@ public class RegisterAssertions : RegistrationAssertions
/// </summary>
/// <param name="subject">The container</param>
/// <param name="type">The type that should be registered on the container</param>
public RegisterAssertions(IComponentContext subject, Type type) : base(subject, type)
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
public RegisterAssertions(IComponentContext subject, Type type, AssertionChain assertionChain)
: base(subject, type, assertionChain)
{
}

Expand Down Expand Up @@ -67,7 +70,7 @@ public RegisterAssertions AsImplementedInterfaces()

private void AssertResolveAs(Type serviceType)
{
new ResolveAssertions(Subject, serviceType).As(Type);
new ResolveAssertions(Subject, serviceType, CurrentAssertionChain).As(Type);
}

private static List<Type> GetImplementedInterfaces(Type type)
Expand Down
10 changes: 6 additions & 4 deletions FluentAssertions.Autofac/RegisterGenericSourceAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Autofac;
using Autofac.Core;
using Autofac.Core.Resolving.Pipeline;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;

namespace FluentAssertions.Autofac;
Expand Down Expand Up @@ -33,8 +34,9 @@ public class
/// </summary>
/// <param name="subject">The component context</param>
/// <param name="type">The type that should be registered on the container</param>
public RegisterGenericSourceAssertions(IComponentContext subject, Type type) :
base(subject)
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
public RegisterGenericSourceAssertions(IComponentContext subject, Type type, AssertionChain assertionChain)
: base(subject, assertionChain)
{
AssertGenericType(type);
_type = type;
Expand All @@ -49,7 +51,7 @@ public RegistrationAssertions As(Type type)
var serviceType = GenericServiceTypeFor(type, out var componentType);
var service = new TypedService(serviceType);
var registration = RegistrationFor(type, service, componentType);
return new RegistrationAssertions(Subject, registration);
return new RegistrationAssertions(Subject, registration, CurrentAssertionChain);
}

/// <summary>
Expand All @@ -62,7 +64,7 @@ public RegistrationAssertions Named(string serviceName, Type type)
var serviceType = GenericServiceTypeFor(type, out var componentType);
var service = new KeyedService(serviceName, serviceType);
var registration = RegistrationFor(type, service, componentType);
return new RegistrationAssertions(Subject, registration);
return new RegistrationAssertions(Subject, registration, CurrentAssertionChain);
}

private IComponentRegistration RegistrationFor(Type type, Service service, Type componentType)
Expand Down
9 changes: 7 additions & 2 deletions FluentAssertions.Autofac/RegistrationAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Autofac.Core;
using Autofac.Core.Activators.Reflection;
using Autofac.Core.Lifetime;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;

namespace FluentAssertions.Autofac;
Expand Down Expand Up @@ -40,7 +41,9 @@ public class RegistrationAssertions : ReferenceTypeAssertions<IComponentContext,
/// </summary>
/// <param name="subject">The container</param>
/// <param name="type">The type that should be registered on the container</param>
public RegistrationAssertions(IComponentContext subject, Type type) : base(subject)
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
public RegistrationAssertions(IComponentContext subject, Type type, AssertionChain assertionChain)
: base(subject, assertionChain)
{
Type = type ?? throw new ArgumentNullException(nameof(type));
_registration = Subject.ComponentRegistry.GetRegistration(Type);
Expand All @@ -52,7 +55,9 @@ public RegistrationAssertions(IComponentContext subject, Type type) : base(subje
/// </summary>
/// <param name="subject">The container</param>
/// <param name="registration"></param>
public RegistrationAssertions(IComponentContext subject, IComponentRegistration registration) : base(subject)
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
public RegistrationAssertions(IComponentContext subject, IComponentRegistration registration, AssertionChain assertionChain)
: base(subject, assertionChain)
{
_registration = registration ?? throw new ArgumentNullException(nameof(registration));
Type = registration.Activator.LimitType;
Expand Down
8 changes: 5 additions & 3 deletions FluentAssertions.Autofac/ResolveAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class ResolveAssertions : ReferenceTypeAssertions<IComponentContext, Reso
/// </summary>
/// <param name="container">The container</param>
/// <param name="serviceType">The service type</param>
public ResolveAssertions(IComponentContext container, Type serviceType) : base(container)
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
public ResolveAssertions(IComponentContext container, Type serviceType, AssertionChain assertionChain)
: base(container, assertionChain)
{
_serviceType = serviceType;
var typeToResolve = typeof(IEnumerable<>).MakeGenericType(serviceType);
Expand All @@ -42,7 +44,7 @@ public ResolveAssertions(IComponentContext container, Type serviceType) : base(c
_instances.AddRange(array.OfType<object>());
}

Execute.Assertion
CurrentAssertionChain
.ForCondition(_instances.Any())
.FailWith($"Expected container to resolve '{_serviceType}' but it did not.");
}
Expand All @@ -66,7 +68,7 @@ public RegistrationAssertions As(Type type, params Type[] types)
{
AssertTypeResolved(type);
types.ToList().ForEach(AssertTypeResolved);
return new RegistrationAssertions(Subject, type);
return new RegistrationAssertions(Subject, type, CurrentAssertionChain);
}

/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions FluentAssertions.Autofac/TypeScanningAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Autofac;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;

namespace FluentAssertions.Autofac;
Expand Down Expand Up @@ -39,12 +40,14 @@ public class TypeScanningAssertions : ReferenceTypeAssertions<IComponentContext,
/// </summary>
/// <param name="subject"></param>
/// <param name="types">The types to assert</param>
/// <param name="assertionChain">The current <see cref="AssertionChain"/></param>
/// <exception cref="ArgumentNullException"></exception>
public TypeScanningAssertions(IComponentContext subject, IEnumerable<Type> types) : base(subject)
public TypeScanningAssertions(IComponentContext subject, IEnumerable<Type> types, AssertionChain assertionChain)
: base(subject, assertionChain)
{
Types = FilterTypes(types);
_registerAssertions = new Lazy<List<RegisterAssertions>>(
() => Types.Select(t => Subject.Should().Have().Registered(t)).ToList());
() => Types.Select(t => new ContainerRegistrationAssertions(Subject, CurrentAssertionChain).Registered(t)).ToList());
}

/// <summary>
Expand All @@ -53,7 +56,7 @@ public TypeScanningAssertions(IComponentContext subject, IEnumerable<Type> types
/// </summary>
public TypeScanningAssertions Where(Func<Type, bool> predicate)
{
return new TypeScanningAssertions(Subject, Types.Where(predicate));
return new TypeScanningAssertions(Subject, Types.Where(predicate), CurrentAssertionChain);
}

/// <summary>
Expand Down
Loading
Loading