Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix tests #6

Merged
merged 13 commits into from
Jul 17, 2024
21 changes: 21 additions & 0 deletions .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Format check
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
dotnet-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Format
working-directory: ./src
run: dotnet format --verify-no-changes

2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET
name: Build & Test check

on:
push:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
{
if (ErrorContent is not null)
{
builder.AddContent(1, ErrorContent(CurrentException));
builder.AddContent(1, ErrorContent(CurrentException));
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions src/Raygun.NetCore.Blazor/Models/BreadcrumbDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal record BreadcrumbDetails
/// <summary>
/// A custom value used to arbitrarily group this Breadcrumb.
/// </summary>
[JsonInclude]
[JsonInclude]
public string Category { get; set; }

/// <summary>
Expand All @@ -34,7 +34,7 @@ internal record BreadcrumbDetails
/// <summary>
/// Any custom data you want to record about application state when the Breadcrumb was recorded.
/// </summary>
[JsonInclude]
[JsonInclude]
public Dictionary<string, object> CustomData { get; set; }

/// <summary>
Expand All @@ -46,7 +46,7 @@ internal record BreadcrumbDetails
/// <summary>
/// The message you want to record for this Breadcrumb.
/// </summary>
[JsonInclude]
[JsonInclude]
public string Message { get; set; }

/// <summary>
Expand All @@ -70,7 +70,7 @@ internal record BreadcrumbDetails
/// <summary>
/// The <see cref="BreadcrumbType"> for the message. Defaults to <see cref="BreadcrumbType.Manual"/>.
/// </summary>
[JsonInclude]
[JsonInclude]
public BreadcrumbType Type { get; set; }

#endregion
Expand Down
6 changes: 1 addition & 5 deletions src/Raygun.NetCore.Blazor/Models/BrowserSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Raygun.NetCore.Blazor.Models
{

/// <summary>
/// Attributes about the Browser that are <i>highly unlikely</i> to change at runtime.
/// </summary>
Expand All @@ -13,7 +12,6 @@ namespace Raygun.NetCore.Blazor.Models
/// </remarks>
internal record BrowserSpecs
{

#region Private Members

private string calculatedBrowserVersion;
Expand Down Expand Up @@ -142,7 +140,5 @@ internal void ParseUserAgent()
}

#endregion

}

}
}
2 changes: 1 addition & 1 deletion src/Raygun.NetCore.Blazor/Models/BrowserUserAgentData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal record BrowserUserAgentData
///
/// </summary>
public string CalculatedOSVersion => $"{Platform} {(
Platform == "Windows" && Decimal.Parse(PlatformVersion?.Split(".")?[0] ?? "0") >= 13 ? "11" :
Platform == "Windows" && Decimal.Parse(PlatformVersion?.Split(".")?[0] ?? "0") >= 13 ? "11" :
Platform == "Windows" && Decimal.Parse(PlatformVersion?.Split(".")?[0] ?? "0") < 13 ? "10" :
PlatformVersion)}";

Expand Down
6 changes: 3 additions & 3 deletions src/Raygun.NetCore.Blazor/Models/ClientDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ internal record ClientDetails
/// <summary>
/// The name of this Client library.
/// </summary>
[JsonInclude]
[JsonInclude]
public string Name { get; set; }

/// <summary>
/// The version of this Client library.
/// </summary>
[JsonInclude]
[JsonInclude]
public string Version { get; set; }

/// <summary>
/// The URL for the repository this Client library is maintained in.
/// </summary>
[JsonInclude]
[JsonInclude]
public string ClientUrl { get; set; }

#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/Raygun.NetCore.Blazor/Models/EnvironmentDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ internal EnvironmentDetails(BrowserSpecs specs, BrowserStats stats)
ColorDepth = specs.ColorDepth;
CurrentOrientation = stats.Orientation.ToString();
DeviceManufacturer = !string.IsNullOrWhiteSpace(specs.DeviceManufacturer) ? specs.DeviceManufacturer : null;
DeviceModel = !string.IsNullOrWhiteSpace(specs.DeviceModel) ? specs.DeviceModel: null;
DeviceModel = !string.IsNullOrWhiteSpace(specs.DeviceModel) ? specs.DeviceModel : null;
DeviceName = !string.IsNullOrWhiteSpace(specs.DeviceName) ? specs.DeviceName : null; ;
Locale = specs.Locale;
OSVersion = !string.IsNullOrWhiteSpace(specs.UAHints?.CalculatedOSVersion) ? specs.UAHints.CalculatedOSVersion : specs.CalculatedOSVersion;
Platform = specs.UAHints.CalculatedPlatform ?? specs.Platform;
Platform = specs.UAHints?.CalculatedPlatform ?? specs.Platform;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IDE also displayed a warning here saying that UAHints could be null. One of the tests failed due to it being null too.

