There are now a number of options that can be set (and infinite combinations with custom MockHandlers). Some of these I find I need to use in the same way for an entire test suite. Currently, I'm using a custom extension method, but the drawback is it has to be called on every builder, ie:
internal static class MyCustomAutoSubstituteExtensions
{
public static AutoSubstituteBuilder AddCustomExtensions(this AutoSubstituteBuilder builder) => ...
}
public class Test
{
[Fact]
public void SomeTest()
{
using var mock = AutoSubstitute.Configure()
.AddCustomExtensions()
...
.Build();
}
This works, but requires every test to manually call this. I propose an API that can be called early on (potentially via C# 9 module initializers) that then gets applied to all tests. It would also be good to provide a way to 'lock' the default set so nothing else inadvertently changes things.
Here's the proposal for the API:
public class AutoSubstitute
{
public static DefaultAutoSubstituteBuilder Default { get; }
}
public class DefaultAutoSubstituteBuilder
{
public DefaultAutoSubstituteBuilder ConfigureDefault(Action<AutoSubstituteBuilder> configure);
public void Reset();
public DefaultAutoSubstituteBuilder Lock();
}
Some open questions:
There are now a number of options that can be set (and infinite combinations with custom MockHandlers). Some of these I find I need to use in the same way for an entire test suite. Currently, I'm using a custom extension method, but the drawback is it has to be called on every builder, ie:
This works, but requires every test to manually call this. I propose an API that can be called early on (potentially via C# 9 module initializers) that then gets applied to all tests. It would also be good to provide a way to 'lock' the default set so nothing else inadvertently changes things.
Here's the proposal for the API:
Some open questions: