public void SetErrorEntries_ShouldSetExceptionProperty() { var builder = new NoticeBuilder(); builder.SetErrorEntries(new Exception()); var notice = builder.ToNotice(); Assert.NotNull(notice.Exception); }
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)); }
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); }
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")); }
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)); }
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)); }
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")); }