-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from SkillsFundingAgency/MF-255-non-eoi-add-a…
…pprentice MF-255 Non-EOI select apprentice
- Loading branch information
Showing
16 changed files
with
420 additions
and
360 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/SFA.DAS.Reservations.Web.UnitTests/Customisations/ArrangeActionContextAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Reflection; | ||
using AutoFixture; | ||
using AutoFixture.Kernel; | ||
using AutoFixture.NUnit3; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace SFA.DAS.Reservations.Web.UnitTests.Customisations | ||
{ | ||
[AttributeUsage(AttributeTargets.Parameter)] | ||
public class ArrangeActionContextAttribute : CustomizeAttribute | ||
{ | ||
public override ICustomization GetCustomization(ParameterInfo parameter) | ||
{ | ||
if (parameter == null) | ||
{ | ||
throw new ArgumentNullException(nameof(parameter)); | ||
} | ||
|
||
if (parameter.ParameterType != typeof(ActionExecutingContext)) | ||
{ | ||
throw new ArgumentException(nameof(parameter)); | ||
} | ||
|
||
return new ArrangeActionContextCustomisation(); | ||
} | ||
} | ||
|
||
public class ArrangeActionContextCustomisation : ICustomization | ||
{ | ||
public void Customize(IFixture fixture) | ||
{ | ||
fixture.Customizations.Add(new ActionExecutingContextBuilder()); | ||
fixture.Customize<ActionExecutingContext>(composer => composer | ||
.Without(context => context.Result)); | ||
} | ||
} | ||
|
||
public class ActionExecutingContextBuilder : ISpecimenBuilder | ||
{ | ||
public object Create(object request, ISpecimenContext context) | ||
{ | ||
if (request is ParameterInfo paramInfo | ||
&& paramInfo.ParameterType == typeof(object) | ||
&& paramInfo.Name == "controller") | ||
{ | ||
return context.Create<Controller>(); | ||
} | ||
|
||
return new NoSpecimen(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.