Skip to content

Commit 17aeb93

Browse files
committed
Upgrades MudBlazor and modernizes C# syntax
Updates MudBlazor to version 8.x, adapting client-side components to new API changes for dialog instances and system dark mode detection. Adopts C# 12 features, including primary constructors for controllers and test fixtures, and collection expressions for concise initialization. Applies the `sealed` modifier to record types for enhanced immutability. Enhances Dependabot configuration by grouping GitHub Actions for better management and updates the ReportGenerator GitHub Action.
1 parent 10e5154 commit 17aeb93

File tree

10 files changed

+28
-38
lines changed

10 files changed

+28
-38
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ updates:
99
directory: "/" # Location of package manifests
1010
schedule:
1111
interval: "weekly"
12+
groups:
13+
github-actions:
14+
patterns:
15+
- "*"

.github/workflows/main_pointerstar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: dotnet test --configuration Release --no-build --collect:"XPlat Code Coverage" --results-directory ./coverage
3636

3737
- name: ReportGenerator
38-
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.18
38+
uses: danielpalme/ReportGenerator-GitHub-Action@5.5.0
3939
with:
4040
reports: coverage/**/coverage.cobertura.xml
4141
targetdir: coveragereport

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
3232
<PackageVersion Include="Moq" Version="4.20.72" />
3333
<PackageVersion Include="Moq.AutoMock" Version="3.5.0" />
34-
<PackageVersion Include="MudBlazor" Version="7.15.0" />
34+
<PackageVersion Include="MudBlazor" Version="8.14.0" />
3535
<PackageVersion Include="Polly" Version="8.5.2" />
3636
<PackageVersion Include="QRCoder" Version="1.6.0" />
3737
<PackageVersion Include="Toolbelt.Blazor.PWA.Updater" Version="3.0.1" />

PointerStar/Client/Components/UserDialog.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
@code {
3838
[CascadingParameter]
39-
private MudDialogInstance? MudDialog { get; set; }
39+
private IMudDialogInstance? MudDialog { get; set; }
4040
[Parameter]
4141
public string? RoomId { get; set; }
4242
[Parameter]

PointerStar/Client/Shared/MainLayout.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
{
2727
if (firstRender && _mudThemeProvider is { } themeProvider)
2828
{
29-
_isDarkMode = await themeProvider.GetSystemPreference();
30-
await themeProvider.WatchSystemPreference(OnSystemPreferenceChanged);
29+
_isDarkMode = await themeProvider.GetSystemDarkModeAsync();
30+
await themeProvider.WatchSystemDarkModeAsync(OnSystemPreferenceChanged);
3131
StateHasChanged();
3232
}
3333
}

PointerStar/Server/Controllers/RoomController.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using HashidsNet;
1+
using HashidsNet;
22
using Microsoft.AspNetCore.Mvc;
33
using PointerStar.Server.Room;
44
using PointerStar.Shared;
@@ -7,18 +7,11 @@ namespace PointerStar.Server.Controllers;
77

88
[ApiController]
99
[Route("api/[controller]")]
10-
public class RoomController : ControllerBase
10+
public class RoomController(Hashids hashIds, IRoomManager roomManager) : ControllerBase
1111
{
1212
private static readonly Random Random = new();
13-
private Hashids HashIds { get; }
14-
private IRoomManager RoomManager { get; }
15-
16-
public RoomController(Hashids hashIds, IRoomManager roomManager)
17-
{
18-
HashIds = hashIds ?? throw new ArgumentNullException(nameof(hashIds));
19-
RoomManager = roomManager ?? throw new ArgumentNullException(nameof(roomManager));
20-
}
21-
13+
private Hashids HashIds { get; } = hashIds ?? throw new ArgumentNullException(nameof(hashIds));
14+
private IRoomManager RoomManager { get; } = roomManager ?? throw new ArgumentNullException(nameof(roomManager));
2215

2316
[HttpGet("Generate")]
2417
public string Generate()

PointerStar/Shared/RoomState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace PointerStar.Shared;
22

3-
public record class RoomState(string RoomId, User[] Users)
3+
public sealed record class RoomState(string RoomId, User[] Users)
44
{
55
public IReadOnlyList<User> TeamMembers
66
=> [.. Users.Where(u => u.Role == Role.TeamMember)];
@@ -30,7 +30,7 @@ public IReadOnlyList<User> Observers
3030
public DateTime? VoteStartTime { get; init; }
3131
}
3232

33-
public record class User(Guid Id, string Name)
33+
public sealed record class User(Guid Id, string Name)
3434
{
3535
public const int MaxNameLength = 40;
3636

@@ -39,7 +39,7 @@ public record class User(Guid Id, string Name)
3939
public Role Role { get; init; } = Role.TeamMember;
4040
}
4141

42-
public record class Role(Guid Id, string Name)
42+
public sealed record class Role(Guid Id, string Name)
4343
{
4444
private static readonly Guid FacilitatorId = new("5fea7d71-fb62-405c-823c-09752c684bf0");
4545
private static readonly Guid TeamMemberId = new("116b133b-b16d-4a92-a3ce-ae53688e973c");

Tests/PointerStar.Client.Tests/ViewModels/RoomViewModelTests.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ public async Task ConnectToRoomAsync_WithExistingRoomState_UpdatesUser()
113113
viewModel.RoomId = "RoomId";
114114
await viewModel.OnInitializedAsync();
115115
viewModel.Name = "Foo";
116-
var roomState = new RoomState("roomId", new[] { new User(Guid.NewGuid(), "Test") });
117-
mocker.GetMock<IRoomHubConnection>().Raise(x => x.RoomStateUpdated += null, null, roomState);
116+
var roomState = new RoomState("roomId", [new User(Guid.NewGuid(), "Test")]);
117+
mocker.GetMock<IRoomHubConnection>().Raise(x => x.RoomStateUpdated += null, null!, roomState);
118118

119119
viewModel.Name = "New Name";
120120
viewModel.SelectedRoleId = Role.Observer.Id;
@@ -165,7 +165,7 @@ public async Task OnInitializedAsync_WithVoteStartTime_PeriodicallyNotifiesOfSta
165165
viewModel.RoomId = "RoomId";
166166
await viewModel.OnInitializedAsync();
167167
User facilitator = new(Guid.NewGuid(), "Facilitator") { Role = Role.Facilitator };
168-
RoomState roomState = new(Guid.NewGuid().ToString(), new[] { facilitator })
168+
RoomState roomState = new(Guid.NewGuid().ToString(), [facilitator])
169169
{
170170
VoteStartTime = DateTime.UtcNow.AddMinutes(-1)
171171
};
@@ -174,7 +174,7 @@ public async Task OnInitializedAsync_WithVoteStartTime_PeriodicallyNotifiesOfSta
174174

175175
//We expect a timer or similar to trigger state changes to make it appear as though the timer is updating
176176
ManualResetEventSlim mre = new(false);
177-
viewModel.PropertyChanged += (object? _, PropertyChangedEventArgs e) =>
177+
viewModel.PropertyChanged += (_, e) =>
178178
{
179179
mre.Set();
180180
};
@@ -272,7 +272,7 @@ public void IsFacilitator_WithFacilitatorUser_ReturnsTrue()
272272
{
273273
AutoMocker mocker = new();
274274
User facilitator = new(Guid.NewGuid(), "Facilitator") { Role = Role.Facilitator };
275-
RoomState roomState = new(Guid.NewGuid().ToString(), new[] { facilitator });
275+
RoomState roomState = new(Guid.NewGuid().ToString(), [facilitator]);
276276
RoomViewModel viewModel = mocker.CreateInstance<RoomViewModel>();
277277
viewModel.CurrentUserId = facilitator.Id;
278278
WithRoomState(mocker, roomState);
@@ -288,7 +288,7 @@ public void IsTeamMember_WithTeamMemberUser_ReturnsTrue()
288288
{
289289
AutoMocker mocker = new();
290290
User teamMember = new(Guid.NewGuid(), "Team Member") { Role = Role.TeamMember };
291-
RoomState roomState = new(Guid.NewGuid().ToString(), new[] { teamMember });
291+
RoomState roomState = new(Guid.NewGuid().ToString(), [teamMember]);
292292
RoomViewModel viewModel = mocker.CreateInstance<RoomViewModel>();
293293
viewModel.CurrentUserId = teamMember.Id;
294294
WithRoomState(mocker, roomState);
@@ -304,7 +304,7 @@ public void IsObserver_WithObserverUser_ReturnsTrue()
304304
{
305305
AutoMocker mocker = new();
306306
User observer = new(Guid.NewGuid(), "Observer") { Role = Role.Observer };
307-
RoomState roomState = new(Guid.NewGuid().ToString(), new[] { observer });
307+
RoomState roomState = new(Guid.NewGuid().ToString(), [observer]);
308308
RoomViewModel viewModel = mocker.CreateInstance<RoomViewModel>();
309309
viewModel.CurrentUserId = observer.Id;
310310
WithRoomState(mocker, roomState);
@@ -366,7 +366,7 @@ public async Task RemoveUserAsync_WithUserId_RemovesUser()
366366
AutoMocker mocker = new();
367367
mocker.Setup<IRoomHubConnection, bool>(x => x.IsConnected).Returns(true);
368368
User teamMember = new(Guid.NewGuid(), "Team Member") { Role = Role.TeamMember };
369-
RoomState roomState = new(Guid.NewGuid().ToString(), new[] { teamMember });
369+
RoomState roomState = new(Guid.NewGuid().ToString(), [teamMember]);
370370
RoomViewModel viewModel = mocker.CreateInstance<RoomViewModel>();
371371
WithRoomState(mocker, roomState);
372372

@@ -390,7 +390,5 @@ private static void WithUserDialog(AutoMocker mocker, string? name, Guid? select
390390
}
391391

392392
private static void WithRoomState(AutoMocker mocker, RoomState roomState)
393-
{
394-
mocker.GetMock<IRoomHubConnection>().Raise(x => x.RoomStateUpdated += null, null, roomState);
395-
}
393+
=> mocker.GetMock<IRoomHubConnection>().Raise(x => x.RoomStateUpdated += null, null!, roomState);
396394
}

Tests/PointerStar.Server.Tests/Controllers/RoomControllerTests.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
namespace PointerStar.Server.Tests.Controllers;
66

77
[ConstructorTests(typeof(RoomController))]
8-
public partial class RoomControllerTests : IClassFixture<WebApplicationFactory>
8+
public partial class RoomControllerTests(WebApplicationFactory factory) : IClassFixture<WebApplicationFactory>
99
{
10-
private WebApplicationFactory Factory { get; }
11-
12-
public RoomControllerTests(WebApplicationFactory factory)
13-
{
14-
Factory = factory;
15-
}
10+
private WebApplicationFactory Factory { get; } = factory;
1611

1712
[Fact]
1813
public async Task Generate_ReturnsUniqueStrings()

Tests/PointerStar.Server.Tests/WebApplicationFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace PointerStar.Server.Tests;
66

77
public class WebApplicationFactory : WebApplicationFactory<Program>
88
{
9-
private List<ServiceDescriptor> AdditionalServices { get; } = new();
9+
private List<ServiceDescriptor> AdditionalServices { get; } = [];
1010

1111
public void UseService<TInterface>(TInterface instance)
1212
where TInterface : notnull

0 commit comments

Comments
 (0)