diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 0aec135..64629e0 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -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
@@ -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:
diff --git a/FluentAssertions.Autofac.Tests/FluentAssertions.Autofac.Tests.csproj b/FluentAssertions.Autofac.Tests/FluentAssertions.Autofac.Tests.csproj
index ae7da4c..040da76 100644
--- a/FluentAssertions.Autofac.Tests/FluentAssertions.Autofac.Tests.csproj
+++ b/FluentAssertions.Autofac.Tests/FluentAssertions.Autofac.Tests.csproj
@@ -6,10 +6,7 @@
-
-
-
- net6.0
+ net8.0
false
FluentAssertions.Autofac
@@ -17,16 +14,16 @@
-
-
-
-
-
-
+
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/FluentAssertions.Autofac/AutofacAssertionExtensions.cs b/FluentAssertions.Autofac/AutofacAssertionExtensions.cs
index 133095b..314508f 100644
--- a/FluentAssertions.Autofac/AutofacAssertionExtensions.cs
+++ b/FluentAssertions.Autofac/AutofacAssertionExtensions.cs
@@ -1,4 +1,5 @@
using Autofac;
+using FluentAssertions.Execution;
namespace FluentAssertions.Autofac;
@@ -15,16 +16,12 @@ public static class AutofacAssertionExtensions
/// (e.g. or ).
///
public static ContainerAssertions Should(this IComponentContext container)
- {
- return new ContainerAssertions(container);
- }
+ => new(container, AssertionChain.GetOrCreate());
///
/// Returns an object that can be used to assert the current
/// .
///
public static BuilderAssertions Should(this ContainerBuilder builder)
- {
- return new BuilderAssertions(builder);
- }
+ => new(builder, AssertionChain.GetOrCreate());
}
diff --git a/FluentAssertions.Autofac/BuilderAssertions.cs b/FluentAssertions.Autofac/BuilderAssertions.cs
index ddf2f30..4ec1943 100644
--- a/FluentAssertions.Autofac/BuilderAssertions.cs
+++ b/FluentAssertions.Autofac/BuilderAssertions.cs
@@ -34,8 +34,9 @@ public class BuilderAssertions : ReferenceTypeAssertions class.
///
///
- ///
- public BuilderAssertions(ContainerBuilder subject) : base(subject)
+ /// The current
+ public BuilderAssertions(ContainerBuilder subject, AssertionChain assertionChain)
+ : base(subject, assertionChain)
{
}
@@ -44,9 +45,7 @@ public BuilderAssertions(ContainerBuilder subject) : base(subject)
///
/// The module type
public void RegisterModule() where TModule : Module, new()
- {
- RegisterModule(typeof(TModule));
- }
+ => RegisterModule(typeof(TModule));
///
/// Asserts that the specified module type has been registered on the current .
@@ -56,7 +55,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.");
}
diff --git a/FluentAssertions.Autofac/ContainerAssertions.cs b/FluentAssertions.Autofac/ContainerAssertions.cs
index 8c74fae..0225403 100644
--- a/FluentAssertions.Autofac/ContainerAssertions.cs
+++ b/FluentAssertions.Autofac/ContainerAssertions.cs
@@ -5,6 +5,7 @@
using System.Reflection;
using Autofac;
using Autofac.Util;
+using FluentAssertions.Execution;
using FluentAssertions.Primitives;
namespace FluentAssertions.Autofac;
@@ -29,7 +30,9 @@ public class ContainerAssertions : ReferenceTypeAssertions class.
///
/// The subject
- public ContainerAssertions(IComponentContext container) : base(container)
+ /// The current
+ public ContainerAssertions(IComponentContext container, AssertionChain assertionChain)
+ : base(container, assertionChain)
{
}
@@ -38,45 +41,35 @@ public ContainerAssertions(IComponentContext container) : base(container)
/// .
///
public ContainerRegistrationAssertions Have()
- {
- return new ContainerRegistrationAssertions(Subject);
- }
+ => new(Subject, CurrentAssertionChain);
///
/// Returns an object that can be used to assert the current
/// .
///
public ResolveAssertions Resolve(Type serviceType)
- {
- return new ResolveAssertions(Subject, serviceType);
- }
+ => new(Subject, serviceType, CurrentAssertionChain);
///
/// Returns an object that can be used to assert the current
/// .
///
public ResolveAssertions Resolve()
- {
- return Resolve(typeof(TService));
- }
+ => Resolve(typeof(TService));
///
/// Asserts the specified type has been registered with auto activation on the current
/// .
///
public void AutoActivate(Type type)
- {
- Subject.AssertAutoActivates(type);
- }
+ => Subject.AssertAutoActivates(type);
///
/// Asserts the specified type has been registered with auto activation on the current
/// .
///
public void AutoActivate()
- {
- AutoActivate(typeof(TService));
- }
+ => AutoActivate(typeof(TService));
///
/// Returns an object that can be used to assert registered types on the current
@@ -86,7 +79,7 @@ public void AutoActivate()
public TypeScanningAssertions RegisterAssemblyTypes(params Assembly[] assemblies)
{
var types = assemblies.SelectMany(assembly => assembly.GetLoadableTypes());
- return new TypeScanningAssertions(Subject, types);
+ return new TypeScanningAssertions(Subject, types, CurrentAssertionChain);
}
///
@@ -95,7 +88,5 @@ public TypeScanningAssertions RegisterAssemblyTypes(params Assembly[] assemblies
///
///
public TypeScanningAssertions RegisterTypes(IEnumerable types)
- {
- return new TypeScanningAssertions(Subject, types);
- }
+ => new(Subject, types, CurrentAssertionChain);
}
diff --git a/FluentAssertions.Autofac/ContainerRegistrationAssertions.cs b/FluentAssertions.Autofac/ContainerRegistrationAssertions.cs
index d2e5342..8234935 100644
--- a/FluentAssertions.Autofac/ContainerRegistrationAssertions.cs
+++ b/FluentAssertions.Autofac/ContainerRegistrationAssertions.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Autofac;
+using FluentAssertions.Execution;
using FluentAssertions.Primitives;
namespace FluentAssertions.Autofac;
@@ -13,8 +14,8 @@ namespace FluentAssertions.Autofac;
#if !DEBUG
[System.Diagnostics.DebuggerNonUserCode]
#endif
-public class
- ContainerRegistrationAssertions : ReferenceTypeAssertions
+public class ContainerRegistrationAssertions
+ : ReferenceTypeAssertions
{
///
///
@@ -27,7 +28,9 @@ public class
/// Initializes a new instance of the class.
///
/// The subject
- public ContainerRegistrationAssertions(IComponentContext subject) : base(subject)
+ /// The current
+ public ContainerRegistrationAssertions(IComponentContext subject, AssertionChain assertionChain)
+ : base(subject, assertionChain)
{
}
@@ -36,18 +39,14 @@ public ContainerRegistrationAssertions(IComponentContext subject) : base(subject
/// and .
///
public RegisterAssertions Registered()
- {
- return new RegisterAssertions(Subject, typeof(TService));
- }
+ => new(Subject, typeof(TService), CurrentAssertionChain);
///
/// Returns an object that can be used to assert the current
/// and the specified type.
///
public RegisterAssertions Registered(Type type)
- {
- return new RegisterAssertions(Subject, type);
- }
+ => new(Subject, type, CurrentAssertionChain);
///
/// Returns an object that can be used to assert the current
@@ -55,10 +54,8 @@ public RegisterAssertions Registered(Type type)
///
public RegisterAssertions Registered(object instance)
{
- if (instance == null)
- throw new ArgumentNullException(nameof(instance));
-
- return new RegisterAssertions(Subject, instance.GetType());
+ ArgumentNullException.ThrowIfNull(instance);
+ return new RegisterAssertions(Subject, instance.GetType(), CurrentAssertionChain);
}
///
@@ -66,19 +63,14 @@ public RegisterAssertions Registered(object instance)
/// .
///
/// The service type
- public void NotRegistered()
- {
- NotRegistered(typeof(TService));
- }
+ public void NotRegistered() => NotRegistered(typeof(TService));
///
/// Asserts that the specified service type has not been registered on the current .
///
/// The service type
public void NotRegistered(Type type)
- {
- Subject.IsRegistered(type).Should().BeFalse($"Type '{type}' should not be registered");
- }
+ => Subject.IsRegistered(type).Should().BeFalse($"Type '{type}' should not be registered");
///
/// Asserts that the specified has not been registered on the current
@@ -86,55 +78,40 @@ public void NotRegistered(Type type)
///
/// The service name
/// The service type
- public void NotRegistered(string serviceName)
- {
- NotRegistered(serviceName, typeof(TService));
- }
+ public void NotRegistered(string serviceName) => NotRegistered(serviceName, typeof(TService));
///
/// Asserts that the specified service type has not been registered on the current
- /// with the
- /// specified name.
+ /// with the specified name.
///
/// The service name
/// The service type
public void NotRegistered(string serviceName, Type type)
- {
- Subject.IsRegisteredWithName(serviceName, type).Should()
+ => Subject.IsRegisteredWithName(serviceName, type).Should()
.BeFalse($"Type '{type}' should not be registered with name '{serviceName}'");
- }
///
/// Asserts that the specified service type has not been registered on the current
- /// with the
- /// specified key.
+ /// with the specified key.
///
/// The service key
/// The service type
- public void NotRegistered(object serviceKey)
- {
- NotRegistered(serviceKey, typeof(TService));
- }
+ public void NotRegistered(object serviceKey) => NotRegistered(serviceKey, typeof(TService));
///
/// Asserts that the specified service type has not been registered on the current
- /// with the
- /// specified key.
+ /// with the specified key.
///
/// The service key
/// The service type
public void NotRegistered(object serviceKey, Type type)
- {
- Subject.IsRegisteredWithKey(serviceKey, type).Should()
+ => Subject.IsRegisteredWithKey(serviceKey, type).Should()
.BeFalse($"Type '{type}' should not be registered with key '{serviceKey}'");
- }
///
/// Returns an object that can be used to assert the current
/// and the specified generic type.
///
public RegisterGenericSourceAssertions RegisteredGeneric(Type genericComponentTypeDefinition)
- {
- return new RegisterGenericSourceAssertions(Subject, genericComponentTypeDefinition);
- }
+ => new(Subject, genericComponentTypeDefinition, CurrentAssertionChain);
}
diff --git a/FluentAssertions.Autofac/FluentAssertions.Autofac.csproj b/FluentAssertions.Autofac/FluentAssertions.Autofac.csproj
index e0c9dbf..1481f49 100644
--- a/FluentAssertions.Autofac/FluentAssertions.Autofac.csproj
+++ b/FluentAssertions.Autofac/FluentAssertions.Autofac.csproj
@@ -5,17 +5,17 @@
-
- net6.0;net5.0;netcoreapp3.1;net48;net472;netstandard2.0;netstandard2.1
+
+ net47;net6.0;netstandard2.0;netstandard2.1
true
false
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/FluentAssertions.Autofac/RegisterAssertions.cs b/FluentAssertions.Autofac/RegisterAssertions.cs
index 193b364..7b1c55f 100644
--- a/FluentAssertions.Autofac/RegisterAssertions.cs
+++ b/FluentAssertions.Autofac/RegisterAssertions.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using Autofac;
+using FluentAssertions.Execution;
namespace FluentAssertions.Autofac;
@@ -19,7 +20,9 @@ public class RegisterAssertions : RegistrationAssertions
///
/// The container
/// The type that should be registered on the container
- public RegisterAssertions(IComponentContext subject, Type type) : base(subject, type)
+ /// The current
+ public RegisterAssertions(IComponentContext subject, Type type, AssertionChain assertionChain)
+ : base(subject, type, assertionChain)
{
}
@@ -50,10 +53,7 @@ public RegisterAssertions As(Type type, params Type[] types)
///
/// Asserts that the registered service type can be resolved from the current .
///
- public RegisterAssertions AsSelf()
- {
- return As(Type);
- }
+ public RegisterAssertions AsSelf() => As(Type);
///
/// Asserts that all implemented interfaces of the registered service type can be resolved from the current
@@ -66,9 +66,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 GetImplementedInterfaces(Type type)
{
diff --git a/FluentAssertions.Autofac/RegisterGenericSourceAssertions.cs b/FluentAssertions.Autofac/RegisterGenericSourceAssertions.cs
index b042d29..14523a8 100644
--- a/FluentAssertions.Autofac/RegisterGenericSourceAssertions.cs
+++ b/FluentAssertions.Autofac/RegisterGenericSourceAssertions.cs
@@ -5,6 +5,7 @@
using Autofac;
using Autofac.Core;
using Autofac.Core.Resolving.Pipeline;
+using FluentAssertions.Execution;
using FluentAssertions.Primitives;
namespace FluentAssertions.Autofac;
@@ -16,8 +17,8 @@ namespace FluentAssertions.Autofac;
#if !DEBUG
[System.Diagnostics.DebuggerNonUserCode]
#endif
-public class
- RegisterGenericSourceAssertions : ReferenceTypeAssertions
+public class RegisterGenericSourceAssertions
+ : ReferenceTypeAssertions
{
private readonly Type _type;
@@ -33,8 +34,9 @@ public class
///
/// The component context
/// The type that should be registered on the container
- public RegisterGenericSourceAssertions(IComponentContext subject, Type type) :
- base(subject)
+ /// The current
+ public RegisterGenericSourceAssertions(IComponentContext subject, Type type, AssertionChain assertionChain)
+ : base(subject, assertionChain)
{
AssertGenericType(type);
_type = type;
@@ -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);
}
///
@@ -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)
@@ -78,8 +80,7 @@ private IComponentRegistration RegistrationFor(Type type, Service service, Type
private Type GenericServiceTypeFor(Type type, out Type componentType)
{
AssertGenericType(type);
- var componentServicePairText =
- $"Component={_type.FullName} Service={type.FullName}";
+ var componentServicePairText = $"Component={_type.FullName} Service={type.FullName}";
_type.GetGenericArguments().Should().HaveCount(type.GetGenericArguments().Length,
$"the generic arguments count of both generic component and generic service must be equal. {componentServicePairText}.");
@@ -90,7 +91,7 @@ private Type GenericServiceTypeFor(Type type, out Type componentType)
var serviceType = type.MakeGenericType(argumentTypes);
componentType.Should().Implement(serviceType,
- $"component must implement specified service. {componentServicePairText}.");
+ $"component must implement specified service. {componentServicePairText}.");
return serviceType;
}
@@ -113,9 +114,6 @@ private static void AssertGenericType(Type type)
throw new ArgumentNullException(nameof(type));
if (!type.IsGenericTypeDefinition)
- {
- throw new ArgumentException("Type must be a generic type definition.",
- nameof(type));
- }
+ throw new ArgumentException("Type must be a generic type definition.", nameof(type));
}
}
diff --git a/FluentAssertions.Autofac/RegistrationAssertions.cs b/FluentAssertions.Autofac/RegistrationAssertions.cs
index eda3c1a..f180049 100644
--- a/FluentAssertions.Autofac/RegistrationAssertions.cs
+++ b/FluentAssertions.Autofac/RegistrationAssertions.cs
@@ -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;
@@ -40,7 +41,9 @@ public class RegistrationAssertions : ReferenceTypeAssertions
/// The container
/// The type that should be registered on the container
- public RegistrationAssertions(IComponentContext subject, Type type) : base(subject)
+ /// The current
+ public RegistrationAssertions(IComponentContext subject, Type type, AssertionChain assertionChain)
+ : base(subject, assertionChain)
{
Type = type ?? throw new ArgumentNullException(nameof(type));
_registration = Subject.ComponentRegistry.GetRegistration(Type);
@@ -52,7 +55,9 @@ public RegistrationAssertions(IComponentContext subject, Type type) : base(subje
///
/// The container
///
- public RegistrationAssertions(IComponentContext subject, IComponentRegistration registration) : base(subject)
+ /// The current
+ public RegistrationAssertions(IComponentContext subject, IComponentRegistration registration, AssertionChain assertionChain)
+ : base(subject, assertionChain)
{
_registration = registration ?? throw new ArgumentNullException(nameof(registration));
Type = registration.Activator.LimitType;
@@ -65,10 +70,7 @@ public RegistrationAssertions(IComponentContext subject, IComponentRegistration
///
/// The service name
/// The service type
- public RegistrationAssertions Named(string name)
- {
- return Named(name, typeof(TService));
- }
+ public RegistrationAssertions Named(string name) => Named(name, typeof(TService));
///
/// Asserts that the specified has been registered on the current
@@ -90,10 +92,7 @@ public RegistrationAssertions Named(string name, Type type)
///
/// The service key
/// The service type
- public RegistrationAssertions Keyed(object key)
- {
- return Keyed(key, typeof(TService));
- }
+ public RegistrationAssertions Keyed(object key) => Keyed(key, typeof(TService));
///
/// Asserts that the specified has been registered on the current
@@ -113,59 +112,41 @@ public RegistrationAssertions Keyed(object key, Type type)
/// .
///
public RegistrationAssertions SingleInstance()
- {
- return Lifetime()
- .Shared(InstanceSharing.Shared);
- }
+ => Lifetime().Shared(InstanceSharing.Shared);
///
/// Asserts that the current service type has been registered as 'instance per dependency' on the current
/// .
///
public RegistrationAssertions InstancePerDependency()
- {
- return Lifetime()
- .Shared(InstanceSharing.None);
- }
+ => Lifetime().Shared(InstanceSharing.None);
///
/// Asserts that the current service type has been registered as 'instance per lifetime scope' on the current
/// .
///
public RegistrationAssertions InstancePerLifetimeScope()
- {
- return Lifetime()
- .Shared(InstanceSharing.Shared);
- }
+ => Lifetime().Shared(InstanceSharing.Shared);
///
/// Asserts that the current service type has been registered as 'instance per matching lifetime scope' on the current
/// .
///
public RegistrationAssertions InstancePerMatchingLifetimeScope()
- {
- return Lifetime()
- .Shared(InstanceSharing.Shared);
- }
+ => Lifetime().Shared(InstanceSharing.Shared);
///
/// Asserts that the current service type has been registered as 'instance per request' on the current
/// .
///
public RegistrationAssertions InstancePerRequest()
- {
- return Lifetime()
- .Shared(InstanceSharing.Shared);
- }
+ => Lifetime().Shared(InstanceSharing.Shared);
///
/// Asserts that the current service type has been registered as 'instance per owned' of the specified
/// on the current .
///
- public RegistrationAssertions InstancePerOwned()
- {
- return InstancePerOwned(typeof(TService));
- }
+ public RegistrationAssertions InstancePerOwned() => InstancePerOwned(typeof(TService));
///
/// Asserts that the current service type has been registered as 'instance per owned' of the specified
@@ -181,19 +162,13 @@ public RegistrationAssertions InstancePerOwned(Type serviceType)
/// Asserts that the current service type has been registered as 'externally owned' on the current
/// .
///
- public RegistrationAssertions ExternallyOwned()
- {
- return Owned(InstanceOwnership.ExternallyOwned);
- }
+ public RegistrationAssertions ExternallyOwned() => Owned(InstanceOwnership.ExternallyOwned);
///
/// Asserts that the current service type has been registered as 'owned by lifetime scope' on the current
/// .
///
- public RegistrationAssertions OwnedByLifetimeScope()
- {
- return Owned(InstanceOwnership.OwnedByLifetimeScope);
- }
+ public RegistrationAssertions OwnedByLifetimeScope() => Owned(InstanceOwnership.OwnedByLifetimeScope);
///
/// Asserts the current service type has been registered using the specified on the
@@ -248,9 +223,7 @@ public RegistrationAssertions AutoActivate()
/// The parameter name
/// The parameter value
public RegistrationAssertions WithParameter(string name, object value)
- {
- return WithParameter(new NamedParameter(name, value));
- }
+ => WithParameter(new NamedParameter(name, value));
///
/// Asserts the current service type has been registered with the specified constructor parameter.
@@ -264,9 +237,7 @@ public RegistrationAssertions WithParameter(string name, object value)
/// .
///
///
- public RegistrationAssertions WithParameter(
- Func predicate,
- int? matchCount = null)
+ public RegistrationAssertions WithParameter(Func predicate, int? matchCount = null)
{
var matchingParams = _parameters.Where(predicate);
@@ -275,8 +246,7 @@ public RegistrationAssertions WithParameter(
matchingParams
.Count()
.Should()
- .Be(
- matchCount.Value,
+ .Be(matchCount.Value,
$"exactly {matchCount.Value} parameter(s) matching a predicate should have been registered");
}
else
@@ -328,24 +298,18 @@ private static IList GetParameters(IComponentRegistration registratio
{
var parameters = new List();
- if (!(registration.Activator is ReflectionActivator activator))
- {
+ if (registration.Activator is not ReflectionActivator activator)
return parameters;
- }
const string fieldName = "_defaultParameters";
const BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Static;
var field = activator.GetType().GetField(fieldName, bindFlags);
if (field == null)
- {
return parameters;
- }
if (field.GetValue(activator) is Parameter[] p)
- {
parameters.AddRange(p);
- }
return parameters;
}
diff --git a/FluentAssertions.Autofac/ResolveAssertions.cs b/FluentAssertions.Autofac/ResolveAssertions.cs
index 9e51483..abc630b 100644
--- a/FluentAssertions.Autofac/ResolveAssertions.cs
+++ b/FluentAssertions.Autofac/ResolveAssertions.cs
@@ -33,7 +33,9 @@ public class ResolveAssertions : ReferenceTypeAssertions
/// The container
/// The service type
- public ResolveAssertions(IComponentContext container, Type serviceType) : base(container)
+ /// The current
+ public ResolveAssertions(IComponentContext container, Type serviceType, AssertionChain assertionChain)
+ : base(container, assertionChain)
{
_serviceType = serviceType;
var typeToResolve = typeof(IEnumerable<>).MakeGenericType(serviceType);
@@ -42,7 +44,7 @@ public ResolveAssertions(IComponentContext container, Type serviceType) : base(c
_instances.AddRange(array.OfType
/// The type to resolve
// ReSharper disable once UnusedMember.Global
- public RegistrationAssertions As()
- {
- return As(typeof(TImplementation));
- }
+ public RegistrationAssertions As() => As(typeof(TImplementation));
///
/// Asserts that the specified implementation type(s) can be resolved from the current .
@@ -66,30 +65,21 @@ 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);
}
///
/// Asserts that the registered service type can be resolved from the current .
///
- public RegistrationAssertions AsSelf()
- {
- return As(_serviceType);
- }
-
+ public RegistrationAssertions AsSelf() => As(_serviceType);
///
/// Asserts that the service type has been registered with auto activation on the current
/// .
///
- public void AutoActivate()
- {
- Subject.AssertAutoActivates(_serviceType);
- }
+ public void AutoActivate() => Subject.AssertAutoActivates(_serviceType);
private void AssertTypeResolved(Type type)
- {
- _instances.Should().Contain(instance => instance.GetType() == type,
+ => _instances.Should().Contain(instance => instance.GetType() == type,
$"Type '{_serviceType}' should be resolved as '{type}'");
- }
}
diff --git a/FluentAssertions.Autofac/TypeScanningAssertions.cs b/FluentAssertions.Autofac/TypeScanningAssertions.cs
index aabd153..fc7cf5e 100644
--- a/FluentAssertions.Autofac/TypeScanningAssertions.cs
+++ b/FluentAssertions.Autofac/TypeScanningAssertions.cs
@@ -5,6 +5,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Autofac;
+using FluentAssertions.Execution;
using FluentAssertions.Primitives;
namespace FluentAssertions.Autofac;
@@ -39,12 +40,13 @@ public class TypeScanningAssertions : ReferenceTypeAssertions
///
/// The types to assert
- ///
- public TypeScanningAssertions(IComponentContext subject, IEnumerable types) : base(subject)
+ /// The current
+ public TypeScanningAssertions(IComponentContext subject, IEnumerable types, AssertionChain assertionChain)
+ : base(subject, assertionChain)
{
Types = FilterTypes(types);
_registerAssertions = new Lazy>(
- () => Types.Select(t => Subject.Should().Have().Registered(t)).ToList());
+ () => Types.Select(t => new ContainerRegistrationAssertions(Subject, CurrentAssertionChain).Registered(t)).ToList());
}
///
@@ -52,26 +54,18 @@ public TypeScanningAssertions(IComponentContext subject, IEnumerable types
/// the specified .
///
public TypeScanningAssertions Where(Func predicate)
- {
- return new TypeScanningAssertions(Subject, Types.Where(predicate));
- }
+ => new(Subject, Types.Where(predicate), CurrentAssertionChain);
///
/// Specifies a subset of types to register from a scanned assembly.
///
- public TypeScanningAssertions Except()
- {
- return Where(t => t != typeof(T));
- }
+ public TypeScanningAssertions Except() => Where(t => t != typeof(T));
///
/// Asserts that the scanned types can be resolved from the current
/// as the specified .
///
- public TypeScanningAssertions As()
- {
- return As(typeof(T));
- }
+ public TypeScanningAssertions As() => As(typeof(T));
///
/// Asserts that the scanned types can be resolved from the current
@@ -122,13 +116,8 @@ private static IEnumerable FilterTypes(IEnumerable types)
!IsCompilerGenerated(t));
}
- private static bool IsDelegate(Type type)
- {
- return type.GetTypeInfo().IsSubclassOf(typeof(Delegate));
- }
+ private static bool IsDelegate(Type type) => type.GetTypeInfo().IsSubclassOf(typeof(Delegate));
private static bool IsCompilerGenerated(Type type)
- {
- return type.GetTypeInfo().GetCustomAttributes().Any();
- }
+ => type.GetTypeInfo().GetCustomAttributes().Any();
}
diff --git a/GitVersion.yml b/GitVersion.yml
index 92865d2..0afe0bd 100644
--- a/GitVersion.yml
+++ b/GitVersion.yml
@@ -1,2 +1,3 @@
mode: ContinuousDelivery
+next-version: 8.0.0
branches: { }
diff --git a/SampleLib/SampleLib.csproj b/SampleLib/SampleLib.csproj
index 9d7134c..f0c63ba 100644
--- a/SampleLib/SampleLib.csproj
+++ b/SampleLib/SampleLib.csproj
@@ -1,28 +1,28 @@
-
-
- net6.0
- False
- false
-
-
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
-
-
+
+
+ net8.0
+ False
+ false
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
diff --git a/build/Build.cs b/build/Build.cs
index 41f3d8c..05d3b90 100644
--- a/build/Build.cs
+++ b/build/Build.cs
@@ -12,11 +12,8 @@
using Nuke.Common.Tools.ReportGenerator;
using Nuke.Common.Tools.SonarScanner;
using Nuke.Common.Utilities.Collections;
-using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
-[CheckBuildProjectConfigurations]
-[UnsetVisualStudioEnvironmentVariables]
// NUKE CI Integration: http://www.nuke.build/docs/authoring-builds/ci-integration.html
[GitHubActions("build", GitHubActionsImage.WindowsLatest,
AutoGenerate = false,
@@ -41,7 +38,7 @@ class Build : NukeBuild
{
TestsDirectory
.GlobDirectories("**/bin", "**/obj", "**/TestResults")
- .ForEach(DeleteDirectory);
+ .ForEach(d => d.DeleteDirectory());
});
Target Restore => _ => _
@@ -197,7 +194,7 @@ class Build : NukeBuild
[Solution] readonly Solution Solution;
- const string Framework = "net6.0";
+ const string Framework = "net8.0";
[GitVersion(Framework = Framework, NoFetch = true)] readonly GitVersion GitVersion;
[Parameter("The SonarQube login token")]
diff --git a/build/_build.csproj b/build/_build.csproj
index 9da2166..1db8f97 100644
--- a/build/_build.csproj
+++ b/build/_build.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net8.0
CS0649;CS0169
..
..
@@ -10,8 +10,8 @@
-
-
+
+
diff --git a/global.json b/global.json
index e780aca..34fe4d4 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "6.0.101",
+ "version": "8.0.100",
"rollForward": "latestMajor",
"allowPrerelease": true
}
diff --git a/solution.targets b/solution.targets
index b502228..8c658b1 100644
--- a/solution.targets
+++ b/solution.targets
@@ -13,12 +13,14 @@
FluentAssertions.Autofac
FluentAssertions
en
- Copyright © FluentAssertions 2017-2020
+ Copyright © FluentAssertions 2017-2026
Fluent Assertions extensions for Autofac
Apache-2.0
autofac;fluent-assertions;ioc;tdd;dotnet-core
https://github.com/fluentassertions/fluentassertions.autofac
+
+ 8.0.0-pre.1
false