-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
197 additions
and
93 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/BlazorUI/Demo/Bit.BlazorUI.Demo.Server/Bit.BlazorUI.Demo.Server.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...orUI/Demo/Client/Bit.BlazorUI.Demo.Client.Windows/Bit.BlazorUI.Demo.Client.Windows.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...erplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/Boilerplate.Client.Maui.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...e/Bit.Boilerplate/src/Client/Boilerplate.Client.Windows/Boilerplate.Client.Windows.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Boilerplate.Server.Api.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...lates/Boilerplate/Bit.Boilerplate/src/Tests/Extensions/WebApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Boilerplate.Server.Web; | ||
using Boilerplate.Tests.Services; | ||
using Boilerplate.Client.Core.Services.Contracts; | ||
|
||
namespace Microsoft.AspNetCore.Builder; | ||
|
||
public static partial class WebApplicationBuilderExtensions | ||
{ | ||
public static void AddTestProjectServices(this WebApplicationBuilder builder) | ||
{ | ||
var services = builder.Services; | ||
|
||
services.TryAddScoped<IStorageService, TestStorageService>(); | ||
services.TryAddTransient<IAuthTokenProvider, TestTokenProvider>(); | ||
|
||
services.TryAddTransient(sp => | ||
{ | ||
return new HttpClient(sp.GetRequiredService<HttpMessageHandler>()) | ||
{ | ||
BaseAddress = new Uri(sp.GetRequiredService<IConfiguration>().GetServerAddress(), UriKind.Absolute) | ||
}; | ||
}); | ||
|
||
builder.AddServerWebProjectServices(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Templates/Boilerplate/Bit.Boilerplate/src/Tests/IdentityApiTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Boilerplate.Client.Core.Services; | ||
using Boilerplate.Shared.Controllers.Identity; | ||
|
||
namespace Boilerplate.Tests; | ||
|
||
[TestClass] | ||
public partial class IdentityApiTests | ||
{ | ||
[TestMethod] | ||
public async Task SignInTest() | ||
{ | ||
await using var server = new AppTestServer(); | ||
|
||
await server.Build(services => | ||
{ | ||
// Services registered in this test project will be used instead of the application's services, allowing you to fake certain behaviors during testing. | ||
}).Start(); | ||
|
||
await using var scope = server.Services.CreateAsyncScope(); | ||
|
||
var authenticationManager = scope.ServiceProvider.GetRequiredService<AuthenticationManager>(); | ||
|
||
var signInResponse = await authenticationManager.SignIn(new() | ||
{ | ||
Email = "[email protected]", | ||
Password = "123456" | ||
}, default); | ||
|
||
var userController = scope.ServiceProvider.GetRequiredService<IUserController>(); | ||
|
||
var user = await userController.GetCurrentUser(default); | ||
|
||
Assert.AreEqual(Guid.Parse("8ff71671-a1d6-4f97-abb9-d87d7b47d6e7"), user.Id); | ||
} | ||
|
||
[TestMethod, ExpectedException(typeof(UnauthorizedException))] | ||
public async Task UnauthorizedAccessTest() | ||
{ | ||
await using var server = new AppTestServer(); | ||
|
||
await server.Build().Start(); | ||
|
||
await using var scope = server.Services.CreateAsyncScope(); | ||
|
||
var userController = scope.ServiceProvider.GetRequiredService<IUserController>(); | ||
|
||
var user = await userController.GetCurrentUser(default); | ||
} | ||
} |
Oops, something went wrong.