using Chernobyl;
using NUnit.Framework;
namespace System.Utility
{
///
/// A type used to test the invoking of methods or raising of events.
///
public class InvokeTester
{
///
/// Initializes a new instance of the class.
///
/// The message that is printed when a test
/// fails.
public InvokeTester(string failureMessage)
: this(false, failureMessage)
{}
///
/// Initializes a new instance of the class.
///
/// True if the test should fail when
/// is invoked, false if
/// otherwise. This property is false by default.
/// The message that is printed when a test
/// fails.
public InvokeTester(bool pass, string failureMessage)
{
Pass = pass;
FailureMessage = failureMessage;
}
///
/// An event handler that, when invoked, either fails or passes the test
/// based on the value of .
///
/// The sender of the event.
/// The instance containing the
/// event data.
public void EventHandler(object sender, EventArgs e)
{
if (Pass)
Assert.Pass();
else
Assert.Fail(FailureMessage);
}
///
/// True if the test should fail when
/// is invoked, false if otherwise. This property is false by default.
///
public bool Pass { get; set; }
///
/// The message that is printed when a test fails.
///
public string FailureMessage
{
get => _failureMessage;
set => _failureMessage = value.ThrowIfNull(nameof(value)).Value;
}
///
/// The backing field to .
///
string _failureMessage;
}
}