using NUnit.Framework;
namespace Chernobyl
{
///
/// A class that is used to test the API of types
/// implementing the interface.
///
public abstract class NamedTests
{
[Test, Description("Tests that the name can be set with a specified name " +
"and then that name is the same after it has been queried.")]
public void SettingAndQueryingName()
{
const string testName = "Test Name";
INamed named = CreateNamed();
named.Name = testName;
Assert.AreEqual(testName, named.Name, "The name \"" + testName + "\" " +
"was set on the INamed instance using the INamed.Name property " +
"but a query of that instances shows that that the actual name " +
"is \"" + named.Name + "\".");
}
[Test, Description("Tests to see if the INamed instance is given the " +
"expected name as defined by the property ExpectedName. Note that " +
"the test is ignored if the ExpectedName property returns an empty " +
"string, which it does by default.")]
public void NameIsExpected()
{
if(ExpectedName.Length == 0)
Assert.Ignore("NamedTests.ExpectedName property is an empty " +
"string so this test is ignored. ");
INamed named = CreateNamed();
Assert.AreEqual(ExpectedName, named.Name, "The expected name \"" +
ExpectedName + "\" " + "was not the value of the INamed.Name " +
"property. The actual name was \"" + named.Name + "\".");
}
///
/// Should create the instance that is being tested.
/// This method should always create a new instance and never reuse that
/// instance.
///
/// The new instance to be tested.
protected abstract INamed CreateNamed();
///
/// The name that is expected by the test
/// method. If the value returned is an empty string, then the test is
/// ignored.
///
protected virtual string ExpectedName
{
get { return string.Empty; }
}
}
}