using System; using System.Collections.Generic; using NUnit.Framework; namespace Chernobyl.Values { // ReSharper disable ObjectCreationAsStatement [TestFixture, Description("Tests for the Select type.")] public class SelectTests : ValueTests, string> { //---------------------------------------------------------------------- // Select(IValue, Func) Tests //---------------------------------------------------------------------- [Test, Description("Ensures Select(IValue, Func) " + "throws an ArgumentNullException when its first argument " + "is null.")] public void ConstructorValueFuncFirstArgumentNullException() { Assert.Throws(() => new Select(null, i => i.ToString())); } [Test, Description("Ensures Select(IValue, Func) " + "throws an ArgumentNullException when its second argument " + "is null.")] public void ConstructorValueFuncSecondArgumentNullException() { Assert.Throws(() => new Select(new DynamicContainer(0), null)); } //---------------------------------------------------------------------- // Select(IValue, Func, IEqualityComparer) Tests //---------------------------------------------------------------------- [Test, Description("Ensures Select(IValue, Func, IEqualityComparer) " + "throws an ArgumentNullException when its first argument " + "is null.")] public void ConstructorValueFuncIEqualityComparerFirstArgumentNullException() { Assert.Throws(() => new Select(null, i => i.ToString(), EqualityComparer.Default)); } [Test, Description("Ensures Select(IValue, Func, IEqualityComparer) " + "throws an ArgumentNullException when its second argument " + "is null.")] public void ConstructorValueFuncIEqualityComparerSecondArgumentNullException() { Assert.Throws(() => new Select(new DynamicContainer(0), null, EqualityComparer.Default)); } [Test, Description("Ensures Select(IValue, Func, IEqualityComparer) " + "throws an ArgumentNullException when its third argument " + "is null.")] public void ConstructorValueFuncIEqualityComparerThirdArgumentNullException() { Assert.Throws(() => new Select(new DynamicContainer(0), i => i.ToString(), null)); } //---------------------------------------------------------------------- // Utility //---------------------------------------------------------------------- protected override ValueTests, string>.Wrapper CreateValue() { return new Wrapper(); } protected new class Wrapper : ValueTests, string>.Wrapper { public Wrapper() : base(null, "0", "5") { _container.IsReady = false; TestInstance = new Select(_container, i => i.ToString()); } public override void MakeReady() { // Not needed. Select doesn't become ready. _container.IsReady = true; } public override void ChangeValue() { _container.Value = 5; } public override void FakeChangeValue() { _container.Value = _container.Value; } readonly DynamicContainer _container = new DynamicContainer(0); /// /// Type to help with testing. /// public class DynamicContainer : DynamicContainer { public DynamicContainer(int value) : base(value) { IsReady = false; } public new bool IsReady { get { return base.IsReady; } set { base.IsReady = value; } } } } } // ReSharper restore ObjectCreationAsStatement }