davezych / shience

A .NET port(ish) of Github's Scientist library. (https://github.com/github/scientist)
MIT License
9 stars 1 forks source link

.Test() should throw when called multiple times #20

Closed MovGP0 closed 8 years ago

MovGP0 commented 8 years ago

When .Test() is called multiple times, it overrides the Control and Candidate actions.

In such cases the user should create a new Science using the factory method Shience.New instead. Therefore, I'd prefer to have to throw an InvalidOperationException() when .Test() is called multiple times.

MovGP0 commented 8 years ago

example code:

public static Science<TResult> Test<TResult>(this Science<TResult> science, Func<TResult> control, Func<TResult> candidate)
{
    if(control == null) throw new ArgumentNullException(nameof(control));
    if(candidate == null) throw new ArgumentNullException(nameof(candidate));

    if(science.Control != null || science.Candidate != null) 
    {
        // message from translatable resource file
        var message = ErrorMessages.TestMayNotBeCalledMultipleTimes; 
        throw new InvalidOperationException(message);
    }

    science.Control = control;
    science.Candidate = candidate;

    return science;
}