Exemple #1
0
        public void TestThatCompletesRepeatsAfterFailure()
        {
            var andThenValue = -1;

            var completes = new RepeatableCompletes <int>(0);

            completes
            .AndThen(value =>
            {
                if (value < 10)
                {
                    throw new InvalidOperationException();
                }
                return(value);
            })
            .AndThen(val => val * 2)
            .AndThen(val => andThenValue = val)
            .Repeat();

            completes.With(5);
            completes.Await();
            Assert.True(completes.HasFailed);

            completes.With(10);
            var outcome20 = completes.Await();

            Assert.Equal(20, outcome20);
            Assert.Equal(20, andThenValue);
        }
Exemple #2
0
        public void TestThatCompletesRepeatsAfterTimeout()
        {
            var andThenValue = -1;

            var completes = new RepeatableCompletes <int>(0);

            completes
            .AndThen(1, val => val * 2)
            .AndThen(val => andThenValue = val)
            .Repeat();

            var thread = new Thread(() =>
            {
                Thread.Sleep(10000);
                completes.With(5);
            });

            thread.Start();

            completes.Await(TimeSpan.FromMilliseconds(10));
            Assert.True(completes.HasFailed);

            completes.With(10);
            var outcome20 = completes.Await();

            Assert.Equal(20, outcome20);
            Assert.Equal(20, andThenValue);
        }
Exemple #3
0
        public void TestThatCompletesRepeats()
        {
            var andThenValue = -1;

            var completes = new RepeatableCompletes <int>(0);

            completes
            .AndThen(val => val * 2)
            .AndThen(val => andThenValue = val)
            .Repeat();

            completes.With(5);
            Assert.Equal(10, andThenValue);

            completes.With(10);
            Assert.Equal(20, andThenValue);

            completes.With(21);
            Assert.Equal(42, andThenValue);
        }
Exemple #4
0
        public void TestThatCompletesRepeatsForClient()
        {
            var andThenValue = -1;
            var service      = new RepeatableCompletes <int>(0);

            var client = service
                         .AndThen(value => value * 2)
                         .AndThen((value) => andThenValue = value)
                         .Repeat();

            service.With(5);
            var outcome10 = client.Await();

            Assert.Equal(10, outcome10);
            Assert.Equal(10, andThenValue);

            service.With(10);
            var outcome20 = client.Await();

            Assert.Equal(20, outcome20);
            Assert.Equal(20, andThenValue);
        }