I've got an issue in Unit Testing that I've been unable to solve. I think the most succinct way to say it is:
I want to be able to use a Type provided in a Theory InlineAutoMoqData's parameters as the T in Shouldly's Should.Throw method. This would allow me to create different Row Tests (I guess that's Inline Theories in this framework) expecting varying Exception types, should there be multiple associated with a method.
I am unsure if it's possible, but here is an example of the unit test itself.
[Theory]
[InlineAutoMoqData("bork", typeof(FileTypeNotRecognizedException))]
public void Build_ReturnsSpecificException_FileNamePassedIn(string fileName, Type expected, ProcessFactory sut)
{
Should.Throw<expected>(() => sut.Build(fileName));
}
The questions I looked at, before getting stumped and posting this, were: Dynamically Create a generic type for template and Creating a Generic<T> type instance with a variable containing the Type
Is something like this possible?
Edit:
I see that in xUnit I can achieve this via the Assert.Throws(Type, Delegate) method.
[Theory]
[InlineAutoMoqData("bork", typeof(FileTypeNotRecognizedException))]
public void Build_ReturnsSpecificException_FileNamePassedIn(string fileName, Type expected, ProcessFactory sut)
{
Assert.Throws(expected, () => sut.Build(fileName));
}
I would still like to know if there is a way to achieve it whenever I want the Type to be in a Generic Method.