Skip to content

Commit 55a35f2

Browse files
committed
Updated BUnit classes
1 parent 868832e commit 55a35f2

28 files changed

Lines changed: 128 additions & 139 deletions

tests/AdminConsole.Tests/Components/BadgeTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using Bunit;
22
using Passwordless.AdminConsole.Components.Shared;
3-
using Passwordless.AdminConsole.TagHelpers;
43
using Xunit;
54
using Badge = Passwordless.AdminConsole.Components.Shared.Badge;
65

76
namespace Passwordless.AdminConsole.Tests.Components;
87

9-
public class BadgeTests : TestContext
8+
public class BadgeTests : BunitContext
109
{
1110
#region Class
1211
[Theory]
@@ -18,7 +17,7 @@ public class BadgeTests : TestContext
1817
public void Badge_Renders_WhiteText(ContextualStyles variant)
1918
{
2019
// Arrange
21-
var cut = RenderComponent<Badge>(parameters => parameters
20+
var cut = Render<Badge>(parameters => parameters
2221
.Add(p => p.Variant, variant));
2322

2423
// Act
@@ -42,7 +41,7 @@ public void Badge_Renders_WhiteText(ContextualStyles variant)
4241
public void Badge_Renders_ExpectedBackground_Variant(ContextualStyles variant, string expectedClass)
4342
{
4443
// Arrange
45-
var cut = RenderComponent<Badge>(parameters => parameters
44+
var cut = Render<Badge>(parameters => parameters
4645
.Add(p => p.Variant, variant));
4746

4847
// Act
@@ -58,7 +57,7 @@ public void Badge_Renders_ExpectedBackground_Variant(ContextualStyles variant, s
5857
public void Badge_Renders_ExpectedText()
5958
{
6059
// Arrange
61-
var cut = RenderComponent<Badge>(parameters => parameters
60+
var cut = Render<Badge>(parameters => parameters
6261
.Add(p => p.Message, "Active"));
6362
var span = cut.Find("span");
6463

tests/AdminConsole.Tests/Components/Pages/Account/MagicTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using Bunit;
22
using Microsoft.AspNetCore.Components;
3-
using Microsoft.AspNetCore.Http;
43
using Microsoft.AspNetCore.Http.HttpResults;
5-
using Microsoft.AspNetCore.Mvc;
6-
using Microsoft.AspNetCore.Mvc.Infrastructure;
74
using Microsoft.Extensions.DependencyInjection;
8-
using Microsoft.Extensions.Logging.Abstractions;
95
using Passwordless.AdminConsole.Components.Pages.Account;
106
using Passwordless.AdminConsole.Endpoints;
117
using Passwordless.AdminConsole.Identity;
@@ -15,7 +11,7 @@
1511

1612
namespace Passwordless.AdminConsole.Tests.Components.Pages.Account;
1713

18-
public class MagicTests : TestContext
14+
public class MagicTests : BunitContext
1915
{
2016
public MagicTests()
2117
{
@@ -58,7 +54,7 @@ public async Task Redirects_to_error_page_when_token_is_not_valid()
5854

5955
navigationManager.NavigateTo(redirectResult.Url);
6056

61-
var cut = this.RenderComponent<Magic>();
57+
var cut = this.Render<Magic>();
6258
Assert.NotNull(cut.Find("#invalid-magic-link-token-alert"));
6359
}
6460

tests/AdminConsole.Tests/Components/Pages/App/Credentials/UserTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Bunit;
22
using Bunit.TestDoubles;
3-
using Microsoft.AspNetCore.Http;
4-
using Microsoft.AspNetCore.Mvc.ViewFeatures;
53
using Microsoft.Extensions.DependencyInjection;
64
using Moq;
75
using Passwordless.AdminConsole.Components.Pages.App.Credentials;
@@ -10,7 +8,7 @@
108

119
namespace Passwordless.AdminConsole.Tests.Components.Pages.App.Credentials;
1210

13-
public class UserTests : TestContext
11+
public class UserTests : BunitContext
1412
{
1513
private readonly Mock<IScopedPasswordlessClient> _passwordlessClientMock = new();
1614

@@ -25,7 +23,7 @@ public UserTests()
2523
public void User_ShouldRender_UserIdInSummary()
2624
{
2725
// Arrange
28-
var actual = RenderComponent<User>(builder =>
26+
var actual = Render<User>(builder =>
2927
builder.Add(parameters => parameters.UserId, "123"));
3028

3129
// Assert
@@ -37,7 +35,7 @@ public void User_ShouldRender_UserIdInSummary()
3735
public void User_ShouldRender_CredentialsComponent()
3836
{
3937
// Arrange
40-
var actual = RenderComponent<User>(builder =>
38+
var actual = Render<User>(builder =>
4139
builder.Add(parameters => parameters.UserId, "123"));
4240

4341
// Assert

tests/AdminConsole.Tests/Components/Pages/App/LogTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using AutoFixture;
22
using Bunit;
3-
using Bunit.TestDoubles;
4-
using Microsoft.AspNetCore.Components;
53
using Microsoft.Extensions.DependencyInjection;
64
using Microsoft.Extensions.Logging;
75
using Moq;
@@ -14,7 +12,7 @@
1412

1513
namespace Passwordless.AdminConsole.Tests.Components.Pages.App;
1614

17-
public class LogTests : TestContext
15+
public class LogTests : BunitContext
1816
{
1917
private readonly Mock<ICurrentContext> _currentContextMock = new();
2018
private readonly Mock<IEventLogService> _eventLogServiceMock = new();
@@ -48,7 +46,7 @@ public void LogPage_DoesRendersEmptyTable_WhenEventsIsEmpty()
4846
.ReturnsAsync(expectedEvents);
4947

5048
// Act
51-
var cut = RenderComponent<Log>(p => p
49+
var cut = Render<Log>(p => p
5250
.Add(param => param.AppId, "myapp"));
5351

5452
// Assert

tests/AdminConsole.Tests/Components/Pages/App/ReportingComponents/TotalCredentialsCountChartTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Passwordless.AdminConsole.Tests.Components.Pages.App.ReportingComponents;
1111

12-
public class TotalCredentialsCountChartTests : TestContext
12+
public class TotalCredentialsCountChartTests : BunitContext
1313
{
1414
private readonly Mock<IHttpContextAccessor> _httpContextAccessorMock = new();
1515
private readonly Mock<IFileVersionProvider> _fileVersionProviderMock = new();
@@ -26,7 +26,7 @@ public TotalCredentialsCountChartTests()
2626
}
2727

2828
[Fact]
29-
public void RenderComponent_Renders_ExpectedId()
29+
public void Render_Renders_ExpectedId()
3030
{
3131
// Arrange
3232
var data = new List<PeriodicCredentialReportResponse>
@@ -37,7 +37,7 @@ public void RenderComponent_Renders_ExpectedId()
3737
new(new DateOnly(2024, 1, 5), 5, 10)
3838
}.AsEnumerable();
3939

40-
var cut = RenderComponent<TotalCredentialsCountChart>(parameters => parameters
40+
var cut = Render<TotalCredentialsCountChart>(parameters => parameters
4141
.Add(p => p.Data, data));
4242

4343
// Act

tests/AdminConsole.Tests/Components/Pages/App/ReportingComponents/TotalUsersCountChartTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Passwordless.AdminConsole.Tests.Components.Pages.App.ReportingComponents;
1111

12-
public class TotalUsersCountChartTests : TestContext
12+
public class TotalUsersCountChartTests : BunitContext
1313
{
1414
private readonly Mock<IHttpContextAccessor> _httpContextAccessorMock = new();
1515
private readonly Mock<IFileVersionProvider> _fileVersionProviderMock = new();
@@ -26,7 +26,7 @@ public TotalUsersCountChartTests()
2626
}
2727

2828
[Fact]
29-
public void RenderComponent_Renders_ExpectedId()
29+
public void Render_Renders_ExpectedId()
3030
{
3131
// Arrange
3232
var data = new List<PeriodicCredentialReportResponse>
@@ -37,7 +37,7 @@ public void RenderComponent_Renders_ExpectedId()
3737
new(new DateOnly(2024, 1, 5), 5, 10)
3838
}.AsEnumerable();
3939

40-
var cut = RenderComponent<TotalUsersCountChart>(parameters => parameters
40+
var cut = Render<TotalUsersCountChart>(parameters => parameters
4141
.Add(p => p.Data, data));
4242

4343
// Act

tests/AdminConsole.Tests/Components/Pages/App/Settings/AuthenticatorsTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using AutoFixture;
22
using Bunit;
33
using Bunit.TestDoubles;
4-
using Microsoft.AspNetCore.Components;
54
using Microsoft.Extensions.DependencyInjection;
65
using Moq;
76
using Passwordless.AdminConsole.Components.Pages.App.Settings;
@@ -15,7 +14,7 @@
1514

1615
namespace Passwordless.AdminConsole.Tests.Components.Pages.App.Settings;
1716

18-
public class AuthenticatorsTests : TestContext
17+
public class AuthenticatorsTests : BunitContext
1918
{
2019
private readonly Mock<ICurrentContext> _currentContextMock = new();
2120
private readonly Mock<IPasswordlessManagementClient> _passwordlessManagementClientMock = new();
@@ -54,7 +53,7 @@ public void AllowList_Renders_SortedAlphabetically()
5453
new(Guid.Parse("cb69481e-8ff7-4039-93ec-0a2729a154a8"), new DateTime(2024, 01, 01)),
5554
});
5655

57-
var cut = RenderComponent<Authenticators>();
56+
var cut = Render<Authenticators>();
5857

5958
// Act
6059

@@ -86,7 +85,7 @@ public void AllowList_Renders_Nothing_WhenAllowListEmpty()
8685
.ReturnsAsync(new List<ConfiguredAuthenticatorResponse>());
8786

8887
// Act
89-
var cut = RenderComponent<Authenticators>();
88+
var cut = Render<Authenticators>();
9089

9190
// Assert
9291
Assert.Throws<ElementNotFoundException>(() => cut.Find("div#allowlist"));
@@ -104,11 +103,11 @@ public void Authenticators_RedirectsTo_Settings_WhenAttestationIsNotAllowed()
104103
_passwordlessClientMock.Setup(x =>
105104
x.GetConfiguredAuthenticatorsAsync(It.Is<ConfiguredAuthenticatorRequest>(p => p.IsAllowed == true)))
106105
.ReturnsAsync(new List<ConfiguredAuthenticatorResponse>());
107-
var nav = Services.GetRequiredService<FakeNavigationManager>();
106+
var nav = Services.GetRequiredService<BunitNavigationManager>();
108107
var baseUriLength = nav.BaseUri.Length;
109108

110109
// Act
111-
var cut = RenderComponent<Authenticators>(parameters =>
110+
var cut = Render<Authenticators>(parameters =>
112111
parameters.Add(p => p.AppId, "cb69481e-8ff7-4039-93ec-0a2729a154b1"));
113112

114113
// Assert

tests/AdminConsole.Tests/Components/Pages/App/Settings/SettingsComponents/ApiKeysSectionTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Passwordless.AdminConsole.Tests.Components.Pages.App.Settings.SettingsComponents;
1717

18-
public class ApiKeysSectionTests : TestContext
18+
public class ApiKeysSectionTests : BunitContext
1919
{
2020
private readonly Mock<ICurrentContext> _currentContext = new();
2121
private readonly Mock<IPasswordlessManagementClient> _managementClientMock = new();
@@ -46,7 +46,7 @@ public void ApiKeysSection_DoesNotRender_WhenApplicationIsPendingDeletion()
4646
{
4747
// Arrange
4848
_currentContext.SetupGet(x => x.IsPendingDelete).Returns(true);
49-
var cut = RenderComponent<ApiKeysSection>();
49+
var cut = Render<ApiKeysSection>();
5050

5151
// Assert
5252
cut.MarkupMatches("");
@@ -64,7 +64,7 @@ public void ApiKeysSection_Renders_WhenApplicationIsNotPendingDeletion()
6464
var expectedApiKeys = _fixture.CreateMany<ApiKeyResponse>().ToImmutableList();
6565
_managementClientMock.Setup(x => x.GetApiKeysAsync(It.Is<string>(p => p == _currentContext.Object.AppId!)))
6666
.ReturnsAsync(expectedApiKeys);
67-
var cut = RenderComponent<ApiKeysSection>();
67+
var cut = Render<ApiKeysSection>();
6868

6969
// Assert
7070
cut.MarkupMatches("<div class=\"panel\" diff:ignoreChildren></div>");
@@ -84,7 +84,7 @@ public void ApiKeysSection_Renders_LockIcon_WhenApiKeyIsUnlocked()
8484
};
8585
_managementClientMock.Setup(x => x.GetApiKeysAsync(It.Is<string>(p => p == _currentContext.Object.AppId!)))
8686
.ReturnsAsync(expectedApiKeys);
87-
var cut = RenderComponent<ApiKeysSection>();
87+
var cut = Render<ApiKeysSection>();
8888

8989
// Assert
9090
var actualCell = cut.FindAll("tbody>tr").Single(x => x.Children.Length > 1).Children.Last();
@@ -108,7 +108,7 @@ public void ApiKeysSection_Renders_ExpectedIcons_WhenApiKeyIsLocked()
108108
};
109109
_managementClientMock.Setup(x => x.GetApiKeysAsync(It.Is<string>(p => p == _currentContext.Object.AppId!)))
110110
.ReturnsAsync(expectedApiKeys);
111-
var cut = RenderComponent<ApiKeysSection>();
111+
var cut = Render<ApiKeysSection>();
112112

113113
// Assert
114114
var actualCell = cut.FindAll("tbody>tr").Single(x => x.Children.Length > 1).Children.Last();

tests/AdminConsole.Tests/Components/Pages/App/Settings/SettingsComponents/CreateApiKeyComponentTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Passwordless.AdminConsole.Tests.Components.Pages.App.Settings.SettingsComponents;
1616

17-
public class CreateApiKeyComponentTests : TestContext
17+
public class CreateApiKeyComponentTests : BunitContext
1818
{
1919
private readonly Mock<ICurrentContext> _currentContext = new();
2020
private readonly Mock<IPasswordlessManagementClient> _managementClientMock = new();
@@ -45,7 +45,7 @@ public void CreateApiKeyComponent_Renders_ExpectedScopes()
4545
{
4646
// Arrange
4747
var scopes = Enum.GetValues<SecretKeyScopes>().ToList();
48-
var cut = RenderComponent<CreateApiKeyComponent<SecretKeyScopes>>(p => p
48+
var cut = Render<CreateApiKeyComponent<SecretKeyScopes>>(p => p
4949
.Add(x => x.Scopes, scopes)
5050
.Add(x => x.OnCreateClicked, () => { }));
5151

tests/AdminConsole.Tests/Components/Pages/App/Settings/SettingsComponents/DeleteApplicationSectionTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Passwordless.AdminConsole.Tests.Components.Pages.App.Settings.SettingsComponents;
1515

16-
public class DeleteApplicationSectionTests : TestContext
16+
public class DeleteApplicationSectionTests : BunitContext
1717
{
1818
private readonly Mock<IApplicationService> _appServiceMock = new();
1919
private readonly Mock<IHttpContextAccessor> _httpContextAccessorMock = new();
@@ -37,7 +37,7 @@ public void Renders_CannotDeleteImmediatelyParagraphs_WhenCannotDeleteImmediatel
3737
.ReturnsAsync(false);
3838

3939
// Act
40-
var cut = RenderComponent<DeleteApplicationSection>(c =>
40+
var cut = Render<DeleteApplicationSection>(c =>
4141
c.Add(p => p.Application, application));
4242

4343
// Assert
@@ -56,7 +56,7 @@ public void DoesNotRender_ExpectedParagraphs_WhenCanDeleteImmediately()
5656
.ReturnsAsync(true);
5757

5858
// Act
59-
var cut = RenderComponent<DeleteApplicationSection>(c =>
59+
var cut = Render<DeleteApplicationSection>(c =>
6060
c.Add(p => p.Application, application));
6161

6262
// Assert
@@ -77,7 +77,7 @@ public void Renders_ExpectedForms_WhenIsPendingDeletion()
7777
};
7878

7979
// Act
80-
var cut = RenderComponent<DeleteApplicationSection>(c =>
80+
var cut = Render<DeleteApplicationSection>(c =>
8181
c.Add(p => p.Application, application));
8282

8383
// Assert
@@ -98,7 +98,7 @@ public void DoesNotRender_ExpectedForms_WhenIsNotPendingDeletion()
9898
};
9999

100100
// Act
101-
var cut = RenderComponent<DeleteApplicationSection>(c =>
101+
var cut = Render<DeleteApplicationSection>(c =>
102102
c.Add(p => p.Application, application));
103103

104104
// Assert
@@ -116,7 +116,7 @@ public void SubmittingDeleteForm_WithIncorrectNameConfirmation_ShowsValidationMe
116116
x.CanDeleteApplicationImmediatelyAsync(It.Is<string>(p => p == application.Id)))
117117
.ReturnsAsync(true);
118118

119-
var cut = RenderComponent<DeleteApplicationSection>(c =>
119+
var cut = Render<DeleteApplicationSection>(c =>
120120
c.Add(p => p.Application, application));
121121

122122
// Act
@@ -150,7 +150,7 @@ public void SubmittingDeleteForm_WithCorrectNameConfirmation_NavigatesAwayWhenSu
150150
It.Is<string>(p => p == username)))
151151
.ReturnsAsync(expectedDeleteResponse);
152152

153-
var cut = RenderComponent<DeleteApplicationSection>(c =>
153+
var cut = Render<DeleteApplicationSection>(c =>
154154
c.Add(p => p.Application, application));
155155

156156
// Act
@@ -165,7 +165,7 @@ public void SubmittingDeleteForm_WithCorrectNameConfirmation_NavigatesAwayWhenSu
165165
It.Is<string>(p => p == application.Id),
166166
It.Is<string>(p => p == username)), Times.Once);
167167

168-
var navMan = Services.GetRequiredService<FakeNavigationManager>();
168+
var navMan = Services.GetRequiredService<BunitNavigationManager>();
169169
Assert.Equal("http://localhost/Organization/Overview", navMan.Uri);
170170
}
171171

@@ -186,7 +186,7 @@ public void SubmittingCancelDeleteForm_WithCorrectNameConfirmation_NavigatesToSa
186186
var principal = new ClaimsPrincipal(identity);
187187
_httpContextAccessorMock.SetupGet(x => x.HttpContext.User).Returns(principal);
188188

189-
var cut = RenderComponent<DeleteApplicationSection>(c =>
189+
var cut = Render<DeleteApplicationSection>(c =>
190190
c.Add(p => p.Application, application));
191191

192192
// Act
@@ -198,7 +198,7 @@ public void SubmittingCancelDeleteForm_WithCorrectNameConfirmation_NavigatesToSa
198198
_appServiceMock.Verify(x =>
199199
x.CancelDeletionForApplicationAsync(It.Is<string>(p => p == application.Id)), Times.Once);
200200

201-
var navMan = Services.GetRequiredService<FakeNavigationManager>();
201+
var navMan = Services.GetRequiredService<BunitNavigationManager>();
202202
Assert.Equal("http://localhost/", navMan.Uri);
203203
}
204204
}

0 commit comments

Comments
 (0)