Exemplo n.º 1
0
        public void GivenAnExceptionWithNoMetadata_LogMessage__LogsTheException(TheoryLoggerEventType eventType,
                                                                                string formattedMessageTab)
        {
            // Arrange.
            SetupLogManager(formattedMessageTab);
            var          logger       = LogManager.GetLogger("test");
            const string errorMessage = "Something sad happened.";
            var          exception    = new Exception(errorMessage);

            const string formattedErrorMessage = "pew pew";
            string       error;

            // Act.
            using (var testServer = new TestServer())
            {
                LogMessage(eventType, logger)(exception, formattedErrorMessage);
                error = testServer.GetLastResponse();
            }

            // Assert.
            var anotherTabName = string.IsNullOrWhiteSpace(formattedMessageTab)
                ? "Custom Data"
                : formattedMessageTab;

            var result = JObject.Parse(error);

            result["events"][0]["exceptions"][0]["message"].ToString().ShouldBe(errorMessage);
            result["events"][0]["exceptions"][0]["stacktrace"].HasValues.ShouldBe(true);
            result["events"][0]["metaData"].Count().ShouldBe(2);
            result["events"][0]["metaData"][anotherTabName][BugsnagTarget.FormattedMessageKey].ShouldBe(formattedErrorMessage);
            result["events"][0]["severity"].ToString().ShouldBe(MapTheoryLoggerEventTypeToSeverity(eventType));
        }
Exemplo n.º 2
0
        public void GivenAMessage_LogMessage_LogsTheErrorMessage(TheoryLoggerEventType eventType)
        {
            // Arrange.
            SetupLogManager(null);
            var          logger       = LogManager.GetLogger("test");
            const string errorMessage = "Something sad happened.";

            string error;

            // Act.
            using (var testServer = new TestServer())
            {
                LogMessageWithNoException(eventType, logger)(errorMessage);
                error = testServer.GetLastResponse();
            }

            // Assert.
            var result = JObject.Parse(error);

            result["events"][0]["exceptions"][0]["errorClass"].ToString().ShouldBe("BugsnagException");
            result["events"][0]["exceptions"][0]["message"].ToString().ShouldBe(errorMessage);
            result["events"][0]["exceptions"][0]["stacktrace"].HasValues.ShouldBe(true);
            result["events"][0]["metaData"].Count().ShouldBe(1);
            result["events"][0]["metaData"]["Exception Details"]["runtimeEnding"].ToString().ShouldBe("False");
        }