ProcessorCount = specs.ProcessorCount;
ResolutionScale = stats.DevicePixelRatio;
ScreenHeight = specs.ScreenHeight;
Expand Down
14 changes: 7 additions & 7 deletions src/Raygun.NetCore.Blazor/Models/ErrorDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ internal class ErrorDetails
/// <summary>
/// The name of the <see langword="class" /> the error was produced in.
/// </summary>
[JsonInclude]
[JsonInclude]
public string ClassName { get; set; }

/// <summary>
/// Data contained in the error object.
/// </summary>
[JsonInclude]
[JsonInclude]
public NonGeneric.IDictionary Data { get; set; }

/// <summary>
/// Details about the symbol files related to the error.
/// </summary>
[JsonInclude]
[JsonInclude]
public List<PEDebugDetails> Images { get; set; }

/// <summary>
///
/// </summary>
[JsonInclude]
[JsonInclude]
public ErrorDetails InnerError { get; set; }

/// <summary>
///
/// </summary>
[JsonInclude]
[JsonInclude]
public List<ErrorDetails> InnerErrors { get; set; }

/// <summary>
///
/// </summary>
[JsonInclude]
[JsonInclude]
public string Message { get; set; }

/// <summary>
Expand All @@ -58,7 +58,7 @@ internal class ErrorDetails
/// <remarks>
/// The first one in the list should be the highest on the stack
/// </remarks>
[JsonInclude]
[JsonInclude]
public List<StackTraceDetails> StackTrace { get; set; }

#endregion
Expand Down
16 changes: 8 additions & 8 deletions src/Raygun.NetCore.Blazor/Models/EventDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ internal record EventDetails
/// <summary>
/// A trail of breadcrumbs leading up to this event.
/// </summary>
[JsonInclude]
[JsonInclude]
public List<BreadcrumbDetails> Breadcrumbs { get; set; }

/// <summary>
/// Information about the client library you are using for talking to the Raygun API.
/// </summary>
[JsonInclude]
[JsonInclude]
public ClientDetails Client { get; set; }

/// <summary>
/// Information about the environment at the time of the event.
/// </summary>
[JsonInclude]
[JsonInclude]
public EnvironmentDetails Environment { get; set; }

/// <summary>
Expand All @@ -49,19 +49,19 @@ internal record EventDetails
/// <remarks>
/// Must be 1-100 chars, ideally the result of a hash function e.g MD5
/// </remarks>
[JsonInclude]
[JsonInclude]
public string GroupingKey { get; set; }

/// <summary>
/// The name of machine this event occurred on
/// </summary>
[JsonInclude]
[JsonInclude]
public string MachineName { get; set; }

/// <summary>
/// Information about the HTTP request being processed when the error occurred.
/// </summary>
[JsonInclude]
[JsonInclude]
public RequestDetails Request { get; set; }

/// <summary>
Expand All @@ -70,7 +70,7 @@ internal record EventDetails
/// <remarks>
/// These will be searchable and filterable on the dashboard.
/// </remarks>
[JsonInclude]
[JsonInclude]
public List<string> Tags { get; set; }

/// <summary>
Expand All @@ -85,7 +85,7 @@ internal record EventDetails
/// <remarks>
/// These will be searchable on the dashboard.
/// </remarks>
[JsonInclude]
[JsonInclude]
public Dictionary<string, string> UserCustomData { get; set; }

#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/Raygun.NetCore.Blazor/Models/RaygunRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal record RaygunRequest
public RequestQueueStatus QueueStatus { get; set; }

#endregion

