using System; using System.Collections.Generic; using System.Reflection; using Chernobyl.Collections.Generic.Event; using Chernobyl.Values; using NUnit.Framework; namespace Chernobyl.Reflection { /// /// Tests for the type. /// public class ReturnValueTests : ValueTests, string> { //---------------------------------------------------------------------- // 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("Test not required since ReturnValue is only made ready when " + "all IValue instance's it holds are made ready.")] public override void ProvideRaisedWhenValueIsNotChangedButIsMadeReady() { } //---------------------------------------------------------------------- // Utility //---------------------------------------------------------------------- protected virtual ReturnValue CreateReturnValue( IValue instance, MethodBase method, IEventEnumerable> parameters) { return new ReturnValue(instance, method, parameters); } protected override Wrapper CreateValue() { var parameters = new[] { new DynamicContainer(Strings[0]), new DynamicContainer(null) }; MethodInfo concatMethod = GetType().GetMethod("Concat", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly); return new ReturnValueWrapper( CreateReturnValue(new BasicContainer(this), concatMethod, new DecoratingEventList>(new[] { parameters[0], parameters[1].NotNull() })), parameters, Strings[0] + Strings[1], Strings[0] + Strings[2]); } /// /// Strings used for testing purposes. /// internal static readonly string[] Strings = { "hello", " Bob", " John" }; protected static string Concat(string first, string second) { return first + second; } class ReturnValueWrapper : Wrapper { public ReturnValueWrapper(ReturnValue testInstance, IDynamicContainer[] parameters, string readyValue, string finalValue) : base(testInstance, readyValue, finalValue) { _parameters = parameters; } public override void MakeReady() { _parameters[1].Value = Strings[1]; } public override void ChangeValue() { _parameters[1].Value = Strings[2]; } public override void FakeChangeValue() { _parameters[0].Value = Strings[0]; } IDynamicContainer[] _parameters; } } }