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: #18 RaygunErrorBoundary tests #53

Merged
merged 16 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:

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

12 changes: 11 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '17'
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Restore workloads
working-directory: ./src
run: dotnet workload restore
- name: Restore dependencies
working-directory: ./src
run: dotnet restore
Expand Down
4 changes: 2 additions & 2 deletions src/Raygun.Blazor.Maui/Control/RaygunErrorBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class RaygunErrorBoundary : ErrorBoundary
///
/// </summary>
[Inject]
internal RaygunBlazorClient RaygunClient { get; set; }
required public RaygunBlazorClient RaygunClient { get; set; }

/// <summary>
///
/// </summary>
[Inject]
internal IOptions<RaygunSettings> RaygunSettings { get; set; }
required public IOptions<RaygunSettings> RaygunSettings { get; set; }

#endregion

Expand Down
6 changes: 4 additions & 2 deletions src/Raygun.Blazor.Maui/Raygun.Blazor.Maui.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks>net8.0-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">
$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
$(TargetFrameworks);net8.0-ios;net8.0-maccatalyst;net8.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('osx'))">
$(TargetFrameworks);net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following
this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
Expand Down
1 change: 0 additions & 1 deletion src/Raygun.Blazor.Server/Controls/RaygunErrorBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class RaygunErrorBoundary : ErrorBoundary
/// <returns></returns>
protected override async Task OnErrorAsync(Exception exception)
{
Console.WriteLine("OnErrorAsync");
TheRealAgentK marked this conversation as resolved.
Show resolved Hide resolved
if (!RaygunSettings.Value.CatchUnhandledExceptions) return;

await RaygunClient.RecordExceptionAsync(exception, null, ["UnhandledException", "Blazor", ".NET"]);
Expand Down
14 changes: 7 additions & 7 deletions src/Raygun.Blazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun.Tests.Blazor", "Raygun.Tests.Blazor\Raygun.Tests.Blazor.csproj", "{D21D30DD-3133-483E-ABF9-F1AA552B11B4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun.Tests.Blazor.WebAssembly", "Raygun.Tests.Blazor.WebAssembly\Raygun.Tests.Blazor.WebAssembly.csproj", "{A9A0782E-395E-413B-80E3-BE2C18E25ECB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun.Blazor.Server", "Raygun.Blazor.Server\Raygun.Blazor.Server.csproj", "{F05FD8B3-E379-4520-9008-013D0CD3C983}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun.Samples.Blazor.WebAssembly", "Raygun.Samples.Blazor.WebAssembly\Raygun.Samples.Blazor.WebAssembly.csproj", "{CDBE774B-4AEA-4277-9044-A9718C03CEF6}"
Expand All @@ -36,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun.Samples.Blazor.Maui"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun.Blazor.Maui", "Raygun.Blazor.Maui\Raygun.Blazor.Maui.csproj", "{D7F13D0C-4F1C-49D7-B3C0-BF9FE6C46E38}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raygun.Tests.Blazor.Server", "Raygun.Tests.Blazor.Server\Raygun.Tests.Blazor.Server.csproj", "{54C47781-5CD6-4C85-974B-A521DB03A1DB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -54,10 +54,6 @@ Global
{D21D30DD-3133-483E-ABF9-F1AA552B11B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D21D30DD-3133-483E-ABF9-F1AA552B11B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D21D30DD-3133-483E-ABF9-F1AA552B11B4}.Release|Any CPU.Build.0 = Release|Any CPU
{A9A0782E-395E-413B-80E3-BE2C18E25ECB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9A0782E-395E-413B-80E3-BE2C18E25ECB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9A0782E-395E-413B-80E3-BE2C18E25ECB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9A0782E-395E-413B-80E3-BE2C18E25ECB}.Release|Any CPU.Build.0 = Release|Any CPU
{F05FD8B3-E379-4520-9008-013D0CD3C983}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F05FD8B3-E379-4520-9008-013D0CD3C983}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F05FD8B3-E379-4520-9008-013D0CD3C983}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -80,6 +76,10 @@ Global
{D7F13D0C-4F1C-49D7-B3C0-BF9FE6C46E38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7F13D0C-4F1C-49D7-B3C0-BF9FE6C46E38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7F13D0C-4F1C-49D7-B3C0-BF9FE6C46E38}.Release|Any CPU.Build.0 = Release|Any CPU
{54C47781-5CD6-4C85-974B-A521DB03A1DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54C47781-5CD6-4C85-974B-A521DB03A1DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54C47781-5CD6-4C85-974B-A521DB03A1DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54C47781-5CD6-4C85-974B-A521DB03A1DB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -88,11 +88,11 @@ Global
{8A3CFEA0-2E8B-4C45-91A8-2FD075486B11} = {4DC8B2BE-3AB9-4068-BC72-F97B75716E85}
{AA9AC6CD-D344-42E7-908B-8252466CB26D} = {4DC8B2BE-3AB9-4068-BC72-F97B75716E85}
{D21D30DD-3133-483E-ABF9-F1AA552B11B4} = {B100EB75-8D39-4595-8B7E-8FF2B330273B}
{A9A0782E-395E-413B-80E3-BE2C18E25ECB} = {B100EB75-8D39-4595-8B7E-8FF2B330273B}
{F05FD8B3-E379-4520-9008-013D0CD3C983} = {4DC8B2BE-3AB9-4068-BC72-F97B75716E85}
{CDBE774B-4AEA-4277-9044-A9718C03CEF6} = {A27A5729-C507-433E-8A2B-DEB55C3B6B66}
{9511EF9F-566B-401C-A553-FD137A425C20} = {A27A5729-C507-433E-8A2B-DEB55C3B6B66}
{D7F13D0C-4F1C-49D7-B3C0-BF9FE6C46E38} = {4DC8B2BE-3AB9-4068-BC72-F97B75716E85}
{54C47781-5CD6-4C85-974B-A521DB03A1DB} = {B100EB75-8D39-4595-8B7E-8FF2B330273B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {07FC9E40-0B7C-4088-934B-9204C2719530}
Expand Down
2 changes: 1 addition & 1 deletion src/Raygun.Blazor/Models/BrowserSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Raygun.Blazor.Models
/// This exists because we need to parse some stuff from the browser to construct a proper <see cref="EnvironmentDetails" />
/// instance. Also the <see cref="EnvironmentDetails" /> is a hot mess of JavaScript serialization inconsistency.
/// </remarks>
internal record BrowserSpecs
public record BrowserSpecs
Copy link
Contributor Author

@miquelbeltran miquelbeltran Oct 4, 2024

Choose a reason for hiding this comment

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

Made public so it is accessible from the Raygun.Tests.Blazor.Server project

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the need to do that, but it kind of breaks encapsulation a bit for the same of the code being ore testable. I think that's a choice that can be made consciously, but are there other ways to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it, see 45d0423 (#53)

{
#region Private Members

Expand Down
2 changes: 1 addition & 1 deletion src/Raygun.Blazor/Models/BrowserStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// This exists because we need to parse some stuff from the browser to construct a proper <see cref="EnvironmentDetails" />
/// instance. Also the <see cref="EnvironmentDetails" /> has serialization needs for Raygun that don't align with JSInterop.
/// </remarks>
internal record BrowserStats
public record BrowserStats
{

#region Public Properties
Expand Down
2 changes: 1 addition & 1 deletion src/Raygun.Blazor/Models/BrowserUserAgentData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Raygun.Blazor.Models
/// Any value that is derived from the reported data is prefixed with the word "Calculated" to indicate
/// that it is not directly reported by the browser.
/// </remarks>
internal record BrowserUserAgentData
public record BrowserUserAgentData
{

#region Public Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public TimerBasedSendStrategy(TimeSpan? interval = null)
Start();
}

/// <summary>
/// Class destructor. Disposes the timer.
/// </summary>
~TimerBasedSendStrategy()
{
Dispose();
Expand Down
4 changes: 2 additions & 2 deletions src/Raygun.Samples.Blazor.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static MauiApp CreateMauiApp()
builder.Services.AddMauiBlazorWebView();

#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
builder.Logging.AddDebug();
builder.Services.AddBlazorWebViewDeveloperTools();
builder.Logging.AddDebug();
#endif

return builder.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net8.0-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">
$(TargetFrameworks);net8.0-ios;net8.0-maccatalyst;net8.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('osx'))">
$(TargetFrameworks);net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->

Expand Down
20 changes: 20 additions & 0 deletions src/Raygun.Tests.Blazor.Server/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="Raygun.Tests.Blazor.Server.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet @rendermode="InteractiveServer" />
</head>

<body>
<Routes @rendermode="InteractiveServer" />
<script src="_framework/blazor.web.js"></script>
</body>

</html>
20 changes: 20 additions & 0 deletions src/Raygun.Tests.Blazor.Server/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@using Raygun.Blazor.Server.Controls
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>

<article class="content px-4">
<RaygunErrorBoundary>
@Body
</RaygunErrorBoundary>
TheRealAgentK marked this conversation as resolved.
Show resolved Hide resolved
</article>
</main>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}

main {
flex: 1;
}

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}

.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}

.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}

.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}

.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}

@media (min-width: 641px) {
.page {
flex-direction: row;
}

.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}

.top-row {
position: sticky;
top: 0;
z-index: 1;
}

.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}

.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}

#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}

#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
18 changes: 18 additions & 0 deletions src/Raygun.Tests.Blazor.Server/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">Raygun.Tests.Blazor.Server</a>
</div>
</div>

<input type="checkbox" title="Navigation menu" class="navbar-toggler" />

<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> TestComponent
</NavLink>
</div>
</nav>
</div>

Loading