#region Constructors

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Raygun.NetCore.Blazor/Models/RequestDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal record RequestDetails
/// The HTTP method used to request the URL (GET, POST, PUT, etc).
/// </summary>
[JsonInclude]
public HttpMethod HttpMethod { get; set; }
public string HttpMethod { get; set; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bit strange, not sure if it was a typo or on purpose. The JSON parser failed trying to convert this. The rest of the code did not complain after the change.


/// <summary>
/// The IP address of the client that initiated the request.
Expand Down
6 changes: 3 additions & 3 deletions src/Raygun.NetCore.Blazor/Models/StackTraceDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ internal class StackTraceDetails
/// <summary>
/// The name of the class this stack frame is in.
/// </summary>
[JsonInclude]
[JsonInclude]
public string ClassName { get; set; }

/// <summary>
/// The column of the file that this stack frame is in.
/// </summary>
[JsonInclude]
[JsonInclude]
public int ColumnNumber { get; set; }

/// <summary>
/// The name of the file this stack frame is in.
/// </summary>
[JsonInclude]
[JsonInclude]
public string FileName { get; set; }

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Raygun.NetCore.Blazor/RaygunBlazorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@
/// <code>
/// TBD
/// </code>
public void RecordBreadcrumb(string message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual, string category = null,
public void RecordBreadcrumb(string message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual, string category = null,
Dictionary<string, object> customData = null, string platform = "DotNet")
{
{
_breadcrumbs.Add(new BreadcrumbDetails(message, breadcrumbType, category, customData, platform));
}

Expand All @@ -148,7 +148,7 @@
/// <code>
/// TBD
/// </code>
public async Task RecordExceptionAsync(Exception ex, List<string>? tags = null, bool addUserDetails = false, Dictionary<string, string>? userCustomData = null,

Check warning on line 151 in src/Raygun.NetCore.Blazor/RaygunBlazorClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 151 in src/Raygun.NetCore.Blazor/RaygunBlazorClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
CancellationToken cancellationToken = default)
{
await InitializeAsync();
Expand Down
4 changes: 2 additions & 2 deletions src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/// A dynamic reference to the Raygun Blazor Script, so developers don't have to manually add a script file
/// to their index.html page.
/// </summary>
public IJSObjectReference? RaygunScriptReference { get; private set; }

Check warning on line 39 in src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

#endregion

Expand Down Expand Up @@ -98,7 +98,7 @@
/// <param name="customData"></param>
/// <returns></returns>
[JSInvokable]
public async ValueTask RecordJsBreadcrumb(string message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual,
public async ValueTask RecordJsBreadcrumb(string message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual,
string category = null, Dictionary<string, object> customData = null)
{
_breadcrumbAction.Invoke(message, breadcrumbType, category, customData, "JavaScript");
Expand All @@ -113,7 +113,7 @@
/// <param name="customData"></param>
/// <returns></returns>
[JSInvokable]
public async ValueTask RecordJsException(Exception exception, List<string>? tags = null, bool sendUserData = false, Dictionary<string, string>? customData = null)

Check warning on line 116 in src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 116 in src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
await _exceptionAction.Invoke(exception, tags, sendUserData, customData, CancellationToken.None);
}
Expand Down Expand Up @@ -145,7 +145,7 @@
/// <param name="breadcrumbAction"></param>
/// <param name="exceptionAction"></param>
internal async Task InitializeAsync(Func<ErrorEvent, Task> onUnhandledJsException,
Action<string, BreadcrumbType, string?, Dictionary<string, object>?, string?> breadcrumbAction,

Check warning on line 148 in src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 148 in src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 148 in src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
Func<Exception, List<string>?, bool, Dictionary<string, string>?, CancellationToken, Task> exceptionAction)
{
_breadcrumbAction = breadcrumbAction;
Expand All @@ -154,7 +154,7 @@
// RWM: We're going to register the Raygun script and get the BrowserSpecs first. The reason why is because if we
// handle JS errors & they start coming in before we're ready, then there will be wailing and gnashing of teeth.
RaygunScriptReference = await _jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Raygun.NetCore.Blazor/Raygun.NetCore.Blazor.js");

// RWM: Register the .NET reference with JS so that JS code can also manually create Bookmarks and report Exceptions.
await _jsRuntime.InvokeVoidAsync("window.raygunBlazor.initialize", _dotNetReference);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using CloudNimble.Breakdance.Blazor;
using Bunit;
using CloudNimble.Breakdance.Blazor;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Raygun4Net.Tests.Blazor.WebAssembly
namespace Raygun.NetCore.Tests.Blazor.WebAssembly
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a recommendation by the IDE, to match the namespace definition with the folder name.


/// <summary>
///
/// </summary>
[TestClass]
public class RaygunExceptionCatcherTests : BlazorBreakdanceTestBase
{

#region Test Lifecycle

[TestInitialize]
Expand All @@ -21,16 +20,12 @@ public void Setup()
{
services.AddRaygunBlazor(context.Configuration);
});
TestSetup();
TestSetup(JSRuntimeMode.Loose);
}

[TestCleanup]
public void TearDown() => TestTearDown();

#endregion



}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Raygun": {
"ApiKey": "APIKEY"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests failed to initialize because the appsettings.json was missing this key and so the init method threw an exception.

}
}
2 changes: 1 addition & 1 deletion src/Raygun.NetCore.Tests.Blazor/BreadcrumbDetailsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Breadcrumbs_NewInstance_MessageOverload()
bc.Timestamp.Should().BePositive();
bc.Message.Should().Be("Test");
bc.MethodName.Should().Be(nameof(Breadcrumbs_NewInstance_MessageOverload));
bc.LineNumber.Should().Be(25);
bc.LineNumber.Should().Be(38);
}

#endregion
Expand Down
Loading
Loading