Exemplo n.º 1
0
        public void NotifyAsync()
        {
            Should.Throw <ArgumentNullException>(() => new ExceptionNotifier(null));
            var factory    = Substitute.For <IHybridServiceScopeFactory>();
            var scope      = Substitute.For <IServiceScope>();
            var subscriber = Substitute.For <IExceptionSubscriber>();

            subscriber.Configure().HandleAsync(Arg.Any <ExceptionNotificationContext>()).Returns(Task.CompletedTask).AndDoes(c =>
            {
                var context = c.Arg <ExceptionNotificationContext>();
                context.ShouldNotBeNull();
                context.Exception.ShouldBeOfType <ScorpioException>();
                context.LogLevel.ShouldBe(LogLevel.Error);
                context.Handled.ShouldBeTrue();
            });
            var provider = Substitute.For <IServiceProvider>();

            scope.Configure().ServiceProvider.Returns(provider);
            provider.Configure().GetService(typeof(IEnumerable <IExceptionSubscriber>)).Returns(new List <IExceptionSubscriber> {
                subscriber
            });
            factory.Configure().CreateScope().Returns(scope);
            var notifier = Should.NotThrow(() => new ExceptionNotifier(factory));
            var ex       = new ScorpioException();

            Should.NotThrow(() => notifier.NotifyAsync(ex));
            subscriber.ReceivedWithAnyArgs(1).HandleAsync(Arg.Any <ExceptionNotificationContext>());
        }
Exemplo n.º 2
0
        public void TestMessageNoTextAndException()
        {
            // arrange

            // act
            var exception = new ScorpioException(null, null);

            // assert
            Assert.That(exception.Message, Contains.Substring("SCORPIO"));
            Assert.That(exception.InnerException, Is.Null);
        }
Exemplo n.º 3
0
        public void TestMessageInnerException()
        {
            // arrange
            var innerException = new Exception();

            // act
            var exception = new ScorpioException(null, innerException);

            // assert
            Assert.That(exception.Message, Contains.Substring("SCORPIO"));
            Assert.That(exception.InnerException, Is.EqualTo(innerException));
        }
Exemplo n.º 4
0
        public void TestMessageText()
        {
            // arrange
            var text = "Hallo";

            // act
            var exception = new ScorpioException(text, null);

            // assert
            Assert.That(exception.InnerException, Is.Null);
            Assert.That(exception.Message, Is.EqualTo(text));
        }
Exemplo n.º 5
0
        public void TestMessageTextAndException()
        {
            // arrange
            var text           = "Hallo";
            var innerException = new Exception();

            // act
            var exception = new ScorpioException(text, innerException);

            exception.IdentifierNumber = 5;

            // assert
            Assert.That(exception.InnerException, Is.EqualTo(innerException));
            Assert.That(exception.Message, Is.EqualTo(text));
            Assert.That(exception.IdentifierNumber, Is.EqualTo(5));
        }