mirror of https://github.com/abpframework/abp.git
8 changed files with 187 additions and 2 deletions
@ -0,0 +1,25 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Web"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<AssemblyName>Volo.Abp.Identity.AspNetCore.Tests</AssemblyName> |
|||
<PackageId>Volo.Abp.Identity.AspNetCore.Tests</PackageId> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.TestBase\Volo.Abp.AspNetCore.TestBase.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Identity.AspNetCore\Volo.Abp.Identity.AspNetCore.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.Identity.Domain.Tests\Volo.Abp.Identity.Domain.Tests.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.AspNetCore.TestBase; |
|||
|
|||
namespace Volo.Abp.Identity.AspNetCore |
|||
{ |
|||
public abstract class AbpIdentityAspNetCoreTestBase : AbpAspNetCoreIntegratedTestBase<AbpIdentityAspNetCoreTestStartup> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Mvc.ApplicationParts; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.TestBase; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Identity.AspNetCore |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpIdentityAspNetCoreModule), |
|||
typeof(AbpIdentityDomainTestModule), |
|||
typeof(AbpAspNetCoreTestBaseModule), |
|||
typeof(AbpAspNetCoreMvcModule) |
|||
)] |
|||
public class AbpIdentityAspNetCoreTestModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.PreConfigure<IMvcBuilder>(builder => |
|||
{ |
|||
builder.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(AbpIdentityAspNetCoreTestModule).Assembly)); |
|||
}); |
|||
} |
|||
|
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
var app = context.GetApplicationBuilder(); |
|||
var env = context.GetEnvironment(); |
|||
|
|||
app.UseRouting(); |
|||
app.UseAuthentication(); |
|||
app.UseAuthorization(); |
|||
app.UseConfiguredEndpoints(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace Volo.Abp.Identity.AspNetCore |
|||
{ |
|||
public class AbpIdentityAspNetCoreTestStartup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AbpIdentityAspNetCoreTestModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
using System.Net; |
|||
using System.Net.Http; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Identity.AspNetCore |
|||
{ |
|||
public class AbpSignInManager_Tests : AbpIdentityAspNetCoreTestBase |
|||
{ |
|||
[Fact] |
|||
public async Task Should_SignIn_With_Correct_Credentials() |
|||
{ |
|||
var result = await GetResponseAsStringAsync( |
|||
"api/signin-test/password?userName=admin&password=1q2w3E*" |
|||
); |
|||
|
|||
result.ShouldBe("Succeeded"); |
|||
} |
|||
[Fact] |
|||
public async Task Should_Not_SignIn_With_Wrong_Credentials() |
|||
{ |
|||
var result = await GetResponseAsStringAsync( |
|||
"api/signin-test/password?userName=admin&password=WRONG_PASSWORD" |
|||
); |
|||
|
|||
result.ShouldBe("Failed"); |
|||
} |
|||
|
|||
//TODO: Move to a better common place ----------------------------------------------------
|
|||
|
|||
protected virtual async Task<string> GetResponseAsStringAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) |
|||
{ |
|||
var response = await GetResponseAsync(url, expectedStatusCode); |
|||
return await response.Content.ReadAsStringAsync(); |
|||
} |
|||
|
|||
protected virtual async Task<HttpResponseMessage> GetResponseAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) |
|||
{ |
|||
var response = await Client.GetAsync(url); |
|||
response.StatusCode.ShouldBe(expectedStatusCode); |
|||
return response; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Identity; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace Volo.Abp.Identity.AspNetCore |
|||
{ |
|||
[Route("api/signin-test")] |
|||
public class SignInTestController : AbpController |
|||
{ |
|||
private readonly SignInManager<IdentityUser> _signInManager; |
|||
|
|||
public SignInTestController(SignInManager<IdentityUser> signInManager) |
|||
{ |
|||
_signInManager = signInManager; |
|||
} |
|||
|
|||
[Route("password")] |
|||
public async Task<ActionResult> PasswordLogin(string userName, string password) |
|||
{ |
|||
var result = await _signInManager.PasswordSignInAsync( |
|||
userName, |
|||
password, |
|||
false, |
|||
false |
|||
); |
|||
|
|||
return Content(result.ToString()); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue