diff --git a/README.md b/README.md index 243b3d5..ef76724 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ namespace ConsoleApplication } catch (Exception ex) { - var notice = airbrake.CreateNotice(ex); + var notice = airbrake.BuildNotice(ex); var response = airbrake.NotifyAsync(notice).Result; Console.WriteLine("Status: {0}, Id: {1}, Url: {2}", response.Status, response.Id, response.Url); } @@ -330,13 +330,13 @@ var config = AirbrakeConfig.Load(settings); ### AirbrakeNotifier -#### CreateNotice +#### BuildNotice -`CreateNotice` creates a notice with error details that can be sent to the +`BuildNotice` builds a notice with error details that can be sent to the Airbrake dashboard with the help of [`NotifyAsync`](#notifyasync): ```csharp -notifier.CreateNotice(Severity.Error, exception, "Failed with message {0}", exception.Message); +notifier.BuildNotice(Severity.Error, exception, "Failed with message {0}", exception.Message); ``` #### NotifyAsync @@ -363,7 +363,7 @@ Console.WriteLine(response.Url); `SetHttpContext` attaches HTTP context properties to the notice: ```csharp -var notice = notifier.CreateNotice(ex); +var notice = notifier.BuildNotice(ex); notifier.SetHttpContext(notice, new AspNetCoreHttpContext(context)); notifier.NotifyAsync(notice); ``` @@ -440,10 +440,10 @@ airbrake.AddFilter(notice => [Severity][what-is-severity] allows categorizing how severe an error is. By default, it's set to `error`. To redefine severity, simply pass the `Severity` -as a parameter to the `CreateNotice` method. For example: +as a parameter to the `BuildNotice` method. For example: ```csharp -airbrake.CreateNotice(Severity.Critical, exception); +airbrake.BuildNotice(Severity.Critical, exception); ``` ASP.NET Integration diff --git a/docs/asp-net-core-middleware.md b/docs/asp-net-core-middleware.md index 76a69ae..f3837c3 100644 --- a/docs/asp-net-core-middleware.md +++ b/docs/asp-net-core-middleware.md @@ -72,7 +72,7 @@ public IActionResult Contact() if (airbrakeFeature != null) { var notifier = airbrakeFeature.GetNotifier(); - var notice = notifier.CreateNotice(ex); + var notice = notifier.BuildNotice(ex); notice.SetHttpContext(notice, new AspNetCoreHttpContext(HttpContext)); notifier.Notify(notice); } diff --git a/docs/asp-net-http-module.md b/docs/asp-net-http-module.md index c41bce4..2fda222 100644 --- a/docs/asp-net-http-module.md +++ b/docs/asp-net-http-module.md @@ -98,7 +98,7 @@ public async Task Login(LoginViewModel model, string returnUrl) { var airbrake = (AirbrakeHttpModule)HttpContext.ApplicationInstance.Modules["Airbrake"]; var notifier = airbrake.GetNotifier(); - var notice = notifier.CreateNotice(ex); + var notice = notifier.BuildNotice(ex); notice.SetHttpContext(notice, new AspNetHttpContext(System.Web.HttpContext.Current)); notifier.Notify(notice); } diff --git a/docs/dotnet-core-console.md b/docs/dotnet-core-console.md index 73c7db7..d554af8 100644 --- a/docs/dotnet-core-console.md +++ b/docs/dotnet-core-console.md @@ -90,7 +90,7 @@ If you see `dotnet: command not found`, then follow the steps described in https } catch (Exception ex) { - var notice = airbrake.CreateNotice(ex); + var notice = airbrake.BuildNotice(ex); var response = airbrake.NotifyAsync(notice).Result; Console.WriteLine("Status: {0}, Id: {1}, Url: {2}", response.Status, response.Id, response.Url); } diff --git a/examples/ConsoleApp/Program.cs b/examples/ConsoleApp/Program.cs index 4b78814..9a0a201 100644 --- a/examples/ConsoleApp/Program.cs +++ b/examples/ConsoleApp/Program.cs @@ -38,7 +38,7 @@ static void Case1(IDictionary settings) } catch (Exception ex) { - var notice = notifier.CreateNotice(ex); + var notice = notifier.BuildNotice(ex); notifier.NotifyAsync(notice).ContinueWith(task => { if (task.IsFaulted) @@ -66,7 +66,7 @@ static async void Case2(IDictionary settings) } catch (Exception ex) { - var notice = notifier.CreateNotice(ex); + var notice = notifier.BuildNotice(ex); var response = await notifier.NotifyAsync(notice); if (response != null) Console.WriteLine("Status: {0}, Id: {1}, Url: {2}", response.Status, response.Id, response.Url); diff --git a/src/Sharpbrake.Client/AirbrakeNotifier.cs b/src/Sharpbrake.Client/AirbrakeNotifier.cs index c4a9198..110fa6d 100644 --- a/src/Sharpbrake.Client/AirbrakeNotifier.cs +++ b/src/Sharpbrake.Client/AirbrakeNotifier.cs @@ -60,67 +60,67 @@ public void AddFilter(Func filter) } /// - /// Creates a notice for the exception with severity. + /// Builds a notice for the exception with severity. /// /// Exception to report on. - public Notice CreateNotice(Exception exception) + public Notice BuildNotice(Exception exception) { - return CreateNotice(Severity.Error, exception, null, null); + return BuildNotice(Severity.Error, exception, null, null); } /// - /// Creates a notice for the error with severity. + /// Builds a notice for the error with severity. /// /// Message describing the error. /// Objects positionally formatted into the error message. - public Notice CreateNotice(string message, params object[] args) + public Notice BuildNotice(string message, params object[] args) { - return CreateNotice(Severity.Error, null, message, args); + return BuildNotice(Severity.Error, null, message, args); } /// - /// Creates a notice for the error with severity and associated exception. + /// Builds a notice for the error with severity and associated exception. /// /// Exception associated with the error. /// Message describing the error. /// Objects positionally formatted into the error message. - public Notice CreateNotice(Exception exception, string message, params object[] args) + public Notice BuildNotice(Exception exception, string message, params object[] args) { - return CreateNotice(Severity.Error, exception, message, args); + return BuildNotice(Severity.Error, exception, message, args); } /// - /// Creates a notice for the exception with specified severity. + /// Builds a notice for the exception with specified severity. /// /// Severity level of the error. /// Exception to report on. - public Notice CreateNotice(Severity severity, Exception exception) + public Notice BuildNotice(Severity severity, Exception exception) { - return CreateNotice(severity, exception, null, null); + return BuildNotice(severity, exception, null, null); } /// - /// Creates a notice for the error with specified severity. + /// Builds a notice for the error with specified severity. /// /// Severity level of the error. /// Message describing the error. /// Objects positionally formatted into the error message. - public Notice CreateNotice(Severity severity, string message, params object[] args) + public Notice BuildNotice(Severity severity, string message, params object[] args) { - return CreateNotice(severity, null, message, args); + return BuildNotice(severity, null, message, args); } /// - /// Creates a notice for the error with specified severity and associated exception. + /// Builds a notice for the error with specified severity and associated exception. /// /// Severity level of the error. /// Exception associated with the error. /// Message describing the error. /// Objects positionally formatted into the error message. - public Notice CreateNotice(Severity severity, Exception exception, string message, params object[] args) + public Notice BuildNotice(Severity severity, Exception exception, string message, params object[] args) { var log = InternalLogger.CreateInstance(); - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); log.Trace("Setting error entries"); notice.SetErrorEntries(exception, diff --git a/src/Sharpbrake.Client/NoticeBuilder.cs b/src/Sharpbrake.Client/NoticeBuilder.cs index 7bd5baa..1458f64 100644 --- a/src/Sharpbrake.Client/NoticeBuilder.cs +++ b/src/Sharpbrake.Client/NoticeBuilder.cs @@ -14,10 +14,12 @@ namespace Sharpbrake.Client /// public static class NoticeBuilder { + private const int MaxInnerExceptions = 3; + /// /// Creates a new instance of . /// - public static Notice CreateNotice() + public static Notice BuildNotice() { return new Notice { @@ -63,7 +65,7 @@ public static void SetErrorEntries(this Notice notice, Exception exception, stri } // to reduce JSON size no more than 3 inner exceptions are processed - while (ex != null && errors.Count < 4) + while (ex != null && errors.Count <= MaxInnerExceptions) { errors.Add(new ErrorEntry { diff --git a/src/Sharpbrake.Extensions.Logging/AirbrakeLogger.cs b/src/Sharpbrake.Extensions.Logging/AirbrakeLogger.cs index 3afa178..02f46e3 100644 --- a/src/Sharpbrake.Extensions.Logging/AirbrakeLogger.cs +++ b/src/Sharpbrake.Extensions.Logging/AirbrakeLogger.cs @@ -39,7 +39,7 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except if (formatter != null) message = formatter(state, exception); - var notice = notifier.CreateNotice(GetErrorSeverity(logLevel), exception, message); + var notice = notifier.BuildNotice(GetErrorSeverity(logLevel), exception, message); notifier.SetHttpContext(notice, GetHttpContext()); notifier.NotifyAsync(notice); } diff --git a/src/Sharpbrake.Http.Middleware/AirbrakeMiddleware.cs b/src/Sharpbrake.Http.Middleware/AirbrakeMiddleware.cs index 85f4303..4c1f9e7 100644 --- a/src/Sharpbrake.Http.Middleware/AirbrakeMiddleware.cs +++ b/src/Sharpbrake.Http.Middleware/AirbrakeMiddleware.cs @@ -66,7 +66,7 @@ public async Task Invoke(HttpContext context) } catch (Exception ex) { - var notice = notifier.CreateNotice(ex); + var notice = notifier.BuildNotice(ex); notifier.SetHttpContext(notice, new AspNetCoreHttpContext(context)); await notifier.NotifyAsync(notice); throw; diff --git a/src/Sharpbrake.Http.Module/AirbrakeHttpModule.cs b/src/Sharpbrake.Http.Module/AirbrakeHttpModule.cs index 39c3c26..adac6ea 100644 --- a/src/Sharpbrake.Http.Module/AirbrakeHttpModule.cs +++ b/src/Sharpbrake.Http.Module/AirbrakeHttpModule.cs @@ -40,7 +40,7 @@ public void Init(HttpApplication application) var exception = app.Server.GetLastError().GetBaseException(); var context = new AspNetHttpContext(app.Context); - var notice = notifier.CreateNotice(exception); + var notice = notifier.BuildNotice(exception); notifier.SetHttpContext(notice, context); notifier.NotifyAsync(notice); }; diff --git a/src/Sharpbrake.Log4net/AirbrakeAppender.cs b/src/Sharpbrake.Log4net/AirbrakeAppender.cs index 8c03477..4cd7e4f 100644 --- a/src/Sharpbrake.Log4net/AirbrakeAppender.cs +++ b/src/Sharpbrake.Log4net/AirbrakeAppender.cs @@ -129,7 +129,7 @@ private static Severity GetErrorSeverity(Level logLevel) /// protected override void Append(LoggingEvent logEvent) { - var notice = Notifier.CreateNotice(GetErrorSeverity(logEvent.Level), logEvent.ExceptionObject, logEvent.RenderedMessage); + var notice = Notifier.BuildNotice(GetErrorSeverity(logEvent.Level), logEvent.ExceptionObject, logEvent.RenderedMessage); Notifier.SetHttpContext(notice, GetHttpContext()); Notifier.NotifyAsync(notice); } diff --git a/src/Sharpbrake.NLog/AirbrakeTarget.cs b/src/Sharpbrake.NLog/AirbrakeTarget.cs index 9669689..ed5a699 100644 --- a/src/Sharpbrake.NLog/AirbrakeTarget.cs +++ b/src/Sharpbrake.NLog/AirbrakeTarget.cs @@ -137,7 +137,7 @@ protected override void InitializeTarget() /// protected override void Write(LogEventInfo logEvent) { - var notice = Notifier.CreateNotice(GetErrorSeverity(logEvent.Level), logEvent.Exception, logEvent.FormattedMessage); + var notice = Notifier.BuildNotice(GetErrorSeverity(logEvent.Level), logEvent.Exception, logEvent.FormattedMessage); Notifier.SetHttpContext(notice, GetHttpContext()); Notifier.NotifyAsync(notice); } diff --git a/test/Sharpbrake.Client.Tests/AirbrakeNotifierTests.cs b/test/Sharpbrake.Client.Tests/AirbrakeNotifierTests.cs index 3517cfa..b4cc0d7 100644 --- a/test/Sharpbrake.Client.Tests/AirbrakeNotifierTests.cs +++ b/test/Sharpbrake.Client.Tests/AirbrakeNotifierTests.cs @@ -24,36 +24,36 @@ public void Ctor_ShouldThrowExceptionIfConfigIsNotProvided() } [Fact] - public void CreateNotice_ShouldSetDefaultSeverityToError() + public void BuildNotice_ShouldSetDefaultSeverityToError() { var notifier = new AirbrakeNotifier(new AirbrakeConfig()); - var notice1 = notifier.CreateNotice("message"); - var notice2 = notifier.CreateNotice(new Exception()); + var notice1 = notifier.BuildNotice("message"); + var notice2 = notifier.BuildNotice(new Exception()); Assert.Equal(Severity.Error.ToString().ToLowerInvariant(), notice1.Context.Severity); Assert.Equal(Severity.Error.ToString().ToLowerInvariant(), notice2.Context.Severity); } [Fact] - public void CreateNotice_ShouldSetErrorEntriesIfExceptionProvided() + public void BuildNotice_ShouldSetErrorEntriesIfExceptionProvided() { var notifier = new AirbrakeNotifier(new AirbrakeConfig()); - var notice = notifier.CreateNotice(Severity.Error, new Exception()); + var notice = notifier.BuildNotice(Severity.Error, new Exception()); Assert.NotNull(notice.Errors); } [Fact] - public void CreateNotice_ShouldSetErrorEntriesIfMessageProvided() + public void BuildNotice_ShouldSetErrorEntriesIfMessageProvided() { var notifier = new AirbrakeNotifier(new AirbrakeConfig()); - var notice = notifier.CreateNotice(Severity.Error, "message {0}", 1); + var notice = notifier.BuildNotice(Severity.Error, "message {0}", 1); Assert.NotNull(notice.Errors); } [Fact] - public void CreateNotice_ShouldSetConfigurationContext() + public void BuildNotice_ShouldSetConfigurationContext() { var config = new AirbrakeConfig { @@ -64,7 +64,7 @@ public void CreateNotice_ShouldSetConfigurationContext() }; var notifier = new AirbrakeNotifier(config); - var notice = notifier.CreateNotice(Severity.Error, "message"); + var notice = notifier.BuildNotice(Severity.Error, "message"); Assert.NotNull(notice.Context); Assert.NotNull(notice.Context.EnvironmentName); @@ -72,10 +72,10 @@ public void CreateNotice_ShouldSetConfigurationContext() } [Fact] - public void CreateNotice_ShouldSetEnvironmentContext() + public void BuildNotice_ShouldSetEnvironmentContext() { var notifier = new AirbrakeNotifier(new AirbrakeConfig()); - var notice = notifier.CreateNotice(Severity.Error, new Exception(), "message"); + var notice = notifier.BuildNotice(Severity.Error, new Exception(), "message"); Assert.NotNull(notice.Context); Assert.NotNull(notice.Context.Hostname); @@ -87,7 +87,7 @@ public void CreateNotice_ShouldSetEnvironmentContext() public void SetHttpContext_ShouldSetHttpContext() { var notifier = new AirbrakeNotifier(new AirbrakeConfig()); - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); var context = new FakeHttpContext(); notifier.SetHttpContext(notice, context); @@ -109,7 +109,7 @@ public void NotifyAsync_ShouldThrowExceptionIfProjectIdOrKeyIsNotSet(string proj using (var requestHandler = new FakeHttpRequestHandler()) { var notifier = new AirbrakeNotifier(config, requestHandler); - var exceptionTask = Record.ExceptionAsync(() => Task.Run(() => notifier.NotifyAsync(NoticeBuilder.CreateNotice()))); + var exceptionTask = Record.ExceptionAsync(() => Task.Run(() => notifier.NotifyAsync(NoticeBuilder.BuildNotice()))); Assert.NotNull(exceptionTask); @@ -134,7 +134,7 @@ public void NotifyAsync_ShouldSetStatusToIgnoredIfEnvironmentIsIgnored() using (var requestHandler = new FakeHttpRequestHandler()) { var notifier = new AirbrakeNotifier(config, requestHandler); - var response = notifier.NotifyAsync(NoticeBuilder.CreateNotice()).Result; + var response = notifier.NotifyAsync(NoticeBuilder.BuildNotice()).Result; Assert.True(response.Status == RequestStatus.Ignored); } @@ -180,7 +180,7 @@ public void NotifyAsync_ShouldUpdateNoticeAfterApplyingFilters() return n; }); - var notice = notifier.CreateNotice(new Exception()); + var notice = notifier.BuildNotice(new Exception()); var response = notifier.NotifyAsync(notice).Result; var actualNotice = NoticeBuilder.FromJsonString(requestHandler.HttpRequest.GetRequestStreamContent()); @@ -204,7 +204,7 @@ public void NotifyAsync_ShouldSetStatusToIgnoredIfNoticeIsNullAfterApplyingFilte var notifier = new AirbrakeNotifier(config, requestHandler); notifier.AddFilter(n => null); - var notice = notifier.CreateNotice(new Exception()); + var notice = notifier.BuildNotice(new Exception()); var response = notifier.NotifyAsync(notice).Result; Assert.True(response.Status == RequestStatus.Ignored); @@ -231,7 +231,7 @@ public void NotifyAsync_ShouldSetExceptionIfRequestStreamOrResponseIsFaulted(str requestHandler.HttpRequest.IsFaultedGetResponse = faultedTask == "GetResponse"; var notifier = new AirbrakeNotifier(config, requestHandler); - var notifyTask = notifier.NotifyAsync(NoticeBuilder.CreateNotice()); + var notifyTask = notifier.NotifyAsync(NoticeBuilder.BuildNotice()); var exceptionTask = Record.ExceptionAsync(() => notifyTask); Assert.NotNull(exceptionTask); @@ -263,7 +263,7 @@ public void NotifyAsync_ShouldSetCanceledIfRequestStreamOrResponseIsCanceled(str requestHandler.HttpRequest.IsCanceledGetResponse = canceledTask == "GetResponse"; var notifier = new AirbrakeNotifier(config, requestHandler); - var notifyTask = notifier.NotifyAsync(NoticeBuilder.CreateNotice()); + var notifyTask = notifier.NotifyAsync(NoticeBuilder.BuildNotice()); var exceptionTask = Record.ExceptionAsync(() => notifyTask); Assert.NotNull(exceptionTask); @@ -294,7 +294,7 @@ public void NotifyAsync_ShouldSetRequestStatusToSuccessOnlyIfStatusCodeCreated(b requestHandler.HttpResponse.ResponseJson = "{\"Id\":\"12345\",\"Url\":\"https://airbrake.io/\"}"; var notifier = new AirbrakeNotifier(config, requestHandler); - var airbrakeResponse = notifier.NotifyAsync(NoticeBuilder.CreateNotice()).Result; + var airbrakeResponse = notifier.NotifyAsync(NoticeBuilder.BuildNotice()).Result; if (isStatusCodeCreated) Assert.True(airbrakeResponse.Status == RequestStatus.Success); diff --git a/test/Sharpbrake.Client.Tests/InternalLoggerTests.cs b/test/Sharpbrake.Client.Tests/InternalLoggerTests.cs index 74456c4..f28761c 100644 --- a/test/Sharpbrake.Client.Tests/InternalLoggerTests.cs +++ b/test/Sharpbrake.Client.Tests/InternalLoggerTests.cs @@ -53,7 +53,7 @@ private void NotifyAsync() requestHandler.HttpResponse.ResponseJson = "{\"Id\":\"12345\",\"Url\":\"https://airbrake.io/\"}"; var notifier = new AirbrakeNotifier(config, requestHandler); - var notice = notifier.CreateNotice(new Exception()); + var notice = notifier.BuildNotice(new Exception()); var airbrakeResponse = notifier.NotifyAsync(notice).Result; } } diff --git a/test/Sharpbrake.Client.Tests/NoticeBuilderTests.cs b/test/Sharpbrake.Client.Tests/NoticeBuilderTests.cs index 0c04b2f..5538536 100644 --- a/test/Sharpbrake.Client.Tests/NoticeBuilderTests.cs +++ b/test/Sharpbrake.Client.Tests/NoticeBuilderTests.cs @@ -15,9 +15,9 @@ namespace Sharpbrake.Client.Tests public class NoticeBuilderTests { [Fact] - public void CreateNotice_ShouldInitializeContextAndNotifierInfo() + public void BuildNotice_ShouldInitializeContextAndNotifierInfo() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); Assert.NotNull(notice.Context); Assert.NotNull(notice.Context.Notifier); @@ -30,7 +30,7 @@ public void SetErrorEntries_ShouldSetExceptionsInCorrectOrder() new Exception("Inner exception 1", new Exception("Inner exception 2"))); - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetErrorEntries(ex, string.Empty); var errorEntries = notice.Errors; @@ -51,7 +51,7 @@ public void SetErrorEntries_ShouldLimitInnerExceptionsToThree() new Exception("Inner exception 3", new Exception("Inner exception 4"))))); - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetErrorEntries(ex, string.Empty); var errorEntries = notice.Errors; @@ -65,7 +65,7 @@ public void SetErrorEntries_ShouldSetMessageIfPresent() { var ex = new FakeException("error message from exception"); - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetErrorEntries(ex, "message"); var errorEntries = notice.Errors; @@ -80,7 +80,7 @@ public void SetErrorEntries_ShouldSetErrorMessageFromExceptionIfNoMessage() { var ex = new FakeException("error message from exception"); - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetErrorEntries(ex, string.Empty); var errorEntries = notice.Errors; @@ -93,7 +93,7 @@ public void SetErrorEntries_ShouldSetErrorMessageFromExceptionIfNoMessage() [Fact] public void SetErrorEntries_ShouldSetExceptionProperty() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetErrorEntries(new Exception(), string.Empty); Assert.NotNull(notice.Exception); @@ -102,7 +102,7 @@ public void SetErrorEntries_ShouldSetExceptionProperty() [Fact] public void SetErrorEntries_ShouldSetErrorEntryUsingMessageIfExceptionEmpty() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetErrorEntries(null, "message"); var errorEntries = notice.Errors; @@ -115,7 +115,7 @@ public void SetErrorEntries_ShouldSetErrorEntryUsingMessageIfExceptionEmpty() [Fact] public void SetConfigurationContext_ShouldSetEnvironmentNameAndAppVersion() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetConfigurationContext(new AirbrakeConfig { Environment = "local", @@ -130,7 +130,7 @@ public void SetConfigurationContext_ShouldSetEnvironmentNameAndAppVersion() [Fact] public void SetConfigurationContext_ShouldNotSetEnvironmentNameAndAppVersionIfConfigIsNull() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetConfigurationContext(null); Assert.NotNull(notice.Context); @@ -145,7 +145,7 @@ public void SetConfigurationContext_ShouldNotSetEnvironmentNameAndAppVersionIfCo InlineData("host", "os", "lang")] public void SetEnvironmentContext_ShouldSetEnvironmentContextAccordingToPassedParameters(string host, string os, string lang) { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetEnvironmentContext(host, os, lang); if (string.IsNullOrEmpty(host) && string.IsNullOrEmpty(os) && string.IsNullOrEmpty(lang)) @@ -165,7 +165,7 @@ public void SetEnvironmentContext_ShouldSetEnvironmentContextAccordingToPassedPa [Fact] public void SetHttpContext_ShouldNotSetHttpContextIfContextParamIsEmpty() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetHttpContext(null, null); Assert.Null(notice.HttpContext); @@ -183,7 +183,7 @@ public void SetHttpContext_ContextHttpParameters(string url, string userAgent) UserAgent = userAgent }; - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetHttpContext(httpContext, null); Assert.NotNull(notice.Context); @@ -205,7 +205,7 @@ public void SetHttpContext_ContextUserInfo(string id, string name, string email) UserEmail = email }; - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetHttpContext(httpContext, null); Assert.NotNull(notice.Context); @@ -225,7 +225,7 @@ public void SetHttpContext_ShouldSetParametersIfConfigIsNotDefined() Session = new Dictionary() }; - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetHttpContext(httpContext, null); Assert.NotNull(notice.Params); @@ -245,7 +245,7 @@ public void SetHttpContext_ShouldSetParametersIfConfigIsDefined() var config = new AirbrakeConfig(); - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetHttpContext(httpContext, config); Assert.NotNull(notice.Params); @@ -256,7 +256,7 @@ public void SetHttpContext_ShouldSetParametersIfConfigIsDefined() [Fact] public void SetHttpContext_ShouldSetHttpContextProperty() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetHttpContext(new FakeHttpContext(), null); Assert.NotNull(notice.HttpContext); @@ -271,7 +271,7 @@ public void SetHttpContext_ShouldSetActionAndContextIfProvided() Component = "Component" }; - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetHttpContext(httpContext, null); Assert.True(!string.IsNullOrEmpty(notice.Context.Action)); @@ -281,7 +281,7 @@ public void SetHttpContext_ShouldSetActionAndContextIfProvided() [Fact] public void SetSeverity_ShouldSetSeverityLowercase() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetSeverity(Severity.Critical); Assert.Equal("critical", notice.Context.Severity); @@ -290,7 +290,7 @@ public void SetSeverity_ShouldSetSeverityLowercase() [Fact] public void ToJsonString() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetErrorEntries(new Exception(), string.Empty); var actualJson = notice.ToJsonString(); @@ -318,7 +318,7 @@ public void ToJsonString() [Fact] public void ToJsonString_ShouldNotSerializeExceptionAndHttpContext() { - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetErrorEntries(new Exception(), string.Empty); notice.SetHttpContext(new FakeHttpContext(), null); @@ -340,7 +340,7 @@ public void ToJsonString_ShouldTruncateNoticeBigger64KB() } }; - var notice = NoticeBuilder.CreateNotice(); + var notice = NoticeBuilder.BuildNotice(); notice.SetHttpContext(httpContext, null); var json = notice.ToJsonString(); diff --git a/test/Sharpbrake.Client.Tests/UtilsTests.cs b/test/Sharpbrake.Client.Tests/UtilsTests.cs index af0213f..fd838c5 100644 --- a/test/Sharpbrake.Client.Tests/UtilsTests.cs +++ b/test/Sharpbrake.Client.Tests/UtilsTests.cs @@ -427,11 +427,17 @@ public void LogResponse_ShouldLogIfResponseNotEmpty() Status = RequestStatus.Success }; - Utils.LogResponse(logFile, response); + try + { + Utils.LogResponse(logFile, response); - Assert.True(File.Exists(logFile)); - Assert.True(!string.IsNullOrEmpty(File.ReadAllText(logFile))); - File.Delete(logFile); + Assert.True(File.Exists(logFile)); + Assert.True(!string.IsNullOrEmpty(File.ReadAllText(logFile))); + } + finally + { + File.Delete(logFile); + } } [Fact] @@ -439,10 +445,16 @@ public void LogResponse_ShouldNotLogIfResponseEmpty() { var logFile = Guid.NewGuid() + ".log"; - Utils.LogResponse(logFile, null); + try + { + Utils.LogResponse(logFile, null); - Assert.True(!File.Exists(logFile)); - File.Delete(logFile); + Assert.True(!File.Exists(logFile)); + } + finally + { + File.Delete(logFile); + } } [Fact]