using System; using System.Collections.Generic; using NUnit.Framework; namespace Chernobyl.Values { [TestFixture, Description("A set of tests for the DynamicContainer type.")] public class DynamicContainerImplementationTests : ValueTests, int> { //----------------------------------------------------------------- // Constructor Tests //----------------------------------------------------------------- [Test, Description("A test to ensure that the values passed to " + "DynamicContainer(T, IComparer) are the correct values on the " + "properties themselves after construction.")] public void ConstructorValueComparerIsCorrect() { IEqualityComparer comparer = new Comparer(); DynamicContainer container = new DynamicContainer(3, comparer); Assert.AreEqual(3, container.Value, "DynamicContainer.Value is not the expected container."); Assert.AreEqual(comparer, container.Comparer, "DynamicContainer.Comparer is not the expected container."); } [Test, Description("A test to ensure that the value passed to " + "DynamicContainer(T) is the correct value on the property itself.")] public void ConstructorValue() { DynamicContainer container = new DynamicContainer(3); Assert.AreEqual(3, container.Value, "DynamicContainer.Value is not the expected container."); } //----------------------------------------------------------------- // DynamicContainer.Comparer Tests //----------------------------------------------------------------- [Test, Description("A test to ensure that DynamicContainer.Comparer throws " + "an ArgumentNullException when it is set to a null value")] public void ComparerArgumentNullException() { DynamicContainer container = new DynamicContainer(3); Assert.Throws(() => container.Comparer = null); } //---------------------------------------------------------------------- // Ready Tests //---------------------------------------------------------------------- [Test, Description("Ensures IValue.Provide is raised when the " + "IValue{T} is made ready.")] [Ignore("DynamicContainer doesn't become ready.")] public override void ProvideRaisedWhenMadeReady() {} [Test, Description("Ensures that event handlers that are added to " + "IValue.Provide are invoked when added to a ready" + "IValue.")] [Ignore("DynamicContainer doesn't become ready.")] public override void EventHandlersAddedToReadyValueAreInvokedWhenAdded() {} //---------------------------------------------------------------------- // Change Tests //---------------------------------------------------------------------- [Test, Description("A test to ensure that setting the internal value of " + "IValue to the value it is already set at raises the " + "IValue.Provide event if the IValue is not ready. " + "Override this test if it is not applicable.")] [Ignore("DynamicContainer doesn't become ready.")] public override void ProvideRaisedWhenValueIsNotChangedButIsMadeReady() {} //------------------------------------------------------------------ // Utility //------------------------------------------------------------------ /// /// A helper used for testing. /// public class Comparer : IEqualityComparer { public bool Equals(int x, int y) { return x.Equals(y); } public int GetHashCode(int obj) { return obj.GetHashCode(); } } protected override ValueTests, int>.Wrapper CreateValue() { return new Wrapper(); } protected new class Wrapper : ValueTests, int>.Wrapper { public Wrapper() : base(new DynamicContainer(3), 3, 4) {} public override void MakeReady() { // Not needed. DynamicContainer doesn't become ready. } public override void ChangeValue() { TestInstance.Value = FinalValue; } public override void FakeChangeValue() { TestInstance.Value = ReadyValue; } } } }