refactor: Move RegisterMockFor to extension method

pull/151/head
Robert Dailey 1 year ago
parent c981a555ad
commit 51d0219a1a

@ -21,12 +21,12 @@ public static class FluentValidationExtensions
public static IEnumerable<TSource> IsValid<TSource, TValidator>(
this IEnumerable<TSource> source, TValidator validator,
Action<List<ValidationFailure>, TSource>? handleInvalid = null)
where TValidator : IValidator<TSource>, new()
where TValidator : IValidator<TSource>
{
foreach (var s in source)
{
var result = validator.Validate(s);
if (result.IsValid)
if (result is {IsValid: true})
{
yield return s;
}

@ -5,11 +5,11 @@ using Autofac;
using Autofac.Features.ResolveAnything;
using CliFx.Infrastructure;
using Common.TestLibrary;
using NSubstitute;
using NUnit.Framework;
using Recyclarr.Command;
using Serilog;
using Serilog.Events;
using TestLibrary;
using TrashLib;
using TrashLib.Repo.VersionControl;
using TrashLib.Startup;
@ -31,9 +31,9 @@ public abstract class IntegrationFixture : IDisposable
builder.RegisterInstance(Console).As<IConsole>();
builder.RegisterInstance(Logger).As<ILogger>().SingleInstance();
RegisterMockFor<IServiceCommand>(builder);
RegisterMockFor<IGitRepository>(builder);
RegisterMockFor<IGitRepositoryFactory>(builder);
builder.RegisterMockFor<IServiceCommand>();
builder.RegisterMockFor<IGitRepository>();
builder.RegisterMockFor<IGitRepositoryFactory>();
RegisterExtraTypes(builder);
@ -73,11 +73,6 @@ public abstract class IntegrationFixture : IDisposable
// ReSharper restore MemberCanBePrivate.Global
private static void RegisterMockFor<T>(ContainerBuilder builder) where T : class
{
builder.RegisterInstance(Substitute.For<T>()).As<T>();
}
protected T Resolve<T>() where T : notnull
{
return Container.Resolve<T>();

@ -2,5 +2,6 @@
<ItemGroup>
<ProjectReference Include="..\Common.TestLibrary\Common.TestLibrary.csproj" />
<ProjectReference Include="..\Recyclarr\Recyclarr.csproj" />
<ProjectReference Include="..\TestLibrary\TestLibrary.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,12 @@
using Autofac;
using NSubstitute;
namespace TestLibrary;
public static class AutofacTestExtensions
{
public static void RegisterMockFor<T>(this ContainerBuilder builder) where T : class
{
builder.RegisterInstance(Substitute.For<T>()).As<T>();
}
}
Loading…
Cancel
Save