public void Adding_argument_when_invoker_is_completed_has_no_effect()
 {
     var function = new Func<string, string, string>((x, y) => x + y);
     var sut = new Basic.Appendable(function, "a", "b");
     var e = sut.GetConsumingEnumerable().GetEnumerator();
     IsTrue(e.MoveNext());
     AreEqual("aa", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("ab", e.Current.Function.DynamicInvoke());
     sut.Add("c");
     sut.Complete();
     sut.Add("d");
     sut.Add("e");
     IsTrue(e.MoveNext());
     AreEqual("ba", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("bb", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("ca", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("cb", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("ac", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("bc", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("cc", e.Current.Function.DynamicInvoke());
     IsFalse(e.MoveNext());
 }
        public void Works_when_adding_argument_from_other_thread_during_consuming_iteration()
        {
            var function = new Func<string, string, string>((x, y) => x + y);
            var sut = new Basic.Appendable(function, "a", "b");
            var wh = new ManualResetEventSlim();
            var e = sut.GetConsumingEnumerable().GetEnumerator();

            IsTrue(e.MoveNext());
            AreEqual("aa", e.Current.Function.DynamicInvoke());
            IsTrue(e.MoveNext());
            AreEqual("ab", e.Current.Function.DynamicInvoke());

            Task.Run(() =>
            {
                sut.Add("c");
                sut.Complete();
                wh.Set();
            });

            if (!wh.Wait(500))
                throw new TimeoutException();

            IsTrue(e.MoveNext());
            AreEqual("ba", e.Current.Function.DynamicInvoke());
            IsTrue(e.MoveNext());
            AreEqual("bb", e.Current.Function.DynamicInvoke());
            IsTrue(e.MoveNext());
            AreEqual("ca", e.Current.Function.DynamicInvoke());
            IsTrue(e.MoveNext());
            AreEqual("cb", e.Current.Function.DynamicInvoke());
            IsTrue(e.MoveNext());
            AreEqual("ac", e.Current.Function.DynamicInvoke());
            IsTrue(e.MoveNext());
            AreEqual("bc", e.Current.Function.DynamicInvoke());
            IsTrue(e.MoveNext());
            AreEqual("cc", e.Current.Function.DynamicInvoke());
            IsFalse(e.MoveNext());
        }
 public void Works_when_adding_two_arguments_during_consuming_iteration()
 {
     var function = new Func<string, string, string>((x, y) => x + y);
     var sut = new Basic.Appendable(function, "a", "b");
     var e = sut.GetConsumingEnumerable().GetEnumerator();
     IsTrue(e.MoveNext());
     AreEqual("aa", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("ab", e.Current.Function.DynamicInvoke());
     sut.Add("c");
     sut.Add("d");
     sut.Complete();
     IsTrue(e.MoveNext());
     AreEqual("ba", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("bb", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("ca", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("cb", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("ac", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("bc", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("cc", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("da", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("db", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("dc", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("ad", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("bd", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("cd", e.Current.Function.DynamicInvoke());
     IsTrue(e.MoveNext());
     AreEqual("dd", e.Current.Function.DynamicInvoke());
     IsFalse(e.MoveNext());
 }