Beispiel #1
0
        public void ContinueCheckingStrategiesAfterBeingHandled()
        {
            var counter = 0;
            var context = new ErrorHandlingContext(this, ErrorSeverityLevel.NonFatal, new Exception());

            var strategy1 = new Mock <IErrorHandlingStrategy>();

            strategy1.Setup(o => o.Handle(context)).Callback(() =>
            {
                context.MarkErrorAsHandled();
                counter++;
            });

            var strategy2 = new Mock <IErrorHandlingStrategy>();

            strategy2.Setup(o => o.Handle(context)).Callback(() =>
            {
                counter++;
            });

            var target = new CompositeErrorHandlingStrategy();

            target.AddStrategy(strategy1.Object);
            target.AddStrategy(strategy2.Object);

            target.Handle(context);

            Assert.AreEqual(2, counter);
        }
Beispiel #2
0
        public void ExecutesAllStrategiesInTheOriginalOrder()
        {
            var counter = 0;
            var context = new ErrorHandlingContext(this, ErrorSeverityLevel.NonFatal, new Exception());

            var strategy1 = new Mock <IErrorHandlingStrategy>();

            strategy1.Setup(o => o.Handle(context)).Callback(() =>
            {
                Assert.AreEqual(0, counter);
                counter++;
            });

            var strategy2 = new Mock <IErrorHandlingStrategy>();

            strategy2.Setup(o => o.Handle(context)).Callback(() =>
            {
                Assert.AreEqual(1, counter);
                counter++;
            });

            var target = new CompositeErrorHandlingStrategy();

            target.AddStrategy(strategy1.Object);
            target.AddStrategy(strategy2.Object);

            target.Handle(context);

            Assert.AreEqual(2, counter);
        }
Beispiel #3
0
        public void ShouldNotRethrowTheExceptionOnceHandledTest()
        {
            var target = new ErrorHandlingContext(this, ErrorSeverityLevel.NonFatal, new Exception());

            target.MarkErrorAsHandled();
            Assert.DoesNotThrow(() => target.RethrowErrorIfNotHandled());
        }
Beispiel #4
0
        /// <inheritdoc />
        public void Handle(ErrorHandlingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            foreach (var strategy in strategies)
            {
                strategy.Handle(context);
            }
        }
        /// <inheritdoc />
        public void Handle(Exception error, ErrorSeverityLevel severity)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            var errorContext = new ErrorHandlingContext(this, severity, error);

            errorHandlingStrategy.Handle(errorContext);

            errorContext.RethrowErrorIfNotHandled();
        }
Beispiel #6
0
        public void ShouldRethrowTheExceptionTest()
        {
            var target = new ErrorHandlingContext(this, ErrorSeverityLevel.NonFatal, new Exception());

            Assert.Throws <Exception>(() => target.RethrowErrorIfNotHandled());
        }