diff --git a/.gitignore b/.gitignore
index fac6c8b..0626272 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,37 @@
-.idea/
-src/RollbarDotNet/obj/
-src/RollbarDotNet/bin/
-.vs/
-*.lock.json
-test/RollbarDotNet.Tests/bin/
-test/RollbarDotNet.Tests/obj/
-*.user
\ No newline at end of file
+*.swp
+*.*~
+project.lock.json
+.DS_Store
+*.pyc
+nupkg/
+
+# Visual Studio Code
+.vscode
+
+# Rider
+.idea
+
+# User-specific files
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+build/
+bld/
+[Bb]in/
+[Oo]bj/
+[Oo]ut/
+msbuild.log
+msbuild.err
+msbuild.wrn
+
+# Visual Studio 2015
+.vs/
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
index c813ab9..8ebb8ee 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -1,18 +1,18 @@
{
- // Use IntelliSense to find out which attributes exist for C# debugging
- // Use hover for the description of the existing attributes
- // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
- "version": "0.2.0",
- "configurations": [
+ // Use IntelliSense to find out which attributes exist for C# debugging
+ // Use hover for the description of the existing attributes
+ // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
+ "version": "0.2.0",
+ "configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
- "program": "${workspaceFolder}/test/RollbarDotNet.Tests/bin/Debug/netcoreapp1.0/RollbarDotNet.Tests.dll",
+ "program": "${workspaceFolder}/RollbarDotNet.Tests/bin/Debug/netcoreapp3.1/RollbarDotNet.Tests.dll",
"args": [],
- "cwd": "${workspaceFolder}/test/RollbarDotNet.Tests",
+ "cwd": "${workspaceFolder}/RollbarDotNet.Tests",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
@@ -23,6 +23,6 @@
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
- }
- ,]
+ },
+ ]
}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 7095026..a1e101c 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -7,7 +7,7 @@
"type": "process",
"args": [
"build",
- "${workspaceFolder}/test/RollbarDotNet.Tests/RollbarDotNet.Tests.csproj"
+ "${workspaceFolder}/RollbarDotNet.Tests/RollbarDotNet.Tests.csproj"
],
"problemMatcher": "$msCompile"
}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8601b7f..379286f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,71 +1,83 @@
-# 0.7.0
+# Releases
+
+## 0.8.0
+
+Released: 2020/03/25
+
+- Dropped .NET Standard 1.5 support
+- Upgraded to .NET Standard 2.1
+- Change scope of RollbarClient to singleton.
+
+## 0.7.0
+
+Released: 2018/120/08
- Added ILogger support.
-# 0.6.4
+## 0.6.4
Released: 2017/10/22
- Fix a null reference exception when no declaring type on thrown exception.
-# 0.6.3
+## 0.6.3
Released: 2017/09/04
- Use per-request dependencies for handling RollbarClient to prevent errors.
-# 0.6.2
+## 0.6.2
Released: 2017/8/20
- Change method trace string to have full namespace, method name and parameters.
-# 0.6.1
+## 0.6.1
Released: 2017/8/20
- Fixed a bug where .NET Core Service extensions were excluded from the library.
-# 0.6.0
+## 0.6.0
Released: 2017/8/20
-## Features
+### Features
- Upgrade to VS2017/CSProj.
- Add trace frame support.
- Also target NetStandard2.0
-# 0.5.2
+## 0.5.2
Released: 2017/4/21
-## Features
+### Features
-- Updated documentation. #49
-- Can now disable Rollbar from configuration. #48
+- Updated documentation. ##49
+- Can now disable Rollbar from configuration. ##48
-## Bug Fixes
+### Bug Fixes
-- Fix issue with trying to access Request.Form variables during POSTs that may not actually support form variables. #54
+- Fix issue with trying to access Request.Form variables during POSTs that may not actually support form variables. ##54
-# 0.5.1
+## 0.5.1
Released: 2017/3/10
-## Features
+### Features
- More robust testing of sending exceptions to Rollbar (see readme.md for instructions on configuring token for testing).
-## Bug Fixes
+### Bug Fixes
- Fixed issue sending Rollbar exceptions.
-# 0.5.0
+## 0.5.0
Released: 2017/2/26
-## Features
+### Features
- IHttpContextAccessor is no longer assumed to be included as part of `AddIdentity()`, we'll add it.
- Testing of dependency injection for web platforms (console apps coming soon).
@@ -74,43 +86,43 @@
- Person record support (thank you mkdabrowski).
- Exception builder is now injectable.
-## Bug Fixes
+### Bug Fixes
- Sending a message to Rollbar no longer results in a null reference exception being thrown.
-# 0.4.0
+## 0.4.0
Released: 2016/9/30
-## Features
+### Features
- Upgrade for .NET Core 1.0 release.
-# 0.3.0
+## 0.3.0
Released: 2016/6/12
-## Features
+### Features
- Added support for cookies on request body.
- Added blacklisting variables by name.
-# 0.2.0
+## 0.2.0
Released: 2016/6/9
-## Features
+### Features
- Rollbar message UUID available after error is reported.
- Removed custom parameters from message body.
- Documentation for required configuration variables.
-# 0.1.0
+## 0.1.0
Released: 2016/5/31
Initial release.
-## Features
+### Features
- Ability to send basic logs to Rollbar
diff --git a/Readme.md b/Readme.md
index 741c6da..b716ebb 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,6 +1,6 @@
# RollbarDotNet
-[]()
+[]()
[]()
[](https://codeclimate.com/github/RoushTech/RollbarDotNet/maintainability)
@@ -8,13 +8,13 @@ Rollbar support for your .NET Core projects, relies on dependency injection and
Inspired by RollbarSharp, great library, just required too many tweaks to make play with .NET core well in my opinion.
-# Testing
+## Testing
Environment variables for testing:
- ROLLBAR_TOKEN - Rollbar token for testing.
-# Required services
+## Required services
Please make sure the following services are available for the various builder modules.
@@ -22,7 +22,7 @@ Please make sure the following services are available for the various builder mo
app.UseRollbarExceptionHandler();
```
-# Using in ASP.NET Core
+## Using in ASP.NET Core
Place the following after your error handling code in Startup.Configure:
@@ -42,7 +42,7 @@ There is also one that doesn't load the builders for building out environment in
services.AddRollbar(Configuration);
```
-Hook up the rollar configuration using the following code:
+Hook up the Rollbar configuration using the following code:
``` csharp
services.AddOptions(); // Most apps already are using this, but just in case.
@@ -54,11 +54,20 @@ Configure Rollbar from your appSettings.json file like so:
``` javascript
"Rollbar": {
"AccessToken": "[access token here]",
- "Environment": "[named environment here]"
+ "Environment": "[named environment here]",
+ "Disabled": false
}
```
-## Getting Occurrence UUIDs
+If you want to use the ILogger implementation add this:
+
+``` csharp
+ loggerFactory.AddRollbarDotNetLogger(app.ApplicationServices);
+```
+
+In your `Configure()` method inside of `Startup.cs`
+
+## Getting Occurrence UUID
Getting the occurrence UUID is easy, just get it from the HttpContext Feature collection:
@@ -70,27 +79,27 @@ public IActionResult Error()
}
```
-The UUID can be looked up directly via https://rollbar.com/occurrence/uuid/?uuid=[UUID HERE]. This may be really useful if you want to let your users report errors to you, you can include this UUID automatically in the report.
+The UUID can be looked up directly via `https://rollbar.com/occurrence/uuid/?uuid=[UUID HERE]`. This may be really useful if you want to let your users report errors to you, you can include this UUID automatically in the report.
You can check if Rollbar has reported the exception via the IRollbarResponseFeature.Handled boolean.
-# Calling Directly
+## Calling Directly
You can also post messages/exceptions directly if you so wish.
``` csharp
// Send an exception
-var response = await this.Rollbar.SendException(exception);
+var response = await Rollbar.SendException(exception);
response.Uuid //Event UUID that can be looked up on the rollbar site.
// Send a message
-var response = await this.Rollbar.SendMessage("Hello World!", RollbarLevels.Message);
+var response = await Rollbar.SendMessage("Hello World!", RollbarLevels.Message);
```
-# Calling Without Dependency Injection
+## Calling Without Dependency Injection
-Although I *highly recommend* using depdency injection, you can fairly easily configure Rollbar by hand:
+Although I *highly recommend* using dependency injection, you can fairly easily configure Rollbar by hand:
``` csharp
var rollbarOptions = Options.Create(new RollbarOptions
@@ -120,7 +129,7 @@ catch(Exception exception)
}
```
-# Blacklists
+## Blacklists
Blacklisting will replace variables with asterisks ("**********") when data is sent to Rollbar.
@@ -141,23 +150,10 @@ Inside of your appSettings.json you have two options, using plaintext or regular
}
```
-Additional Blacklists can be coded by inheriting from the RollbarDotNet.Blacklisters.IBlacklister interface and registering it with your application's dependency injection framework.
-
+Additional Blacklists can be coded by inheriting from the `RollbarDotNet.Blacklisters.IBlacklister` interface and registering it with your application's dependency injection framework.
## To do
-### Implement stack frames
-
-As of writing this .NET Core does not support walking the stack frames of the exception, means our error messages are pretty weak.
-
-### Log4net support
-
-As far as I know log4net is _currently_ implementing .NET Core support.
-
### Break out into separate libraries
-.NET Core is all about keeping things slim, do we put ASPNETCore code in a different lib?
-
-### .NET 4.5.1 support
-
-Would be nice for this to support .NET 4.5.1, no testing and no real effort outside of some basic preprocessor stuff in place.
\ No newline at end of file
+.NET Core is all about keeping things slim, do we put ASP.NET code in a different lib?
diff --git a/test/RollbarDotNet.Tests/BlacklistCollectionTests.cs b/RollbarDotNet.Tests/BlacklistCollectionTests.cs
similarity index 85%
rename from test/RollbarDotNet.Tests/BlacklistCollectionTests.cs
rename to RollbarDotNet.Tests/BlacklistCollectionTests.cs
index 32cde67..43661c7 100644
--- a/test/RollbarDotNet.Tests/BlacklistCollectionTests.cs
+++ b/RollbarDotNet.Tests/BlacklistCollectionTests.cs
@@ -13,7 +13,7 @@ public void Check_Pass()
var blacklisterMock = new Mock();
blacklisterMock.Setup(b => b.Check("test")).Returns(true);
var blacklistCollection = new BlacklistCollection(new List { blacklisterMock.Object });
- Assert.Equal(true, blacklistCollection.Check("test"));
+ Assert.True(blacklistCollection.Check("test"));
}
[Fact]
@@ -22,7 +22,7 @@ public void CheckFails()
var blacklisterMock = new Mock();
blacklisterMock.Setup(b => b.Check("test")).Returns(true);
var blacklistCollection = new BlacklistCollection(new List { blacklisterMock.Object });
- Assert.Equal(false, blacklistCollection.Check("testa"));
+ Assert.False(blacklistCollection.Check("testa"));
}
}
}
\ No newline at end of file
diff --git a/test/RollbarDotNet.Tests/Blacklisters/ConfigurationBlacklisterTests.cs b/RollbarDotNet.Tests/Blacklisters/ConfigurationBlacklisterTests.cs
similarity index 68%
rename from test/RollbarDotNet.Tests/Blacklisters/ConfigurationBlacklisterTests.cs
rename to RollbarDotNet.Tests/Blacklisters/ConfigurationBlacklisterTests.cs
index f75f304..379cff0 100644
--- a/test/RollbarDotNet.Tests/Blacklisters/ConfigurationBlacklisterTests.cs
+++ b/RollbarDotNet.Tests/Blacklisters/ConfigurationBlacklisterTests.cs
@@ -26,29 +26,29 @@ protected ConfigurationBlacklister Setup()
[Fact]
public void RegexFail()
{
- var configurationBlacklister = this.Setup();
- Assert.Equal(false, configurationBlacklister.Check("regexfail"));
+ var configurationBlacklister = Setup();
+ Assert.False(configurationBlacklister.Check("regexfail"));
}
[Fact]
public void RegexPass()
{
- var configurationBlacklister = this.Setup();
- Assert.Equal(true, configurationBlacklister.Check("regex"));
+ var configurationBlacklister = Setup();
+ Assert.True(configurationBlacklister.Check("regex"));
}
[Fact]
public void StringFail()
{
- var configurationBlacklister = this.Setup();
- Assert.Equal(false, configurationBlacklister.Check("testa"));
+ var configurationBlacklister = Setup();
+ Assert.False(configurationBlacklister.Check("testa"));
}
[Fact]
public void StringPass()
{
- var configurationBlacklister = this.Setup();
- Assert.Equal(true, configurationBlacklister.Check("test"));
+ var configurationBlacklister = Setup();
+ Assert.True(configurationBlacklister.Check("test"));
}
}
}
\ No newline at end of file
diff --git a/test/RollbarDotNet.Tests/Builder/ConfigurationBuilderTests.cs b/RollbarDotNet.Tests/Builder/ConfigurationBuilderTests.cs
similarity index 100%
rename from test/RollbarDotNet.Tests/Builder/ConfigurationBuilderTests.cs
rename to RollbarDotNet.Tests/Builder/ConfigurationBuilderTests.cs
diff --git a/test/RollbarDotNet.Tests/Builder/EnvironmentBuilderTests.cs b/RollbarDotNet.Tests/Builder/EnvironmentBuilderTests.cs
similarity index 100%
rename from test/RollbarDotNet.Tests/Builder/EnvironmentBuilderTests.cs
rename to RollbarDotNet.Tests/Builder/EnvironmentBuilderTests.cs
diff --git a/test/RollbarDotNet.Tests/Builder/ExceptionBuilderTests.cs b/RollbarDotNet.Tests/Builder/ExceptionBuilderTests.cs
similarity index 79%
rename from test/RollbarDotNet.Tests/Builder/ExceptionBuilderTests.cs
rename to RollbarDotNet.Tests/Builder/ExceptionBuilderTests.cs
index accc461..0231eda 100644
--- a/test/RollbarDotNet.Tests/Builder/ExceptionBuilderTests.cs
+++ b/RollbarDotNet.Tests/Builder/ExceptionBuilderTests.cs
@@ -12,15 +12,15 @@ public class ExceptionBuilderTests
{
public ExceptionBuilderTests()
{
- this.ExceptionBuilder = new ExceptionBuilder();
- this.Payload = new Payload();
+ ExceptionBuilder = new ExceptionBuilder();
+ Payload = new Payload();
}
protected ExceptionBuilder ExceptionBuilder { get; set; }
protected Payload Payload { get; set; }
- protected void ThrowException(string a, int b)
+ protected void ThrowException(string _1, int _2)
{
throw new Exception("test exception");
}
@@ -49,8 +49,8 @@ public void BuildsInnerException()
}
catch (Exception exception)
{
- this.ExceptionBuilder.Execute(this.Payload, exception);
- var body = this.Payload.Data?.Body;
+ ExceptionBuilder.Execute(Payload, exception);
+ var body = Payload.Data?.Body;
Assert.NotNull(body?.TraceChain);
var first = body.TraceChain.First();
Assert.Equal("Exception", first.Exception?.Class);
@@ -65,7 +65,7 @@ public void BuildsInnerException()
[Fact]
public void ExceptionCannotBeNull()
{
- Assert.Throws(() => this.ExceptionBuilder.Execute(this.Payload, null));
+ Assert.Throws(() => ExceptionBuilder.Execute(Payload, null));
}
[Fact]
@@ -77,7 +77,7 @@ public void PayloadCannotBeNull()
}
catch (Exception exception)
{
- Assert.Throws(() => this.ExceptionBuilder.Execute(null, exception));
+ Assert.Throws(() => ExceptionBuilder.Execute(null, exception));
}
}
@@ -86,18 +86,18 @@ public void SetsPayload()
{
try
{
- this.ThrowException("", 0);
+ ThrowException("", 0);
}
catch (Exception exception)
{
- this.ExceptionBuilder.Execute(this.Payload, exception);
- var payload = this.Payload.Data?.Body?.TraceChain?.FirstOrDefault();
+ ExceptionBuilder.Execute(Payload, exception);
+ var payload = Payload.Data?.Body?.TraceChain?.FirstOrDefault();
Assert.Equal("Exception", payload?.Exception?.Class);
Assert.Equal("test exception", payload?.Exception?.Message);
Assert.True(payload?.Frames?.Count == 2);
var frame = payload?.Frames?.FirstOrDefault();
Assert.Equal(
- "RollbarDotNet.Tests.Builder.ExceptionBuilderTests.ThrowException(System.String a, System.Int32 b)",
+ "RollbarDotNet.Tests.Builder.ExceptionBuilderTests.ThrowException(System.String _1, System.Int32 _2)",
frame?.Method);
var stackTrace = new StackTrace(exception, true);
var stackTraceFrame = stackTrace.GetFrames().FirstOrDefault();
diff --git a/test/RollbarDotNet.Tests/Builder/PersonBuilderTests.cs b/RollbarDotNet.Tests/Builder/PersonBuilderTests.cs
similarity index 52%
rename from test/RollbarDotNet.Tests/Builder/PersonBuilderTests.cs
rename to RollbarDotNet.Tests/Builder/PersonBuilderTests.cs
index 4939506..db5221d 100644
--- a/test/RollbarDotNet.Tests/Builder/PersonBuilderTests.cs
+++ b/RollbarDotNet.Tests/Builder/PersonBuilderTests.cs
@@ -11,9 +11,9 @@ public class PersonBuilderTests
{
public PersonBuilderTests()
{
- this._contextAccessor = new Mock();
- this._sut = new PersonBuilder(this._contextAccessor.Object);
- this._payload = new Payload();
+ _contextAccessor = new Mock();
+ _sut = new PersonBuilder(_contextAccessor.Object);
+ _payload = new Payload();
}
private readonly Mock _contextAccessor;
@@ -23,29 +23,29 @@ public PersonBuilderTests()
[Fact]
public void Execute_NoPrincipal_ShouldSetEmptyPerson()
{
- this._contextAccessor.Setup(accessor => accessor.HttpContext.User).Returns((ClaimsPrincipal) null);
+ _contextAccessor.Setup(accessor => accessor.HttpContext.User).Returns((ClaimsPrincipal)null);
- this._sut.Execute(this._payload);
+ _sut.Execute(_payload);
- var person = this._payload.Data.Person;
- Assert.Equal(true, string.IsNullOrEmpty(person.Id));
- Assert.Equal(true, string.IsNullOrEmpty(person.Email));
- Assert.Equal(true, string.IsNullOrEmpty(person.Username));
+ var person = _payload.Data.Person;
+ Assert.True(string.IsNullOrEmpty(person.Id));
+ Assert.True(string.IsNullOrEmpty(person.Email));
+ Assert.True(string.IsNullOrEmpty(person.Username));
}
[Fact]
public void Execute_PrincipalWithEmail_ShouldSetEmail()
{
const string expected = "email";
- this._contextAccessor.Setup(accessor => accessor.HttpContext.User)
+ _contextAccessor.Setup(accessor => accessor.HttpContext.User)
.Returns(new ClaimsPrincipal(new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.Email, expected)
})));
- this._sut.Execute(this._payload);
+ _sut.Execute(_payload);
- var person = this._payload.Data.Person;
+ var person = _payload.Data.Person;
Assert.Equal(expected, person.Email);
}
@@ -53,15 +53,15 @@ public void Execute_PrincipalWithEmail_ShouldSetEmail()
public void Execute_PrincipalWithId_ShouldSetId()
{
const string expected = "id";
- this._contextAccessor.Setup(accessor => accessor.HttpContext.User)
+ _contextAccessor.Setup(accessor => accessor.HttpContext.User)
.Returns(new ClaimsPrincipal(new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.NameIdentifier, expected)
})));
- this._sut.Execute(this._payload);
+ _sut.Execute(_payload);
- var person = this._payload.Data.Person;
+ var person = _payload.Data.Person;
Assert.Equal(expected, person.Id);
}
@@ -69,36 +69,36 @@ public void Execute_PrincipalWithId_ShouldSetId()
public void Execute_PrincipalWithName_ShouldSetName()
{
const string expected = "name";
- this._contextAccessor.Setup(accessor => accessor.HttpContext.User.Identity.Name).Returns(expected);
+ _contextAccessor.Setup(accessor => accessor.HttpContext.User.Identity.Name).Returns(expected);
- this._sut.Execute(this._payload);
+ _sut.Execute(_payload);
- var person = this._payload.Data.Person;
+ var person = _payload.Data.Person;
Assert.Equal(expected, person.Username);
}
[Fact]
public void Execute_PrincipalWithoutEmail_ShouldSetEmailToEmpty()
{
- this._contextAccessor.Setup(accessor => accessor.HttpContext.User)
+ _contextAccessor.Setup(accessor => accessor.HttpContext.User)
.Returns(new ClaimsPrincipal(new ClaimsIdentity()));
- this._sut.Execute(this._payload);
+ _sut.Execute(_payload);
- var person = this._payload.Data.Person;
- Assert.Equal(true, string.IsNullOrEmpty(person.Email));
+ var person = _payload.Data.Person;
+ Assert.True(string.IsNullOrEmpty(person.Email));
}
[Fact]
public void Execute_PrincipalWithoutId_ShouldSetIdToEmpty()
{
- this._contextAccessor.Setup(accessor => accessor.HttpContext.User)
+ _contextAccessor.Setup(accessor => accessor.HttpContext.User)
.Returns(new ClaimsPrincipal(new ClaimsIdentity()));
- this._sut.Execute(this._payload);
+ _sut.Execute(_payload);
- var person = this._payload.Data.Person;
- Assert.Equal(true, string.IsNullOrEmpty(person.Id));
+ var person = _payload.Data.Person;
+ Assert.True(string.IsNullOrEmpty(person.Id));
}
}
}
\ No newline at end of file
diff --git a/test/RollbarDotNet.Tests/Builder/RequestBuilderTests.cs b/RollbarDotNet.Tests/Builder/RequestBuilderTests.cs
similarity index 77%
rename from test/RollbarDotNet.Tests/Builder/RequestBuilderTests.cs
rename to RollbarDotNet.Tests/Builder/RequestBuilderTests.cs
index bcea1fe..1bd1d0a 100644
--- a/test/RollbarDotNet.Tests/Builder/RequestBuilderTests.cs
+++ b/RollbarDotNet.Tests/Builder/RequestBuilderTests.cs
@@ -28,11 +28,11 @@ public Mock CreateIHttpContextAccessor(string method)
httpContextAccessorMock.Setup(h => h.HttpContext.Request.Method).Returns(method);
httpContextAccessorMock.Setup(h => h.HttpContext.Features.Get().RemoteIpAddress)
.Returns(IPAddress.Loopback);
- httpContextAccessorMock.Setup(h => h.HttpContext.Request.Headers).Returns(this.GenerateHeaderDictionary);
- httpContextAccessorMock.Setup(h => h.HttpContext.Request.Query).Returns(this.GenerateQueryCollection);
+ httpContextAccessorMock.Setup(h => h.HttpContext.Request.Headers).Returns(GenerateHeaderDictionary);
+ httpContextAccessorMock.Setup(h => h.HttpContext.Request.Query).Returns(GenerateQueryCollection);
httpContextAccessorMock.Setup(h => h.HttpContext.Request.HasFormContentType).Returns(true);
- httpContextAccessorMock.Setup(h => h.HttpContext.Request.Form).Returns(this.GenerateFormCollection);
- httpContextAccessorMock.Setup(h => h.HttpContext.Request.Cookies).Returns(this.GenerateCookieCollection);
+ httpContextAccessorMock.Setup(h => h.HttpContext.Request.Form).Returns(GenerateFormCollection);
+ httpContextAccessorMock.Setup(h => h.HttpContext.Request.Cookies).Returns(GenerateCookieCollection);
httpContextAccessorMock.Setup(h => h.HttpContext.Request.QueryString)
.Returns(new QueryString("?query=test&blacklist=here"));
return httpContextAccessorMock;
@@ -48,8 +48,8 @@ protected IBlacklistCollection GenerateBacklistCollection(bool enableBlacklist =
protected Payload GeneratePayload(bool enableBlacklist = false, string method = "GET")
{
- var requestBuilder = new RequestBuilder(this.GenerateBacklistCollection(enableBlacklist),
- this.CreateIHttpContextAccessor(method).Object);
+ var requestBuilder = new RequestBuilder(GenerateBacklistCollection(enableBlacklist),
+ CreateIHttpContextAccessor(method).Object);
var payload = new Payload();
requestBuilder.Execute(payload);
return payload;
@@ -60,7 +60,7 @@ protected IHeaderDictionary GenerateHeaderDictionary()
var headerDictionaryMock = new Mock();
headerDictionaryMock
.Setup(h => h.GetEnumerator())
- .Returns(this.GenerateStringValueEnumerator());
+ .Returns(GenerateStringValueEnumerator());
return headerDictionaryMock.Object;
}
@@ -68,7 +68,7 @@ protected IRequestCookieCollection GenerateCookieCollection()
{
var cookieCollectionMock = new Mock();
cookieCollectionMock.Setup(h => h.GetEnumerator())
- .Returns(this.GenerateStringEnumerator());
+ .Returns(GenerateStringEnumerator());
return cookieCollectionMock.Object;
}
@@ -76,7 +76,7 @@ protected IQueryCollection GenerateQueryCollection()
{
var queryCollectionMock = new Mock();
queryCollectionMock.Setup(h => h.GetEnumerator())
- .Returns(this.GenerateStringValueEnumerator());
+ .Returns(GenerateStringValueEnumerator());
return queryCollectionMock.Object;
}
@@ -84,7 +84,7 @@ protected IFormCollection GenerateFormCollection()
{
var formCollectionMock = new Mock();
formCollectionMock.Setup(h => h.GetEnumerator())
- .Returns(this.GenerateStringValueEnumerator());
+ .Returns(GenerateStringValueEnumerator());
return formCollectionMock.Object;
}
@@ -109,7 +109,7 @@ protected IEnumerator> GenerateStringValueEnu
[Fact]
public void Blacklists_Payload_Cookies()
{
- var cookies = this.GeneratePayload(true)?.Data?.Request?.Cookies;
+ var cookies = GeneratePayload(true)?.Data?.Request?.Cookies;
Assert.True(cookies.ContainsKey("blacklist"));
Assert.Equal("**********", cookies["blacklist"]);
}
@@ -117,7 +117,7 @@ public void Blacklists_Payload_Cookies()
[Fact]
public void Blacklists_Payload_Headers()
{
- var headers = this.GeneratePayload(true)?.Data?.Request?.Headers;
+ var headers = GeneratePayload(true)?.Data?.Request?.Headers;
Assert.True(headers.ContainsKey("blacklist"));
Assert.Equal("**********", headers["blacklist"]);
}
@@ -125,7 +125,7 @@ public void Blacklists_Payload_Headers()
[Fact]
public void Blacklists_Payload_Query_Get()
{
- var query = this.GeneratePayload(true)?.Data?.Request?.Get;
+ var query = GeneratePayload(true)?.Data?.Request?.Get;
Assert.True(query.ContainsKey("blacklist"));
Assert.Equal("**********", query["blacklist"]);
}
@@ -133,7 +133,7 @@ public void Blacklists_Payload_Query_Get()
[Fact]
public void Blacklists_Payload_Query_Post()
{
- var query = this.GeneratePayload(true, "POST")?.Data?.Request?.Post;
+ var query = GeneratePayload(true, "POST")?.Data?.Request?.Post;
Assert.True(query.ContainsKey("blacklist"));
Assert.Equal("**********", query["blacklist"]);
}
@@ -141,7 +141,7 @@ public void Blacklists_Payload_Query_Post()
[Fact]
public void Blacklists_Payload_QueryString()
{
- var queryString = this.GeneratePayload(true)?.Data?.Request?.QueryString;
+ var queryString = GeneratePayload(true)?.Data?.Request?.QueryString;
Assert.Equal("?query=test&blacklist=**********", queryString);
}
@@ -153,11 +153,11 @@ public void Blacklists_Payload_QueryString()
[Fact]
public void Bug_ThrowsIncorrectContentType()
{
- var mock = this.CreateIHttpContextAccessor("POST");
+ var mock = CreateIHttpContextAccessor("POST");
mock.Setup(h => h.HttpContext.Request.HasFormContentType).Returns(false);
mock.Setup(h => h.HttpContext.Request.Form)
.Throws(new InvalidOperationException("Incorrect Content-Type: application/json; charset=UTF-8"));
- var requestBuilder = new RequestBuilder(this.GenerateBacklistCollection(), mock.Object);
+ var requestBuilder = new RequestBuilder(GenerateBacklistCollection(), mock.Object);
var payload = new Payload();
requestBuilder.Execute(payload);
}
@@ -165,56 +165,56 @@ public void Bug_ThrowsIncorrectContentType()
[Fact]
public void Builds_Payload_Cookies()
{
- var query = this.GeneratePayload()?.Data?.Request?.Cookies;
- Assert.Equal(this.DefaultDictionary, query);
+ var query = GeneratePayload()?.Data?.Request?.Cookies;
+ Assert.Equal(DefaultDictionary, query);
}
[Fact]
public void Builds_Payload_Headers()
{
- var headers = this.GeneratePayload()?.Data?.Request?.Headers;
- Assert.Equal(this.DefaultDictionary, headers);
+ var headers = GeneratePayload()?.Data?.Request?.Headers;
+ Assert.Equal(DefaultDictionary, headers);
}
[Fact]
public void Builds_Payload_Method()
{
- var payload = this.GeneratePayload();
+ var payload = GeneratePayload();
Assert.Equal("GET", payload.Data?.Request?.Method);
}
[Fact]
public void Builds_Payload_Query_Get()
{
- var query = this.GeneratePayload()?.Data?.Request?.Get;
- Assert.Equal(this.DefaultDictionary, query);
+ var query = GeneratePayload()?.Data?.Request?.Get;
+ Assert.Equal(DefaultDictionary, query);
}
[Fact]
public void Builds_Payload_Query_Post()
{
- var query = this.GeneratePayload(false, "POST")?.Data?.Request?.Post;
- Assert.Equal(this.DefaultDictionary, query);
+ var query = GeneratePayload(false, "POST")?.Data?.Request?.Post;
+ Assert.Equal(DefaultDictionary, query);
}
[Fact]
public void Builds_Payload_QueryString()
{
- var queryString = this.GeneratePayload()?.Data?.Request?.QueryString;
+ var queryString = GeneratePayload()?.Data?.Request?.QueryString;
Assert.Equal("?query=test&blacklist=here", queryString);
}
[Fact]
public void Builds_Payload_Url()
{
- var payload = this.GeneratePayload();
+ var payload = GeneratePayload();
Assert.Equal("http://my.test.domain/request/url/here.txt", payload.Data?.Request?.Url);
}
[Fact]
public void Builds_Payload_UserIp()
{
- var payload = this.GeneratePayload();
+ var payload = GeneratePayload();
Assert.Equal(IPAddress.Loopback.ToString(), payload.Data?.Request?.UserIp);
}
}
diff --git a/test/RollbarDotNet.Tests/Builder/ServerBuilderTests.cs b/RollbarDotNet.Tests/Builder/ServerBuilderTests.cs
similarity index 100%
rename from test/RollbarDotNet.Tests/Builder/ServerBuilderTests.cs
rename to RollbarDotNet.Tests/Builder/ServerBuilderTests.cs
diff --git a/RollbarDotNet.Tests/Core/ExcpetionHandlerMiddlewareTests.cs b/RollbarDotNet.Tests/Core/ExcpetionHandlerMiddlewareTests.cs
new file mode 100644
index 0000000..95298e3
--- /dev/null
+++ b/RollbarDotNet.Tests/Core/ExcpetionHandlerMiddlewareTests.cs
@@ -0,0 +1,57 @@
+namespace RollbarDotNet.Tests.Core
+{
+ using System;
+ using System.Threading.Tasks;
+ using Microsoft.AspNetCore.Http;
+ using Microsoft.Extensions.Options;
+ using Moq;
+ using RollbarDotNet.Builder;
+ using RollbarDotNet.Configuration;
+ using RollbarDotNet.Core;
+ using Xunit;
+
+ public class ExceptionHandlerMiddlewareTests
+ {
+
+ [Fact]
+ public async Task OnlyLogsOnce()
+ {
+ var uuid = string.Empty;
+ var optionsMock = new Mock>();
+ var rollbarClientMock = new Mock(optionsMock.Object);
+ rollbarClientMock.SetupSequence(m => m.Send(It.IsAny()))
+ .Returns(() => ReturnItem("test"))
+ .Returns(() => ReturnItem("fail"));
+ var httpContextMock = new Mock();
+ httpContextMock
+ .Setup(h => h.Features.Set(It.IsAny()));
+ var rollbar = new Rollbar(new IBuilder[] { }, new IExceptionBuilder[] { }, rollbarClientMock.Object);
+ var middleware = new ExceptionHandlerMiddleware(context =>
+ {
+ try
+ {
+ throw new Exception("Middleware tests");
+ }
+ catch (Exception exception)
+ {
+ rollbar.SendException(exception).Wait();
+ throw;
+ }
+ });
+ await Assert.ThrowsAsync(async () => await middleware.Invoke(httpContextMock.Object, rollbar));
+ rollbarClientMock.Verify(m => m.Send(It.IsAny()), Times.Once());
+ httpContextMock.Verify(m => m.Features.Set(It.Is(f => f.Uuid == "test")));
+ }
+
+ private Task ReturnItem(string uuid)
+ {
+ return Task.FromResult(new Payloads.Response
+ {
+ Result = new Payloads.Result
+ {
+ Uuid = uuid
+ }
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/RollbarDotNet.Tests/DependencyInjection/WebDependencyInjectionTests.cs b/RollbarDotNet.Tests/DependencyInjection/WebDependencyInjectionTests.cs
similarity index 74%
rename from test/RollbarDotNet.Tests/DependencyInjection/WebDependencyInjectionTests.cs
rename to RollbarDotNet.Tests/DependencyInjection/WebDependencyInjectionTests.cs
index b76cb76..afd39b4 100644
--- a/test/RollbarDotNet.Tests/DependencyInjection/WebDependencyInjectionTests.cs
+++ b/RollbarDotNet.Tests/DependencyInjection/WebDependencyInjectionTests.cs
@@ -3,11 +3,11 @@
using System;
using System.Threading.Tasks;
using Configuration;
- using Core;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Moq;
+ using RollbarDotNet.Core;
using Xunit;
public class WebDependencyInjectionTests
@@ -25,9 +25,9 @@ public WebDependencyInjectionTests()
o.Environment = "Testing";
});
- this.Services = services;
- this.ServiceProvider = this.Services.BuildServiceProvider();
- this.Rollbar = this.ServiceProvider.GetService();
+ Services = services;
+ ServiceProvider = Services.BuildServiceProvider();
+ Rollbar = ServiceProvider.GetService();
}
protected IServiceCollection Services { get; set; }
@@ -39,14 +39,14 @@ public WebDependencyInjectionTests()
[Fact]
public async Task DisabledRollbar()
{
- var options = this.ServiceProvider.GetService>().Value;
- this.Services.Configure(o =>
+ var options = ServiceProvider.GetService>().Value;
+ Services.Configure(o =>
{
o.AccessToken = options.AccessToken;
o.Disabled = true;
o.Environment = options.Environment;
});
- var serviceProvider = this.Services.BuildServiceProvider();
+ var serviceProvider = Services.BuildServiceProvider();
var rollbar = serviceProvider.GetService();
var response = await rollbar.SendMessage(RollbarLevel.Debug, "Hello");
Assert.Null(response.Result.Uuid);
@@ -55,19 +55,21 @@ public async Task DisabledRollbar()
[Fact]
public async Task SuccessfullyReportMessage()
{
- var response = await this.Rollbar.SendMessage("Hello");
+ var response = await Rollbar.SendMessage("Hello");
Assert.False(string.IsNullOrEmpty(response.Result.Uuid));
}
[Fact]
public async Task SuccessfullyReportMessageWithLevel()
{
- var response = await this.Rollbar.SendMessage(RollbarLevel.Debug, "Hello");
+ var response = await Rollbar.SendMessage(RollbarLevel.Debug, "Hello");
Assert.False(string.IsNullOrEmpty(response.Result.Uuid));
}
- [Fact]
- public async Task SucessfullyReportError()
+ [Theory]
+ [InlineData(null)]
+ [InlineData("Test Message For Exception")]
+ public async Task SuccessfullyReportError(string message)
{
try
{
@@ -82,7 +84,7 @@ public async Task SucessfullyReportError()
}
catch (Exception exception)
{
- var response = await this.Rollbar.SendException(exception);
+ var response = await Rollbar.SendException(exception, message);
Assert.False(string.IsNullOrEmpty(response.Result.Uuid));
}
}
diff --git a/RollbarDotNet.Tests/Kestrel/KestrelTests.cs b/RollbarDotNet.Tests/Kestrel/KestrelTests.cs
new file mode 100644
index 0000000..f776383
--- /dev/null
+++ b/RollbarDotNet.Tests/Kestrel/KestrelTests.cs
@@ -0,0 +1,55 @@
+namespace RollbarDotNet.Tests.Kestrel
+{
+ using System;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.AspNetCore.Builder;
+ using Microsoft.AspNetCore.Hosting;
+ using Microsoft.AspNetCore.Hosting.Server;
+ using Microsoft.AspNetCore.Server.Kestrel.Core;
+ using Microsoft.Extensions.DependencyInjection;
+ using Microsoft.Extensions.Logging;
+ using Moq;
+ using RollbarDotNet.Core;
+ using RollbarDotNet.Logger;
+ using Xunit;
+
+ public class KestrelTests
+ {
+ public KestrelTests()
+ {
+ RollbarMock = new Mock(null, null, null);
+ RollbarMock.Setup(m => m.SendException(It.IsAny(), It.IsAny())).Returns(() => Task.FromResult(null));
+ RollbarMock.Setup(m => m.SendMessage(It.IsAny(), It.IsAny())).Returns(() => Task.FromResult(null));
+ }
+
+ protected Mock RollbarMock { get; set; }
+
+ [Fact]
+ public async Task CanAddRollbarDotNetLogger()
+ {
+ var webHost = CreateBuilder()
+ .ConfigureServices(services =>
+ {
+ services.AddLogging().AddRollbar();
+ })
+ .Configure(app =>
+ {
+ app.UseRollbarExceptionHandler();
+ var loggerFactory = app.ApplicationServices
+ .GetRequiredService();
+ loggerFactory.AddRollbarDotNetLogger(app.ApplicationServices);
+ })
+ .Build();
+ await webHost.StartAsync();
+ await webHost.StopAsync();
+ }
+
+ private IWebHostBuilder CreateBuilder() => new WebHostBuilder()
+ .UseDefaultServiceProvider(options =>
+ {
+ options.ValidateScopes = true;
+ })
+ .UseKestrel();
+ }
+}
\ No newline at end of file
diff --git a/RollbarDotNet.Tests/Kestrel/Startup.cs b/RollbarDotNet.Tests/Kestrel/Startup.cs
new file mode 100644
index 0000000..cec1268
--- /dev/null
+++ b/RollbarDotNet.Tests/Kestrel/Startup.cs
@@ -0,0 +1,33 @@
+namespace RollbarDotNet.Tests.Kestrel
+{
+ using Microsoft.AspNetCore.Builder;
+ using Microsoft.Extensions.DependencyInjection;
+ using RollbarDotNet.Core;
+
+ public class Startup
+ {
+
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services
+ .AddRollbarWeb()
+ .AddControllers();
+ }
+
+ public void Configure(IApplicationBuilder app)
+ {
+ app
+ .UseForwardedHeaders()
+ .UseHttpsRedirection()
+ .UseRouting()
+ .UseCors()
+ .UseAuthentication()
+ .UseAuthorization()
+ .UseDefaultFiles()
+ .UseEndpoints(endpoints =>
+ {
+ endpoints.MapControllers();
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/RollbarDotNet.Tests/Logger/RollbarDotNetLoggerTests.cs b/RollbarDotNet.Tests/Logger/RollbarDotNetLoggerTests.cs
similarity index 69%
rename from test/RollbarDotNet.Tests/Logger/RollbarDotNetLoggerTests.cs
rename to RollbarDotNet.Tests/Logger/RollbarDotNetLoggerTests.cs
index 87dee8b..5b4bf77 100644
--- a/test/RollbarDotNet.Tests/Logger/RollbarDotNetLoggerTests.cs
+++ b/RollbarDotNet.Tests/Logger/RollbarDotNetLoggerTests.cs
@@ -3,12 +3,7 @@ namespace RollbarDotNet.Tests.Logger
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
- using Configuration;
- using Core;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
using Moq;
using RollbarDotNet.Logger;
using Xunit;
@@ -17,10 +12,10 @@ public class RollbarDotNetLoggerTests
{
public RollbarDotNetLoggerTests()
{
- this.RollbarMock = new Mock(null, null, null);
- this.RollbarMock.Setup(m => m.SendException(It.IsAny(), It.IsAny())).Returns(() => Task.FromResult(null));
- this.RollbarMock.Setup(m => m.SendMessage(It.IsAny(), It.IsAny())).Returns(() => Task.FromResult(null));
- this.Logger = new RollbarDotNetLogger(this.RollbarMock.Object);
+ RollbarMock = new Mock(null, null, null);
+ RollbarMock.Setup(m => m.SendException(It.IsAny(), It.IsAny())).Returns(() => Task.FromResult(null));
+ RollbarMock.Setup(m => m.SendMessage(It.IsAny(), It.IsAny())).Returns(() => Task.FromResult(null));
+ Logger = new RollbarDotNetLogger(RollbarMock.Object);
}
protected Mock RollbarMock { get; set; }
@@ -36,40 +31,40 @@ public RollbarDotNetLoggerTests()
[InlineData(LogLevel.None, false)]
public void IsEnabled_Correctly(LogLevel logLevel, bool isEnabled)
{
- Assert.Equal(isEnabled, this.Logger.IsEnabled(logLevel));
+ Assert.Equal(isEnabled, Logger.IsEnabled(logLevel));
}
[Fact]
public void BeginScope_ReturnsNull()
{
- Assert.Null(this.Logger.BeginScope(null));
+ Assert.Null(Logger.BeginScope(null));
}
[Theory]
[MemberData(nameof(Logs))]
public void Log_SendsExceptionIfPassed(LogLevel logLevel, RollbarLevel rollbarLevel, Exception ex, bool shouldSendException, bool shouldSendMessage)
{
- this.Logger.Log(logLevel, 0, (string)null, ex, (s, e) => string.Empty);
- RollbarMock.Verify(r => r.SendException(rollbarLevel, ex), Times.Exactly(shouldSendException ? 1 : 0));
+ Logger.Log(logLevel, 0, (string)null, ex, (s, e) => string.Empty);
+ RollbarMock.Verify(r => r.SendException(rollbarLevel, ex, It.IsAny()), Times.Exactly(shouldSendException ? 1 : 0));
RollbarMock.Verify(r => r.SendMessage(rollbarLevel, It.IsAny()), Times.Exactly(shouldSendMessage ? 1 : 0));
}
public static IEnumerable