public void CheckBasicPropertiesOfNotifications(Exception exp)
        {
            // Arrange
            var client = new BaseClient(StaticData.TestApiKey);

            // Act
            JObject json;
            using (var server = new TestServer(client))
            {
                client.Notify(exp);
                json = server.GetLastResponse();
            }

            // Assert
            Assert.Equal(StaticData.TestApiKey, json["apiKey"]);
            Assert.Equal(Notifier.Name, json["notifier"]["name"]);
            Assert.Equal(Notifier.Version, json["notifier"]["version"]);
            Assert.Equal(Notifier.Url.AbsoluteUri, json["notifier"]["url"]);
        }
        public void CheckInnerExceptionsAreNotified()
        {
            // Arrange
            var client = new BaseClient(StaticData.TestApiKey);

            // Act
            JObject json;
            using (var server = new TestServer(client))
            {
                client.Notify(StaticData.TestInnerException);
                json = server.GetLastResponse();
            }

            // Assert
            Assert.Equal(StaticData.TestApiKey, json["apiKey"]);
            Assert.Equal(3, json["events"][0]["exceptions"].Count());
            Assert.Equal("ArithmeticException", json["events"][0]["exceptions"][0]["errorClass"]);
            Assert.Equal("DivideByZeroException", json["events"][0]["exceptions"][1]["errorClass"]);
            Assert.Equal("TypeAccessException", json["events"][0]["exceptions"][2]["errorClass"]);
        }
        public void CheckInnerExceptionsForBasicAggregateException()
        {
            // Arrange
            var client = new BaseClient(StaticData.TestApiKey);
            AggregateException testAggregateException = null;
            var task1 = Task.Factory.StartNew(() => { throw new FieldAccessException("Task 1 Exception"); });
            var task2 = Task.Factory.StartNew(() => { throw new StackOverflowException("Task 2 Exception"); });
            var task3 = Task.Factory.StartNew(() => { throw new AccessViolationException("Task 3 Exception"); });
            try
            {
                Task.WaitAll(task1, task2, task3);
            }
            catch (AggregateException ae)
            {
                testAggregateException = ae;
            }

            // Act
            JObject json;
            using (var server = new TestServer(client))
            {
                client.Notify(testAggregateException);
                json = server.GetLastResponse();
            }

            // Assert
            Assert.Equal(StaticData.TestApiKey, json["apiKey"]);
            Assert.Equal(1, json["events"].Count());

            // Check that 3 events are created, each having the Aggregate exception as the root exception
            var task1Exps = json["events"][0]["exceptions"].First(x => x["errorClass"].Value<string>() == "FieldAccessException");
            var task2Exps = json["events"][0]["exceptions"].First(x => x["errorClass"].Value<string>() == "StackOverflowException");
            var task3Exps = json["events"][0]["exceptions"].First(x => x["errorClass"].Value<string>() == "AccessViolationException");

            Assert.Equal("AggregateException", json["events"][0]["exceptions"][0]["errorClass"]);

            Assert.Equal("Task 1 Exception", task1Exps["message"]);
            Assert.Equal("Task 2 Exception", task2Exps["message"]);
            Assert.Equal("Task 3 Exception", task3Exps["message"]);
        }
        public void AddSimpleMetadataToANotifications()
        {
            // Arrange
            var client = new BaseClient(StaticData.TestApiKey);
            var testMetadata = new Metadata();
            testMetadata.AddToTab("Test Tab 1", "Key 1", "Value 1");
            testMetadata.AddToTab("Test Tab 1", "Key 2", "Value 2");
            testMetadata.AddToTab("Test Tab 2", "Key 1", "Value 1");

            // Act
            JObject json;
            using (var server = new TestServer(client))
            {
                client.Notify(StaticData.TestThrowException, testMetadata);
                json = server.GetLastResponse();
            }

            // Assert
            var actData = json["events"][0]["metaData"];
            Assert.Equal("Value 1", actData["Test Tab 1"]["Key 1"]);
            Assert.Equal("Value 2", actData["Test Tab 1"]["Key 2"]);
            Assert.Equal("Value 1", actData["Test Tab 2"]["Key 1"]);
        }
        public void DefaultSeverityForManuallyNotifiedExceptionsIsWarning()
        {
            // Arrange
            var client = new BaseClient(StaticData.TestApiKey);

            // Act
            JObject json;
            using (var server = new TestServer(client))
            {
                client.Notify(StaticData.TestThrowException);
                json = server.GetLastResponse();
            }

            // Assert
            Assert.Equal("warning", json["events"][0]["severity"]);
        }
        public void TestNoExceptionLeaks()
        {
            // Arrange
            var client = new BaseClient(StaticData.TestApiKey);

            // Act
            using (var server = new TestServer(client))
            {
                server.Stop();
                try
                {
                    client.Notify(StaticData.TestThrowException);
                }
                catch (Exception e)
                {
                    // Assert
                    Assert.True(false, "No network shouldn't throw: " + e.ToString());
                }
            }
        }
        public void SeveritySetManuallyIsUsedInTheNotification(Severity severity, string expJsonString)
        {
            // Arrange
            var client = new BaseClient(StaticData.TestApiKey);

            // Act
            JObject json;
            using (var server = new TestServer(client))
            {
                client.Notify(StaticData.TestThrowException, severity);
                json = server.GetLastResponse();
            }

            // Assert
            Assert.Equal(expJsonString, json["events"][0]["severity"]);
        }
        public void CheckCallStacksAreReportedCorrectly()
        {
            // Arrange
            var client = new BaseClient(StaticData.TestApiKey);

            // Act
            JObject json;
            using (var server = new TestServer(client))
            {
                client.Notify(StaticData.TestCallStackException);
                json = server.GetLastResponse();
            }

            // Assert
            Assert.Equal(StaticData.TestApiKey, json["apiKey"]);

            var traceJson = json["events"][0]["exceptions"][0]["stacktrace"];

            Assert.Equal(3, traceJson.Count());
            Assert.Equal("TestNamespace.ClassGamma.ThrowException()", traceJson[0]["method"]);
            Assert.Equal("TestNamespace.ClassBeta.ThrowException()", traceJson[1]["method"]);
            Assert.Equal("TestNamespace.ClassAlpha.ThrowException()", traceJson[2]["method"]);
        }