Пример #1
0
        public void SetErrorEntries_ShouldSetExceptionProperty()
        {
            var builder = new NoticeBuilder();

            builder.SetErrorEntries(new Exception());

            var notice = builder.ToNotice();

            Assert.NotNull(notice.Exception);
        }
Пример #2
0
        public void SetErrorEntries_ShouldNotSetActionAndComponentIfNoError()
        {
            var builder = new NoticeBuilder();

            builder.SetErrorEntries(null);

            var notice = builder.ToNotice();

            Assert.True(string.IsNullOrEmpty(notice.Context.Action));
            Assert.True(string.IsNullOrEmpty(notice.Context.Component));
        }
Пример #3
0
        public void ToJsonString_ShouldNotSerializeExceptionAndHttpContext()
        {
            var builder = new NoticeBuilder();

            builder.SetErrorEntries(new Exception());
            builder.SetHttpContext(new FakeHttpContext(), null);

            var notice = builder.ToNotice();
            var json   = NoticeBuilder.ToJsonString(notice);

            Assert.True(json.IndexOf("\"Exception\":", StringComparison.OrdinalIgnoreCase) == -1);
            Assert.True(json.IndexOf("\"HttpContext\":", StringComparison.OrdinalIgnoreCase) == -1);
        }
Пример #4
0
        public void SetErrorEntries_ShouldSetErrorMessageFromExceptionTypeIfNoExceptionMessage()
        {
            var ex = new FakeException();

            var builder = new NoticeBuilder();

            builder.SetErrorEntries(ex);

            var errorEntries = builder.ToNotice().Errors;

            Assert.NotNull(errorEntries);
            Assert.True(errorEntries.Count == 1);
            Assert.True(errorEntries.First().Message.Equals("FakeException"));
        }
Пример #5
0
        public void SetErrorEntries_ShouldLimitInnerExceptionsToThree()
        {
            var ex = new Exception("Main exception",
                                   new Exception("Inner exception 1",
                                                 new Exception("Inner exception 2",
                                                               new Exception("Inner exception 3",
                                                                             new Exception("Inner exception 4")))));

            var builder = new NoticeBuilder();

            builder.SetErrorEntries(ex);

            var errorEntries = builder.ToNotice().Errors;

            // main exception + no more than 3 inner exceptions
            Assert.True(errorEntries.Count.Equals(4));
        }
Пример #6
0
        public void ToJsonString()
        {
            var builder = new NoticeBuilder();

            builder.SetErrorEntries(new Exception());

            var notice = builder.ToNotice();

            var actualJson   = NoticeBuilder.ToJsonString(notice);
            var expectedJson = JsonConvert.SerializeObject(notice, new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            Assert.True(actualJson.Equals(expectedJson));
        }
Пример #7
0
        public void SetErrorEntries_ShouldSetExceptionsInCorrectOrder()
        {
            var ex = new Exception("Main exception",
                                   new Exception("Inner exception 1",
                                                 new Exception("Inner exception 2")));

            var builder = new NoticeBuilder();

            builder.SetErrorEntries(ex);

            var errorEntries = builder.ToNotice().Errors;

            Assert.True(errorEntries.Count.Equals(3));
            Assert.True(errorEntries[0].Message.Equals("Exception: Main exception"));
            Assert.True(errorEntries[1].Message.Equals("Exception: Inner exception 1"));
            Assert.True(errorEntries[2].Message.Equals("Exception: Inner exception 2"));
        }