예제 #1
0
        public void TryAction_Test()
        {
            var isCalled        = false;
            var exceptionRaised = false;

            With.TryAction(() => {
                isCalled = true;
                throw new InvalidOperationException("Test");
            },
                           ex => {
                if (ex is InvalidOperationException)
                {
                    exceptionRaised = true;
                }
            },
                           () => {
                isCalled.Should().Be.True();
                exceptionRaised.Should().Be.True();
            });
        }
예제 #2
0
        public void TryActionAsync_Test()
        {
            var isCalled        = false;
            var exceptionRaised = false;

            With.TryActionAsync(() => {
                Task.Factory.StartNew(() => { isCalled = true; }).Wait();
                throw new AggregateException("AggEx", new InvalidOperationException("Test"));
            },
                                age => age.Handle(ex => {
                if (ex is InvalidOperationException)
                {
                    exceptionRaised = true;
                }

                return(true);
            }),
                                () => {
                Assert.IsTrue(isCalled);
                Assert.IsTrue(exceptionRaised);
            });
        }