using System; using System.Collections.Generic; using Chernobyl.Collections.Generic.Event; using NUnit.Framework; namespace Chernobyl.Values { [TestFixture, Description("Tests for the First type.")] public class FirstTests : ValueTests, int> { //------------------------------------------------------------------ // First(IEventEnumerable) Tests. //------------------------------------------------------------------ [Test, Description("Ensures First(IEventEnumerable) throws an " + "ArgumentNullException when the argument is null.")] public void ConstructorIEventEnumerableArgumentNullException() { Assert.Throws(() => CreateFirst(null)); } //------------------------------------------------------------------ // First(IEventEnumerable, IComparer) Tests. //------------------------------------------------------------------ [Test, Description("Ensures First(IEventEnumerable, IComparer) " + "throws an ArgumentNullException when the first argument is null.")] public void ConstructorIEventEnumerableIComparerFirstArgumentNullException() { Assert.Throws(() => CreateFirst(null, EqualityComparer.Default)); } [Test, Description("Ensures First(IEventEnumerable, IComparer) " + "throws an ArgumentNullException when the first argument is null.")] public void ConstructorIEventEnumerableIComparerSecondArgumentNullException() { var list = new DecoratingEventList(); Assert.Throws(() => CreateFirst(list, null)); } //---------------------------------------------------------------------- // Ready Tests //---------------------------------------------------------------------- [Test, Description("Ensures IValue.Provide is raised when the " + "IValue{T} is made ready.")] [Ignore("First 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("First 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 does not raise the " + "IValue.Provide event. Override this test if it is not applicable.")] [Ignore("Fake value changes are not possible with this type.")] public override void ProvideNotRaisedWhenValueIsNotChanged() {} [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("Fake value changes are not possible with this type.")] public override void ProvideRaisedWhenValueIsNotChangedButIsMadeReady() {} //------------------------------------------------------------------ // Utility Methods //------------------------------------------------------------------ /// /// Creates an instance to test. This method will /// always return a new instance and never return old instances. /// /// The that /// is to be watched for changes to its first item. /// The instance to test. protected virtual First CreateFirst(IEventEnumerable enumerable) { return new First(enumerable); } /// /// Creates an instance to test. This method will /// always return a new instance and never return old instances. /// /// The that /// is to be watched for changes to its first item. /// The instance that is used to check if the /// instance's latest first is equal to it's /// previous first and therefore results in a change. /// The instance to test. protected virtual First CreateFirst(IEventEnumerable enumerable, IEqualityComparer comparer) { return new First(enumerable, comparer); } protected override ValueTests, int>.Wrapper CreateValue() { return new Wrapper(); } protected new class Wrapper : ValueTests, int>.Wrapper { public Wrapper() : base(null, 1, 0) { _list = new DecoratingEventList(); _list.Add(ReadyValue); TestInstance = new First(_list); } public override void MakeReady() { // Not needed. First doesn't become ready. } public override void ChangeValue() { _list.Remove(ReadyValue); } public override void FakeChangeValue() { // Mock value changes are not possible with this type. throw new NotImplementedException(); } DecoratingEventList _list; } } }