コード例 #1
0
        public void LogSendsAggregateExceptionWithInnerExceptionToSentryTest()
        {
            var name     = Guid.NewGuid().ToString();
            var sentryId = Guid.NewGuid().ToString();
            var eventId  = new EventId(Environment.TickCount);
            var state    = new AddressState
            {
                Address = Guid.NewGuid().ToString()
            };
            var first     = Model.Ignoring <ValueTypeException>(x => x.Data).Create <ValueTypeException>();
            var second    = Model.Ignoring <ValueTypeException>(x => x.Data).Create <ValueTypeException>();
            var exception = new AggregateException(Guid.NewGuid().ToString(), first, second);

            exception.AddContextData(state.Address);

            var client = Substitute.For <IRavenClient>();

            client.Capture(Arg.Any <SentryEvent>()).Returns(sentryId);

            var sut = new SentryLogger(name, client);

            sut.Log(LogLevel.Critical, eventId, state, exception, (logState, ex) => ex.ToString());

            client.Received().Capture(
                Arg.Is <SentryEvent>(x => x.Exception.Data["ValueTypeException.Id"].As <string>() == first.Id));
        }
コード例 #2
0
        public void LogSendsAggregateExceptionDetailsToSentryTest()
        {
            var name     = Guid.NewGuid().ToString();
            var sentryId = Guid.NewGuid().ToString();
            var eventId  = new EventId(Environment.TickCount);
            var state    = new AddressState
            {
                Address = Guid.NewGuid().ToString()
            };
            var exception = new AggregateException(Guid.NewGuid().ToString());

            exception.AddContextData(state.Address);

            var client = Substitute.For <IRavenClient>();

            client.Capture(Arg.Any <SentryEvent>()).Returns(sentryId);

            var sut = new SentryLogger(name, client);

            sut.Log(LogLevel.Critical, eventId, state, exception, (logState, ex) => ex.ToString());

            client.Received(1).Capture(Arg.Any <SentryEvent>());
            client.Received().Capture(Arg.Is <SentryEvent>(x => x.Level == ErrorLevel.Fatal));
            client.Received().Capture(Arg.Is <SentryEvent>(x => x.Exception == exception));
            client.Received().Capture(Arg.Is <SentryEvent>(x => x.Message == exception.Message));
            client.Logger.Should().Be(name);
            client.Received().Capture(
                Arg.Is <SentryEvent>(x => x.Exception.Data["ContextData"].As <string>() == state.Address));
            client.Received().Capture(
                Arg.Is <SentryEvent>(x =>
                                     x.Exception.Data["CleanedException"].As <string>() == exception.Demystify().ToString()));
            client.Received().Capture(
                Arg.Is <SentryEvent>(x => x.Exception.Data["StorageException.RequestInformation"] == null));
        }
コード例 #3
0
        public void LogSendsTypeReflectionLoadExceptionWithAdditionalContentTest()
        {
            var name     = Guid.NewGuid().ToString();
            var sentryId = Guid.NewGuid().ToString();
            var eventId  = new EventId(Environment.TickCount);
            var state    = new AddressState
            {
                Address = Guid.NewGuid().ToString("N")
            };
            var first          = Model.Ignoring <ValueTypeException>(x => x.Data).Create <ValueTypeException>();
            var second         = Model.Ignoring <WithNestedClassException>(x => x.Data).Create <WithNestedClassException>();
            var innerException = new ReflectionTypeLoadException(
                new[]
            {
                typeof(string),
                typeof(int)
            },
                new Exception[]
            {
                first,
                second
            });
            var exception = new AggregateException(Guid.NewGuid().ToString(), innerException);

            exception.AddContextData(state.Address);

            var client = Substitute.For <IRavenClient>();

            client.Capture(Arg.Any <SentryEvent>()).Returns(sentryId);

            var sut = new SentryLogger(name, client);

            sut.Log(LogLevel.Critical, eventId, state, exception, (logState, ex) => ex.ToString());

            client.Received().Capture(
                Arg.Is <SentryEvent>(
                    x => x.Exception.Data["ReflectionTypeLoadException.Types"].As <string>()
                    .Contains(innerException.Types[0].AssemblyQualifiedName)));
            client.Received().Capture(
                Arg.Is <SentryEvent>(
                    x => x.Exception.Data["ReflectionTypeLoadException.Types"].As <string>()
                    .Contains(innerException.Types[1].AssemblyQualifiedName)));
            client.Received().Capture(
                Arg.Is <SentryEvent>(
                    x => x.Exception.Data["ReflectionTypeLoadException.LoaderExceptions"].As <string>()
                    .Contains(innerException.LoaderExceptions[0].GetType().Name)));
            client.Received().Capture(
                Arg.Is <SentryEvent>(
                    x => x.Exception.Data["ReflectionTypeLoadException.LoaderExceptions"].As <string>()
                    .Contains(innerException.LoaderExceptions[1].GetType().Name)));
        }