Пример #1
0
        public void ExceptionPackageTest()
        {
            const string rollbarDataTitle = "You have some coding to do...";
            const string exceptionMessage = "Forgotten method";

            System.Exception exception = new NotImplementedException(exceptionMessage);

            IRollbarPackage packagingStrategy =
                new ExceptionPackage(exception, rollbarDataTitle);

            Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!");

            Data rollbarData = packagingStrategy.PackageAsRollbarData();

            Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!");
            Assert.IsNotNull(rollbarData.Body);
            Assert.IsNotNull(rollbarData.Body.Trace);
            Assert.IsNull(rollbarData.Body.Message);
            Assert.IsNull(rollbarData.Body.TraceChain);
            Assert.IsNull(rollbarData.Body.CrashReport);

            Assert.IsNotNull(rollbarData.Body.Trace.Exception);
            Assert.AreEqual(exceptionMessage, rollbarData.Body.Trace.Exception.Message);
            Assert.AreEqual(exception.GetType().FullName, rollbarData.Body.Trace.Exception.Class);
        }
Пример #2
0
        public void AggregateExceptionPackageTest()
        {
            const string rollbarDataTitle       = "You have some coding to do...";
            const string innerExceptionMessage1 = "Forgotten method";

            System.Exception innerException1        = new NotImplementedException(innerExceptionMessage1);
            const string     innerExceptionMessage2 = "Forgotten null-check";

            System.Exception innerException2  = new NullReferenceException(innerExceptionMessage2);
            const string     exceptionMessage = "Application level exception";

            System.Exception exception = new AggregateException(exceptionMessage, innerException1, innerException2);

            IRollbarPackage packagingStrategy =
                new ExceptionPackage(exception, rollbarDataTitle);

            Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!");

            Data rollbarData = packagingStrategy.PackageAsRollbarData();

            Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!");
            Assert.IsNotNull(rollbarData.Body);
            Assert.IsNotNull(rollbarData.Body.TraceChain);
            Assert.IsNull(rollbarData.Body.Trace);
            Assert.IsNull(rollbarData.Body.Message);
            Assert.IsNull(rollbarData.Body.CrashReport);

            Assert.AreEqual(2, rollbarData.Body.TraceChain.Length);

            Assert.IsNotNull(rollbarData.Body.TraceChain[0]);
            Assert.IsNotNull(rollbarData.Body.TraceChain[0].Exception);
            Assert.AreEqual(innerExceptionMessage1, rollbarData.Body.TraceChain[0].Exception.Message);
            Assert.AreEqual(innerException1.GetType().FullName, rollbarData.Body.TraceChain[0].Exception.Class);

            Assert.IsNotNull(rollbarData.Body.TraceChain[1]);
            Assert.IsNotNull(rollbarData.Body.TraceChain[1].Exception);
            Assert.AreEqual(innerExceptionMessage2, rollbarData.Body.TraceChain[1].Exception.Message);
            Assert.AreEqual(innerException2.GetType().FullName, rollbarData.Body.TraceChain[1].Exception.Class);
        }
