Exemplo n.º 1
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));
        }