示例#1
0
        public void Naiv() {
            var sut = new LongRunning();
            string result = null;
            sut.Result += x => result = x;

            sut.GetResultAsync();

            Assert.That(result, Is.EqualTo("Hello"));
        }
示例#2
0
        public void Schon_besser() {
            var sut = new LongRunning();
            var autoResetEvent = new AutoResetEvent(false);

            string result = null;
            sut.Result += x => {
                result = x;
                autoResetEvent.Set();
            };

            sut.GetResultAsync();

            Assert.That(autoResetEvent.WaitOne(5000), Is.True);
            Assert.That(result, Is.EqualTo("Hello"));
        }
示例#3
0
        public void Aspekte_sind_zu_trennen() {
            var asyncer = new Asynchronizer<string>();
            var sut = new LongRunning();
            var autoResetEvent = new AutoResetEvent(false);

            string result = null;
            asyncer.Result += x => {
                result = x;
                autoResetEvent.Set();
            };

            asyncer.Process(sut.GetResult);

            Assert.That(autoResetEvent.WaitOne(5000), Is.True);
            Assert.That(result, Is.EqualTo("Hello"));
        }