Пример #3
0
        public void PersonPackageDecoratorTest()
        {
            const string rollbarDataTitle = "Let's test some strategy decoration...";
            const string exceptionMessage = "Someone forgot null-test!";

            System.Exception exception = new NullReferenceException(exceptionMessage);

            IRollbarPackage packagingStrategy =
                new ExceptionPackage(exception, rollbarDataTitle);

            Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!");

            Data rollbarData = packagingStrategy.PackageAsRollbarData();

            Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!");
            Assert.IsNotNull(rollbarData.Body);
            Assert.IsNotNull(rollbarData.Body.Trace);
            Assert.IsNull(rollbarData.Body.Message);
            Assert.IsNull(rollbarData.Body.TraceChain);
            Assert.IsNull(rollbarData.Body.CrashReport);

            Assert.IsNotNull(rollbarData.Body.Trace.Exception);
            Assert.AreEqual(exceptionMessage, rollbarData.Body.Trace.Exception.Message);
            Assert.AreEqual(exception.GetType().FullName, rollbarData.Body.Trace.Exception.Class);

            Assert.IsTrue(rollbarData.Timestamp.HasValue);
            long initialTimestamp = rollbarData.Timestamp.Value;

            const string personID       = "007";
            const string personUsername = "******";
            const string personEmail    = "*****@*****.**";

            packagingStrategy = new PersonPackageDecorator(packagingStrategy, personID, personUsername, personEmail);

            // All the asserts prior to the decoration should be good again:

            Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!");

            rollbarData = packagingStrategy.PackageAsRollbarData();

            Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!");
            Assert.IsNotNull(rollbarData.Body);
            Assert.IsNotNull(rollbarData.Body.Trace);
            Assert.IsNull(rollbarData.Body.Message);
            Assert.IsNull(rollbarData.Body.TraceChain);
            Assert.IsNull(rollbarData.Body.CrashReport);

            Assert.IsNotNull(rollbarData.Body.Trace.Exception);
            Assert.AreEqual(exceptionMessage, rollbarData.Body.Trace.Exception.Message);
            Assert.AreEqual(exception.GetType().FullName, rollbarData.Body.Trace.Exception.Class);

            // Person decoration specific asserts:

            Assert.IsNotNull(rollbarData.Person);
            Assert.AreEqual(personID, rollbarData.Person.Id);
            Assert.AreEqual(personUsername, rollbarData.Person.UserName);
            Assert.AreEqual(personEmail, rollbarData.Person.Email);

            // Make sure the Data.Timestamp was not overwritten:

            Assert.IsTrue(rollbarData.Timestamp.HasValue);
            Assert.AreEqual(initialTimestamp, rollbarData.Timestamp.Value);
            System.Diagnostics.Debug.WriteLine($"Initial timestamp: {initialTimestamp}");
            System.Diagnostics.Debug.WriteLine($"Decorated timestamp: {rollbarData.Timestamp.Value}");
        }
        public void BasicTest()
        {
            const string rollbarDataTitle = "Let's test some strategy decoration...";
            const string exceptionMessage = "Someone forgot null-test!";

            System.Exception exception = new NullReferenceException(exceptionMessage);

            IRollbarPackage packagingStrategy =
                new ExceptionPackage(exception, rollbarDataTitle);

            Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!");

            Data rollbarData = packagingStrategy.PackageAsRollbarData();

            Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!");
            Assert.IsNotNull(rollbarData.Body);
            Assert.IsNotNull(rollbarData.Body.Trace);
            Assert.IsNull(rollbarData.Body.Message);
            Assert.IsNull(rollbarData.Body.TraceChain);
            Assert.IsNull(rollbarData.Body.CrashReport);

            Assert.IsNotNull(rollbarData.Body.Trace.Exception);
            Assert.AreEqual(exceptionMessage, rollbarData.Body.Trace.Exception.Message);
            Assert.AreEqual(exception.GetType().FullName, rollbarData.Body.Trace.Exception.Class);

            Assert.IsTrue(rollbarData.Timestamp.HasValue);
            long initialTimestamp = rollbarData.Timestamp.Value;


            const string customKey1   = "customKey1";
            const string customValue1 = "customValue1";

            const string customKey2   = "customKey2";
            const string customValue2 = "customValue2";

            Dictionary <string, object> customData = new Dictionary <string, object>()
            {
                { customKey1, customValue1 },
                { customKey2, customValue2 },
            };

            packagingStrategy = new CustomKeyValuePackageDecorator(packagingStrategy, customData);

            // All the asserts prior to the decoration should be good again:

            Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!");

            rollbarData = packagingStrategy.PackageAsRollbarData();

            Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!");
            Assert.IsNotNull(rollbarData.Body);
            Assert.IsNotNull(rollbarData.Body.Trace);
            Assert.IsNull(rollbarData.Body.Message);
            Assert.IsNull(rollbarData.Body.TraceChain);
            Assert.IsNull(rollbarData.Body.CrashReport);

            Assert.IsNotNull(rollbarData.Body.Trace.Exception);
            Assert.AreEqual(exceptionMessage, rollbarData.Body.Trace.Exception.Message);
            Assert.AreEqual(exception.GetType().FullName, rollbarData.Body.Trace.Exception.Class);

            // Custom data decoration specific asserts:

            Assert.IsNotNull(rollbarData.Custom);
            Assert.AreEqual(customData.Count, rollbarData.Custom.Count);
            Assert.IsTrue(rollbarData.Custom.ContainsKey(customKey1));
            Assert.IsTrue(rollbarData.Custom.ContainsKey(customKey2));
            Assert.AreEqual(customValue1, rollbarData.Custom[customKey1]);
            Assert.AreEqual(customValue2, rollbarData.Custom[customKey2]);

            // Make sure the Data.Timestamp was not overwritten:

            Assert.IsTrue(rollbarData.Timestamp.HasValue);
            Assert.AreEqual(initialTimestamp, rollbarData.Timestamp.Value);
            System.Diagnostics.Debug.WriteLine($"Initial timestamp: {initialTimestamp}");
            System.Diagnostics.Debug.WriteLine($"Decorated timestamp: {rollbarData.Timestamp.Value}");
        }