Make application's level IServiceProvider available in classes implementing IScenarioAssertion
tjaskula opened this issue · 4 comments
In some cases there is a need to resolve a service from within the class implementing the IScenarionAssertion
interface.
Ex:
public class SuccessResultAssertion : GraphQLAssertion
{
private readonly string _result;
public SuccessResultAssertion(string result) => _result = result;
public override void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex)
{
var writer = (IDocumentWriter) context.RequestServices.GetService(typeof(IDocumentWriter));
var expectedResult = writer.Write(CreateQueryResult(_result));
var body = ex.ReadBody(context);
if (!body.Equals(expectedResult))
{
ex.Add($"Expected '{expectedResult}' but got '{body}'");
}
}
}
Theoritecally we could use passed in HttpContext
to resolve the service like in the example but it happens that sometimes passed in context.RequestServices
is null
Maybe it would help either exposing Services
on the scenario passed it, or by another means ?
If I run a series of test, for the first test I can resolve service from context.RequestServices
but for all next runing services context.RequestServices
will be always null. I'm still not sure why this happens as SystemUnderTests
is disposed each time a test runs.
What do you think?
Hi @jeremydmiller. Any news on that one ? I can take over if you're out of time.
Oh shoot, sorry, I'd lost track of this altogether. I'm never going to turn down a pull request if you're game;)
Ok, I'll try then my best :)
@jeremydmiller After forking the repo I was unable to write an unit test that would reproduce the incorrect behavior I had. After further investigation I noticed that this has something to do with GraphQL middleware. I consider it's not Alba issue so I'm closing this issue as exposing application wide services is no longer necessary.