mirror of https://github.com/abpframework/abp.git
70 changed files with 1590 additions and 242 deletions
@ -0,0 +1,15 @@ |
|||
using System.Threading.Tasks; |
|||
using Blazorise; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI; |
|||
|
|||
public static class AbpBlazoriseUiModalExtensions |
|||
{ |
|||
public static Task CancelClosingModalWhenFocusLost(this Modal modal, ModalClosingEventArgs eventArgs) |
|||
{ |
|||
// cancel close if clicked outside of modal area
|
|||
eventArgs.Cancel = eventArgs.CloseReason == CloseReason.FocusLostClosing; |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
@model Volo.CmsKit.ViewComponents.CommentDateViewComponent |
|||
|
|||
<p>Welcome Comment Date Component</p> |
|||
@if (Model.IsShow) |
|||
{ |
|||
<p> @DateTime.Today.ToLongDateString()</p> |
|||
} |
|||
else |
|||
{ |
|||
<p>Without date</p> |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
|||
|
|||
namespace Volo.CmsKit.ViewComponents; |
|||
|
|||
[Widget( |
|||
AutoInitialize = true |
|||
)] |
|||
|
|||
[ViewComponent(Name = "CommentDate")] |
|||
public class CommentDateViewComponent : AbpViewComponent |
|||
{ |
|||
public bool IsShow { get; set; } |
|||
|
|||
public CommentDateViewComponent() |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<IViewComponentResult> InvokeAsync(string isShow) |
|||
{ |
|||
return View("~/ViewComponents/CommentDate.cshtml", new CommentDateViewComponent() { IsShow = bool.Parse(isShow) }); |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
@using Volo.CmsKit.ViewComponents |
|||
@model DecisionCommentDateViewModel |
|||
|
|||
<div class="form-check mb-3"> |
|||
<abp-input asp-for="IsShow" /> |
|||
</div> |
|||
@ -0,0 +1,32 @@ |
|||
using System.ComponentModel; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.CmsKit.ViewComponents; |
|||
|
|||
[Widget( |
|||
AutoInitialize = true |
|||
)] |
|||
|
|||
[ViewComponent(Name = "DecisionCommentDate")] |
|||
public class DecisionCommentDateViewComponent : AbpViewComponent |
|||
{ |
|||
public DecisionCommentDateViewComponent() |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<IViewComponentResult> InvokeAsync() |
|||
{ |
|||
return View("~/ViewComponents/DecisionCommentDate.cshtml", new DecisionCommentDateViewModel()); |
|||
} |
|||
} |
|||
|
|||
public class DecisionCommentDateViewModel |
|||
{ |
|||
[DisplayName("Show date in the component")] |
|||
public bool IsShow { get; set; } = true; |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.CmsKit.Admin.Contents; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Contents; |
|||
|
|||
public class ContentAdminAppService_Tests : CmsKitApplicationTestBase |
|||
{ |
|||
private readonly IContentAdminAppService _contentAdminAppService; |
|||
|
|||
public ContentAdminAppService_Tests() |
|||
{ |
|||
_contentAdminAppService = GetRequiredService<IContentAdminAppService>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldGet_PagedListAsync() |
|||
{ |
|||
var widgets = await _contentAdminAppService.GetWidgetsAsync(); |
|||
|
|||
widgets.Items.Count.ShouldBe(0); |
|||
widgets.Items.Any().ShouldBeFalse(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,128 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using OpenIddict.Abstractions; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Authorizations; |
|||
|
|||
public class AbpOpenIddictAuthorizationStore_Tests : OpenIddictDomainTestBase |
|||
{ |
|||
private readonly IOpenIddictAuthorizationStore<OpenIddictAuthorizationModel> _authorizationStore; |
|||
private readonly AbpOpenIddictTestData _testData; |
|||
|
|||
public AbpOpenIddictAuthorizationStore_Tests() |
|||
{ |
|||
_authorizationStore = ServiceProvider.GetRequiredService<IOpenIddictAuthorizationStore<OpenIddictAuthorizationModel>>(); |
|||
_testData = ServiceProvider.GetRequiredService<AbpOpenIddictTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CountAsync() |
|||
{ |
|||
var count = await _authorizationStore.CountAsync(CancellationToken.None); |
|||
count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CreateAsync() |
|||
{ |
|||
var id = Guid.NewGuid(); |
|||
await _authorizationStore.CreateAsync(new OpenIddictAuthorizationModel { |
|||
Id = id, |
|||
ApplicationId = _testData.App1Id, |
|||
Status = "TestStatus3", |
|||
Subject = "TestSubject3", |
|||
Type = OpenIddictConstants.AuthorizationTypes.Permanent |
|||
}, CancellationToken.None); |
|||
|
|||
var authorization = await _authorizationStore.FindByIdAsync(id.ToString(), CancellationToken.None); |
|||
|
|||
authorization.ShouldNotBeNull(); |
|||
authorization.Status.ShouldBe("TestStatus3"); |
|||
authorization.Subject.ShouldBe("TestSubject3"); |
|||
authorization.Type.ShouldBe(OpenIddictConstants.AuthorizationTypes.Permanent); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteAsync() |
|||
{ |
|||
var authorization = await _authorizationStore.FindByIdAsync(_testData.Authorization1Id.ToString(), CancellationToken.None); |
|||
await _authorizationStore.DeleteAsync(authorization, CancellationToken.None); |
|||
|
|||
authorization = await _authorizationStore.FindByIdAsync(_testData.Authorization1Id.ToString(), CancellationToken.None); |
|||
authorization.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync_Should_Return_Null_If_Not_Found() |
|||
{ |
|||
var authorization = await _authorizationStore.FindByIdAsync(new Guid().ToString(), CancellationToken.None); |
|||
authorization.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync_Should_Return_Authorization_If_Not_Found() |
|||
{ |
|||
var authorization = await _authorizationStore.FindByIdAsync(_testData.Authorization1Id.ToString(), CancellationToken.None); |
|||
authorization.ShouldNotBeNull(); |
|||
authorization.Status.ShouldBe("TestStatus1"); |
|||
authorization.Subject.ShouldBe("TestSubject1"); |
|||
authorization.Type.ShouldBe(OpenIddictConstants.AuthorizationTypes.Permanent); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByApplicationIdAsync_Should_Return_Empty_If_Not_Found() |
|||
{ |
|||
var authorizations = await _authorizationStore.FindByApplicationIdAsync(new Guid().ToString(), CancellationToken.None).ToListAsync(); |
|||
|
|||
authorizations.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByApplicationIdAsync_Should_Return_Authorizations_If_Found() |
|||
{ |
|||
var authorizations = await _authorizationStore.FindByApplicationIdAsync(_testData.App1Id.ToString(), CancellationToken.None).ToListAsync(); |
|||
|
|||
authorizations.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindBySubjectAsync_Should_Return_Empty_If_Not_Found() |
|||
{ |
|||
var authorizations = await _authorizationStore.FindBySubjectAsync(new Guid().ToString(), CancellationToken.None).ToListAsync(); |
|||
|
|||
authorizations.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindBySubjectAsync_Should_Return_Authorizations_If_Found() |
|||
{ |
|||
var authorizations = await _authorizationStore.FindBySubjectAsync("TestSubject1", CancellationToken.None).ToListAsync(); |
|||
|
|||
authorizations.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateAsync() |
|||
{ |
|||
var authorization = await _authorizationStore.FindByIdAsync(_testData.Authorization1Id.ToString(), CancellationToken.None); |
|||
|
|||
authorization.Status = "New status"; |
|||
authorization.Subject = "New subject"; |
|||
authorization.Type = OpenIddictConstants.AuthorizationTypes.AdHoc; |
|||
authorization.ApplicationId = _testData.App2Id; |
|||
|
|||
await _authorizationStore.UpdateAsync(authorization, CancellationToken.None); |
|||
|
|||
authorization = await _authorizationStore.FindByIdAsync(_testData.Authorization1Id.ToString(), CancellationToken.None); |
|||
|
|||
authorization.Status.ShouldBe("New status"); |
|||
authorization.Subject.ShouldBe("New subject"); |
|||
authorization.Type.ShouldBe(OpenIddictConstants.AuthorizationTypes.AdHoc); |
|||
authorization.ApplicationId.ShouldBe(_testData.App2Id); |
|||
} |
|||
} |
|||
@ -0,0 +1,324 @@ |
|||
using System; |
|||
using System.Collections.Immutable; |
|||
using System.Globalization; |
|||
using System.Linq; |
|||
using System.Text.Json; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using OpenIddict.Abstractions; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Scopes; |
|||
|
|||
public class AbpOpenIddictScopeStore_Tests : OpenIddictDomainTestBase |
|||
{ |
|||
private readonly IOpenIddictScopeStore<OpenIddictScopeModel> _scopeStore; |
|||
private readonly AbpOpenIddictTestData _testData; |
|||
|
|||
public AbpOpenIddictScopeStore_Tests() |
|||
{ |
|||
_scopeStore = ServiceProvider.GetRequiredService<IOpenIddictScopeStore<OpenIddictScopeModel>>(); |
|||
_testData = ServiceProvider.GetRequiredService<AbpOpenIddictTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CountAsync() |
|||
{ |
|||
var count = await _scopeStore.CountAsync(CancellationToken.None); |
|||
count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CreateAsync() |
|||
{ |
|||
await _scopeStore.CreateAsync( |
|||
new OpenIddictScopeModel { |
|||
Name = "scope3", Description = "scope3 description", DisplayName = "scope3 display name" |
|||
}, CancellationToken.None); |
|||
|
|||
var scope = await _scopeStore.FindByNameAsync("scope3", CancellationToken.None); |
|||
|
|||
scope.ShouldNotBeNull(); |
|||
scope.Name.ShouldBe("scope3"); |
|||
scope.Description.ShouldBe("scope3 description"); |
|||
scope.DisplayName.ShouldBe("scope3 display name"); |
|||
scope.Descriptions.ShouldBeNull(); |
|||
scope.DisplayNames.ShouldBeNull(); |
|||
scope.Resources.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
await _scopeStore.DeleteAsync(scope, CancellationToken.None); |
|||
|
|||
scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
scope.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync_Should_Return_Null_If_Not_Found() |
|||
{ |
|||
var nonExistingId = Guid.NewGuid().ToString(); |
|||
var scope = await _scopeStore.FindByIdAsync(nonExistingId, CancellationToken.None); |
|||
scope.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync_Should_Return_Scope_If_Found() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
|
|||
scope.ShouldNotBeNull(); |
|||
scope.Name.ShouldBe(_testData.Scope1Name); |
|||
scope.DisplayName.ShouldBe("Test Scope 1"); |
|||
scope.Description.ShouldBe("Test Scope 1"); |
|||
scope.DisplayNames.ShouldContain("测试范围1"); |
|||
scope.DisplayNames.ShouldContain("Test Kapsamı 1"); |
|||
scope.Resources.ShouldBe("[\"TestScope1Resource\"]"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByNameAsync_Should_Return_Null_If_Not_Found() |
|||
{ |
|||
var nonExistingName = Guid.NewGuid().ToString(); |
|||
var scope = await _scopeStore.FindByNameAsync(nonExistingName, CancellationToken.None); |
|||
scope.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByNameAsync_Should_Return_Application_If_Found() |
|||
{ |
|||
var scope = await _scopeStore.FindByNameAsync(_testData.Scope1Name, CancellationToken.None); |
|||
|
|||
scope.ShouldNotBeNull(); |
|||
scope.Name.ShouldBe(_testData.Scope1Name); |
|||
scope.DisplayName.ShouldBe("Test Scope 1"); |
|||
scope.Description.ShouldBe("Test Scope 1"); |
|||
scope.DisplayNames.ShouldContain("测试范围1"); |
|||
scope.DisplayNames.ShouldContain("Test Kapsamı 1"); |
|||
scope.Resources.ShouldBe("[\"TestScope1Resource\"]"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByNamesAsync_Should_Return_Empty_If_Not_Found() |
|||
{ |
|||
var scopes = await _scopeStore |
|||
.FindByNamesAsync(ImmutableArray.Create("non-existing-name"), CancellationToken.None).ToListAsync(); |
|||
scopes.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByNamesAsync_Should_Return_Scopes_If_Found() |
|||
{ |
|||
var scopes = await _scopeStore |
|||
.FindByNamesAsync(ImmutableArray.Create("Scope1", "Scope2", "Scope3"), CancellationToken.None) |
|||
.ToListAsync(); |
|||
scopes.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByResourceAsync_Should_Return_Empty_If_Not_Found() |
|||
{ |
|||
var scopes = await _scopeStore.FindByResourceAsync("non-existing-resource", CancellationToken.None) |
|||
.ToListAsync(); |
|||
scopes.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByResourceAsync_Should_Return_Scopes_If_Found() |
|||
{ |
|||
var scopes = await _scopeStore.FindByResourceAsync("TestScope1Resource", CancellationToken.None).ToListAsync(); |
|||
scopes.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetDescriptionAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
var description = await _scopeStore.GetDescriptionAsync(scope, CancellationToken.None); |
|||
description.ShouldBe("Test Scope 1"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetDescriptionsAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
var descriptions = await _scopeStore.GetDescriptionsAsync(scope, CancellationToken.None); |
|||
descriptions.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetDisplayNameAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
var displayName = await _scopeStore.GetDisplayNameAsync(scope, CancellationToken.None); |
|||
displayName.ShouldBe("Test Scope 1"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetDisplayNamesAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
var displayNames = await _scopeStore.GetDisplayNamesAsync(scope, CancellationToken.None); |
|||
displayNames.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetIdAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
var id = await _scopeStore.GetIdAsync(scope, CancellationToken.None); |
|||
id.ShouldBe(_testData.Scope1Id.ToString()); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetNameAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
var name = await _scopeStore.GetNameAsync(scope, CancellationToken.None); |
|||
name.ShouldBe("Scope1"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetPropertiesAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
var properties = await _scopeStore.GetPropertiesAsync(scope, CancellationToken.None); |
|||
properties.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetResourcesAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
var resources = await _scopeStore.GetResourcesAsync(scope, CancellationToken.None); |
|||
resources.Length.ShouldBe(1); |
|||
resources.First().ShouldBe("TestScope1Resource"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task InstantiateAsync() |
|||
{ |
|||
var scope = await _scopeStore.InstantiateAsync(CancellationToken.None); |
|||
scope.ShouldNotBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ListAsync_Should_Return_Empty_If_Not_Found() |
|||
{ |
|||
var scopes = await _scopeStore.ListAsync(2, 2, CancellationToken.None).ToListAsync(); |
|||
scopes.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ListAsync_Should_Return_Applications_If_Found() |
|||
{ |
|||
var scopes = await _scopeStore.ListAsync(2, 0, CancellationToken.None).ToListAsync(); |
|||
|
|||
scopes.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetDescriptionAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
await _scopeStore.SetDescriptionAsync(scope, "New Test Scope 1 Description", CancellationToken.None); |
|||
|
|||
scope.Description.ShouldBe("New Test Scope 1 Description"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetDescriptionsAsync() |
|||
{ |
|||
var descriptions = ImmutableDictionary.Create<CultureInfo, string>(); |
|||
descriptions = descriptions.Add(CultureInfo.GetCultureInfo("en"), "Test Scope"); |
|||
descriptions = descriptions.Add(CultureInfo.GetCultureInfo("zh-Hans"), "测试范围"); |
|||
|
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
await _scopeStore.SetDescriptionsAsync(scope, descriptions, CancellationToken.None); |
|||
|
|||
scope.Descriptions.ShouldContain("Test Scope"); |
|||
scope.Descriptions.ShouldContain("测试范围"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetDisplayNameAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
await _scopeStore.SetDisplayNameAsync(scope, "New Test Scope 1 Display Name", CancellationToken.None); |
|||
|
|||
scope.DisplayName.ShouldBe("New Test Scope 1 Display Name"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetDisplayNamesAsync() |
|||
{ |
|||
var displayNames = ImmutableDictionary.Create<CultureInfo, string>(); |
|||
displayNames = displayNames.Add(CultureInfo.GetCultureInfo("en"), "Test Scope"); |
|||
displayNames = displayNames.Add(CultureInfo.GetCultureInfo("zh-Hans"), "测试范围"); |
|||
|
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
await _scopeStore.SetDisplayNamesAsync(scope, displayNames, CancellationToken.None); |
|||
|
|||
scope.DisplayNames.ShouldContain("Test Scope"); |
|||
scope.DisplayNames.ShouldContain("测试范围"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetNameAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
await _scopeStore.SetNameAsync(scope, "New Test Scope 1 Name", CancellationToken.None); |
|||
|
|||
scope.Name.ShouldBe("New Test Scope 1 Name"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetPropertiesAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
await _scopeStore.SetPropertiesAsync(scope, ImmutableDictionary.Create<string, JsonElement>(), |
|||
CancellationToken.None); |
|||
|
|||
scope.Properties.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetResourcesAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
await _scopeStore.SetResourcesAsync(scope, ImmutableArray.Create("TestScope1Resource", "TestScope1Resource2"), |
|||
CancellationToken.None); |
|||
|
|||
scope.Resources.ShouldContain("TestScope1Resource"); |
|||
scope.Resources.ShouldContain("TestScope1Resource2"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateAsync() |
|||
{ |
|||
var scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
scope.Name = "New Test Scope 1 Name"; |
|||
scope.DisplayName = "New Test Scope 1 Display Name"; |
|||
scope.Resources = "New Test Scope 1 Resource"; |
|||
scope.Properties = "New Test Scope 1 Properties"; |
|||
scope.Description = "New Test Scope 1 Description"; |
|||
scope.Descriptions = "New Test Scope 1 Descriptions"; |
|||
scope.DisplayNames = "New Test Scope 1 Display Names"; |
|||
|
|||
await _scopeStore.UpdateAsync(scope, CancellationToken.None); |
|||
|
|||
scope = await _scopeStore.FindByIdAsync(_testData.Scope1Id.ToString(), CancellationToken.None); |
|||
scope.Name.ShouldBe("New Test Scope 1 Name"); |
|||
scope.DisplayName.ShouldBe("New Test Scope 1 Display Name"); |
|||
scope.Resources.ShouldBe("New Test Scope 1 Resource"); |
|||
scope.Properties.ShouldBe("New Test Scope 1 Properties"); |
|||
scope.Description.ShouldBe("New Test Scope 1 Description"); |
|||
scope.Descriptions.ShouldBe("New Test Scope 1 Descriptions"); |
|||
scope.DisplayNames.ShouldBe("New Test Scope 1 Display Names"); |
|||
} |
|||
} |
|||
@ -0,0 +1,156 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using OpenIddict.Abstractions; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Tokens; |
|||
|
|||
public class AbpOpenIddictTokenStore_Tests : OpenIddictDomainTestBase |
|||
{ |
|||
private readonly IOpenIddictTokenStore<OpenIddictTokenModel> _tokenStore; |
|||
private readonly AbpOpenIddictTestData _testData; |
|||
|
|||
public AbpOpenIddictTokenStore_Tests() |
|||
{ |
|||
_tokenStore = ServiceProvider.GetRequiredService<IOpenIddictTokenStore<OpenIddictTokenModel>>(); |
|||
_testData = ServiceProvider.GetRequiredService<AbpOpenIddictTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CountAsync() |
|||
{ |
|||
var count = await _tokenStore.CountAsync(CancellationToken.None); |
|||
count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CreateAsync() |
|||
{ |
|||
await _tokenStore.CreateAsync(new OpenIddictTokenModel |
|||
{ |
|||
ApplicationId = _testData.App1Id, |
|||
Payload = "TestPayload3", |
|||
Subject = "TestSubject3", |
|||
Type = "TestType3", |
|||
Status = OpenIddictConstants.Statuses.Inactive, |
|||
|
|||
}, CancellationToken.None); |
|||
|
|||
var tokens = await _tokenStore.FindBySubjectAsync("TestSubject3", CancellationToken.None).ToListAsync(); |
|||
|
|||
tokens.Count.ShouldBe(1); |
|||
var token = tokens.First(); |
|||
token.ApplicationId.ShouldBe(_testData.App1Id); |
|||
token.Payload.ShouldBe("TestPayload3"); |
|||
token.Subject.ShouldBe("TestSubject3"); |
|||
token.Type.ShouldBe("TestType3"); |
|||
token.Status.ShouldBe(OpenIddictConstants.Statuses.Inactive); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteAsync() |
|||
{ |
|||
var token = await _tokenStore.FindByIdAsync(_testData.Token1Id.ToString(), CancellationToken.None); |
|||
await _tokenStore.DeleteAsync(token, CancellationToken.None); |
|||
|
|||
token = await _tokenStore.FindByIdAsync(_testData.Token1Id.ToString(), CancellationToken.None); |
|||
token.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync_Should_Return_Empty_If_Not_Found() |
|||
{ |
|||
var tokens = await _tokenStore.FindAsync("non_existing_subject", _testData.App1Id.ToString(), "non_existing_status", "non_existing_type", CancellationToken.None).ToListAsync(); |
|||
|
|||
tokens.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync_Should_Return_Tokens_If_Found() |
|||
{ |
|||
var tokens = await _tokenStore.FindAsync("TestSubject1", _testData.App1Id.ToString(),OpenIddictConstants.Statuses.Redeemed, "TestType1", CancellationToken.None).ToListAsync(); |
|||
|
|||
tokens.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByApplicationIdAsync_Should_Return_Empty_If_Not_Found() |
|||
{ |
|||
var tokens = await _tokenStore.FindByApplicationIdAsync(Guid.NewGuid().ToString(), CancellationToken.None).ToListAsync(); |
|||
|
|||
tokens.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByApplicationIdAsync_Should_Return_Tokens_If_Found() |
|||
{ |
|||
var tokens = await _tokenStore.FindByApplicationIdAsync(_testData.App1Id.ToString(), CancellationToken.None).ToListAsync(); |
|||
|
|||
tokens.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync_Should_Return_Null_If_Not_Found() |
|||
{ |
|||
var nonExistingId = Guid.NewGuid().ToString(); |
|||
var token = await _tokenStore.FindByIdAsync(nonExistingId, CancellationToken.None); |
|||
token.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync_Should_Return_Token_If_Found() |
|||
{ |
|||
var token = await _tokenStore.FindByIdAsync(_testData.Token1Id.ToString(), CancellationToken.None); |
|||
|
|||
token.ShouldNotBeNull(); |
|||
token.ApplicationId.ShouldBe(_testData.App1Id); |
|||
token.Payload.ShouldBe("TestPayload1"); |
|||
token.Subject.ShouldBe("TestSubject1"); |
|||
token.Type.ShouldBe("TestType1"); |
|||
token.Status.ShouldBe(OpenIddictConstants.Statuses.Redeemed); |
|||
token.ExpirationDate.ShouldNotBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByReferenceIdAsync_Should_Return_Null_If_Not_Found() |
|||
{ |
|||
var token = await _tokenStore.FindByReferenceIdAsync(Guid.NewGuid().ToString(), CancellationToken.None); |
|||
token.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByReferenceIdAsync_Should_Return_Token_If_Found() |
|||
{ |
|||
var token = await _tokenStore.FindByIdAsync(_testData.Token1Id.ToString(), CancellationToken.None); |
|||
token = await _tokenStore.FindByReferenceIdAsync(token.ReferenceId, CancellationToken.None); |
|||
token.ShouldNotBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateAsync() |
|||
{ |
|||
var token = await _tokenStore.FindByIdAsync(_testData.Token1Id.ToString(), CancellationToken.None); |
|||
|
|||
var now = DateTime.Now; |
|||
token.ApplicationId = _testData.App2Id; |
|||
token.Payload = "New payload"; |
|||
token.Status = OpenIddictConstants.Statuses.Revoked; |
|||
token.Subject = "New subject"; |
|||
token.Type = "New type"; |
|||
token.ExpirationDate = now; |
|||
|
|||
await _tokenStore.UpdateAsync(token, CancellationToken.None); |
|||
token = await _tokenStore.FindByIdAsync(_testData.Token1Id.ToString(), CancellationToken.None); |
|||
|
|||
token.ApplicationId.ShouldBe(_testData.App2Id); |
|||
token.Payload.ShouldBe("New payload"); |
|||
token.Subject.ShouldBe("New subject"); |
|||
token.Type.ShouldBe("New type"); |
|||
token.Status.ShouldBe(OpenIddictConstants.Statuses.Revoked); |
|||
token.ExpirationDate.ShouldBe(now); |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System.Threading.Tasks; |
|||
using OpenIddict.Abstractions; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Tokens; |
|||
|
|||
public class TokenCleanupService_Tests : OpenIddictDomainTestBase |
|||
{ |
|||
private readonly IOpenIddictTokenManager _tokenManager; |
|||
private readonly IOpenIddictAuthorizationManager _authorizationManager; |
|||
private readonly TokenCleanupService _tokenCleanupService; |
|||
|
|||
public TokenCleanupService_Tests() |
|||
{ |
|||
_tokenManager = GetRequiredService<IOpenIddictTokenManager>(); |
|||
_authorizationManager = GetRequiredService<IOpenIddictAuthorizationManager>(); |
|||
_tokenCleanupService = GetRequiredService<TokenCleanupService>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Clear_Expired_Tokens() |
|||
{ |
|||
var tokensCount = await _tokenManager.CountAsync(); |
|||
var authorizationsCount = await _authorizationManager.CountAsync(); |
|||
|
|||
await _tokenCleanupService.CleanAsync(); |
|||
|
|||
(await _tokenManager.CountAsync()) |
|||
.ShouldBe(tokensCount - 1); |
|||
|
|||
(await _authorizationManager.CountAsync()) |
|||
.ShouldBe(authorizationsCount - 1); |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.OpenIddict.EntityFrameworkCore; |
|||
|
|||
public class OpenIddictApplicationRepository_Tests : OpenIddictApplicationRepository_Tests<OpenIddictEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.OpenIddict.EntityFrameworkCore; |
|||
|
|||
public class OpenIddictAuthorizationRepository_Tests : OpenIddictAuthorizationRepository_Tests<OpenIddictEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.OpenIddict.EntityFrameworkCore; |
|||
|
|||
public class OpenIddictScopeRepository_Tests : OpenIddictScopeRepository_Tests<OpenIddictEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.OpenIddict.EntityFrameworkCore; |
|||
|
|||
public class OpenIddictTokenRepository_Tests : OpenIddictTokenRepository_Tests<OpenIddictEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
using System; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Identity.MongoDB; |
|||
|
|||
namespace Volo.Abp.OpenIddict.MongoDB; |
|||
|
|||
[DependsOn( |
|||
typeof(OpenIddictTestBaseModule), |
|||
typeof(AbpIdentityMongoDbModule), |
|||
typeof(AbpOpenIddictMongoDbModule) |
|||
)] |
|||
public class OpenIddictMongoDbTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var stringArray = MongoDbFixture.ConnectionString.Split('?'); |
|||
var connectionString = stringArray[0].EnsureEndsWith('/') + |
|||
"Db_" + |
|||
Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; |
|||
|
|||
Configure<AbpDbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = connectionString; |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict.MongoDB; |
|||
|
|||
[Collection(MongoTestCollection.Name)] |
|||
public class OpenIddictApplicationRepository_Tests : OpenIddictApplicationRepository_Tests<OpenIddictMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict.MongoDB; |
|||
|
|||
[Collection(MongoTestCollection.Name)] |
|||
public class OpenIddictAuthorizationRepository_Tests : OpenIddictAuthorizationRepository_Tests<OpenIddictMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Identity.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.OpenIddict.MongoDB; |
|||
|
|||
[DependsOn( |
|||
typeof(OpenIddictTestBaseModule), |
|||
typeof(AbpIdentityMongoDbModule), |
|||
typeof(AbpOpenIddictMongoDbModule) |
|||
)] |
|||
public class OpenIddictMongoDbTestModule : AbpModule |
|||
{ |
|||
private static string _connectionString; |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var stringArray = MongoDbFixture.ConnectionString.Split('?'); |
|||
_connectionString = stringArray[0].EnsureEndsWith('/') + |
|||
"Db_" + |
|||
Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; |
|||
|
|||
Configure<AbpDbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = _connectionString; |
|||
}); |
|||
} |
|||
|
|||
public override void OnPreApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
Migrate(context); |
|||
} |
|||
|
|||
private static void Migrate(ApplicationInitializationContext context) |
|||
{ |
|||
var dbContexts = context.ServiceProvider.GetServices<IAbpMongoDbContext>(); |
|||
|
|||
foreach (var dbContext in dbContexts) |
|||
{ |
|||
var mongoUrl = new MongoUrl(_connectionString); |
|||
var databaseName = mongoUrl.DatabaseName; |
|||
var client = new MongoClient(mongoUrl); |
|||
|
|||
if (databaseName.IsNullOrWhiteSpace()) |
|||
{ |
|||
databaseName = ConnectionStringNameAttribute.GetConnStringName(dbContext.GetType()); |
|||
} |
|||
|
|||
(dbContext as AbpMongoDbContext)?.InitializeCollections(client.GetDatabase(databaseName)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict.MongoDB; |
|||
|
|||
[Collection(MongoTestCollection.Name)] |
|||
public class OpenIddictScopeRepository_Tests : OpenIddictScopeRepository_Tests<OpenIddictMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict.MongoDB; |
|||
|
|||
[Collection(MongoTestCollection.Name)] |
|||
public class OpenIddictTokenRepository_Tests : OpenIddictTokenRepository_Tests<OpenIddictMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -1,16 +0,0 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public static class AbpOpenIddictTestData |
|||
{ |
|||
public static Guid App1Id { get; set; } = Guid.NewGuid(); |
|||
public static string App1ClientId { get; set; } = "Client1"; |
|||
public static Guid App2Id { get; set; } = Guid.NewGuid(); |
|||
public static string App2ClientId { get; set; } = "Client2"; |
|||
|
|||
public static Guid Scope1Id { get; set; } = Guid.NewGuid(); |
|||
public static string Scope1Name { get; set; } = "Scope1"; |
|||
public static Guid Scope2Id { get; set; } = Guid.NewGuid(); |
|||
public static string Scope2Name { get; set; } = "Scope2"; |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public class AbpOpenIddictTestData : ISingletonDependency |
|||
{ |
|||
public Guid App1Id { get; set; } = Guid.NewGuid(); |
|||
public string App1ClientId { get; set; } = "Client1"; |
|||
public Guid App2Id { get; set; } = Guid.NewGuid(); |
|||
public string App2ClientId { get; set; } = "Client2"; |
|||
|
|||
public Guid Scope1Id { get; set; } = Guid.NewGuid(); |
|||
public string Scope1Name { get; set; } = "Scope1"; |
|||
public Guid Scope2Id { get; set; } = Guid.NewGuid(); |
|||
public string Scope2Name { get; set; } = "Scope2"; |
|||
|
|||
public Guid Token1Id { get; set; } = Guid.NewGuid(); |
|||
|
|||
public Guid Token2Id { get; set; } = Guid.NewGuid(); |
|||
|
|||
public Guid Authorization1Id { get; set; } = Guid.NewGuid(); |
|||
|
|||
public Guid Authorization2Id { get; set; } = Guid.NewGuid(); |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.OpenIddict.Applications; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public abstract class OpenIddictApplicationRepository_Tests<TStartupModule> : OpenIddictTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly IOpenIddictApplicationRepository _applicationRepository; |
|||
private readonly AbpOpenIddictTestData _testData; |
|||
|
|||
protected OpenIddictApplicationRepository_Tests() |
|||
{ |
|||
_applicationRepository = GetRequiredService<IOpenIddictApplicationRepository>(); |
|||
_testData = GetRequiredService<AbpOpenIddictTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync() |
|||
{ |
|||
(await _applicationRepository.GetListAsync()).Count.ShouldBe(2); |
|||
(await _applicationRepository.GetListAsync("id", 1, int.MaxValue)).Count.ShouldBe(1); |
|||
(await _applicationRepository.GetListAsync("id", 0, int.MaxValue, filter: _testData.App1ClientId)).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetCountAsync() |
|||
{ |
|||
(await _applicationRepository.GetCountAsync()).ShouldBe(2); |
|||
(await _applicationRepository.GetCountAsync(filter: _testData.App1ClientId)).ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByClientIdAsync() |
|||
{ |
|||
var application = await _applicationRepository.FindByClientIdAsync(_testData.App1ClientId); |
|||
|
|||
application.ShouldNotBeNull(); |
|||
application.ClientId.ShouldBe(_testData.App1ClientId); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByPostLogoutRedirectUriAsync() |
|||
{ |
|||
var applications = await _applicationRepository.FindByPostLogoutRedirectUriAsync("https://abp.io"); |
|||
applications.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByRedirectUriAsync() |
|||
{ |
|||
var applications = await _applicationRepository.FindByRedirectUriAsync("https://abp.io"); |
|||
applications.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ListAsync() |
|||
{ |
|||
(await _applicationRepository.ListAsync(int.MaxValue , 0)).Count.ShouldBe(2); |
|||
(await _applicationRepository.ListAsync(int.MaxValue , 2)).Count.ShouldBe(0); |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using OpenIddict.Abstractions; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.OpenIddict.Authorizations; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public abstract class OpenIddictAuthorizationRepository_Tests<TStartupModule> : OpenIddictTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly IOpenIddictAuthorizationRepository _authorizationRepository; |
|||
private readonly AbpOpenIddictTestData _testData; |
|||
|
|||
public OpenIddictAuthorizationRepository_Tests() |
|||
{ |
|||
_authorizationRepository = GetRequiredService<IOpenIddictAuthorizationRepository>(); |
|||
_testData = GetRequiredService<AbpOpenIddictTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync() |
|||
{ |
|||
(await _authorizationRepository.FindAsync(subject:"TestSubject1", client: new Guid())).Count.ShouldBe(0); |
|||
(await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id)).Count.ShouldBe(1); |
|||
(await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: "NonExistsStatus")).Count.ShouldBe(0); |
|||
(await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: "TestStatus1")).Count.ShouldBe(1); |
|||
(await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: "TestStatus1" ,type: "NonExistsType")).Count.ShouldBe(0); |
|||
(await _authorizationRepository.FindAsync(subject:"TestSubject1", client: _testData.App1Id, status: "TestStatus1" ,type: OpenIddictConstants.AuthorizationTypes.Permanent)).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByApplicationIdAsync() |
|||
{ |
|||
var authorizations = await _authorizationRepository.FindByApplicationIdAsync(_testData.App1Id); |
|||
|
|||
authorizations.Count.ShouldBe(1); |
|||
authorizations.First().ApplicationId.ShouldBe(_testData.App1Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync() |
|||
{ |
|||
var authorization = await _authorizationRepository.FindByIdAsync(_testData.Authorization1Id); |
|||
|
|||
authorization.ShouldNotBeNull(); |
|||
authorization.Id.ShouldBe(_testData.Authorization1Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindBySubjectAsync() |
|||
{ |
|||
(await _authorizationRepository.FindBySubjectAsync(subject:"TestSubject1")).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ListAsync() |
|||
{ |
|||
(await _authorizationRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(2); |
|||
(await _authorizationRepository.ListAsync(int.MaxValue, 2)).Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetPruneListAsync() |
|||
{ |
|||
var threshold = DateTime.UtcNow - TimeSpan.FromDays(14); |
|||
(await _authorizationRepository.GetPruneListAsync(threshold, int.MaxValue)).Count.ShouldBe(1); |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.OpenIddict.Scopes; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public abstract class OpenIddictScopeRepository_Tests<TStartupModule> : OpenIddictTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly IOpenIddictScopeRepository _scopeRepository; |
|||
private readonly AbpOpenIddictTestData _testData; |
|||
|
|||
public OpenIddictScopeRepository_Tests() |
|||
{ |
|||
_scopeRepository = GetRequiredService<IOpenIddictScopeRepository>(); |
|||
_testData = GetRequiredService<AbpOpenIddictTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync() |
|||
{ |
|||
(await _scopeRepository.GetListAsync("id", 0, int.MaxValue)).Count.ShouldBe(2); |
|||
(await _scopeRepository.GetListAsync("id", 0, int.MaxValue, filter: _testData.Scope1Name)).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetCountAsync() |
|||
{ |
|||
(await _scopeRepository.GetCountAsync()).ShouldBe(2); |
|||
(await _scopeRepository.GetCountAsync(filter: _testData.Scope1Name)).ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync() |
|||
{ |
|||
var scope = await _scopeRepository.FindByIdAsync(_testData.Scope1Id); |
|||
|
|||
scope.ShouldNotBeNull(); |
|||
scope.Id.ShouldBe(_testData.Scope1Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByNameAsync() |
|||
{ |
|||
var scope = await _scopeRepository.FindByNameAsync(_testData.Scope1Name); |
|||
|
|||
scope.ShouldNotBeNull(); |
|||
scope.Name.ShouldBe(_testData.Scope1Name); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByNamesAsync() |
|||
{ |
|||
(await _scopeRepository.FindByNamesAsync(new []{_testData.Scope1Name, _testData.Scope2Name})).Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByResourceAsync() |
|||
{ |
|||
(await _scopeRepository.FindByResourceAsync("TestScope1Resource")).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ListAsync() |
|||
{ |
|||
(await _scopeRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(2); |
|||
(await _scopeRepository.ListAsync(int.MaxValue, 2)).Count.ShouldBe(0); |
|||
} |
|||
} |
|||
@ -0,0 +1,104 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using OpenIddict.Abstractions; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.OpenIddict.Tokens; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public abstract class OpenIddictTokenRepository_Tests<TStartupModule> : OpenIddictTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly IOpenIddictTokenRepository _tokenRepository; |
|||
private readonly AbpOpenIddictTestData _testData; |
|||
|
|||
public OpenIddictTokenRepository_Tests() |
|||
{ |
|||
_tokenRepository = GetRequiredService<IOpenIddictTokenRepository>(); |
|||
_testData = GetRequiredService<AbpOpenIddictTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteManyByApplicationIdAsync() |
|||
{ |
|||
await _tokenRepository.DeleteManyByApplicationIdAsync(new Guid()); |
|||
(await _tokenRepository.GetCountAsync()).ShouldBe(2); |
|||
|
|||
await _tokenRepository.DeleteManyByApplicationIdAsync(_testData.App1Id); |
|||
(await _tokenRepository.GetCountAsync()).ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteManyByAuthorizationIdAsync() |
|||
{ |
|||
await _tokenRepository.DeleteManyByAuthorizationIdAsync(new Guid()); |
|||
(await _tokenRepository.GetCountAsync()).ShouldBe(2); |
|||
|
|||
await _tokenRepository.DeleteManyByAuthorizationIdAsync(_testData.Authorization1Id); |
|||
(await _tokenRepository.GetCountAsync()).ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync() |
|||
{ |
|||
(await _tokenRepository.FindAsync("TestSubject1", new Guid())).Count.ShouldBe(0); |
|||
(await _tokenRepository.FindAsync("TestSubject1", _testData.App1Id)).Count.ShouldBe(1); |
|||
(await _tokenRepository.FindAsync("TestSubject1", _testData.App1Id, "NonExistsStatus")).Count.ShouldBe(0); |
|||
(await _tokenRepository.FindAsync("TestSubject1", _testData.App1Id, OpenIddictConstants.Statuses.Redeemed)).Count.ShouldBe(1); |
|||
(await _tokenRepository.FindAsync("TestSubject1", _testData.App1Id, OpenIddictConstants.Statuses.Redeemed, "NonExistsType")).Count.ShouldBe(0); |
|||
(await _tokenRepository.FindAsync("TestSubject1", _testData.App1Id, OpenIddictConstants.Statuses.Redeemed, "TestType1")).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByApplicationIdAsync() |
|||
{ |
|||
(await _tokenRepository.FindByApplicationIdAsync(_testData.App1Id)).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByAuthorizationIdAsync() |
|||
{ |
|||
(await _tokenRepository.FindByAuthorizationIdAsync(_testData.Authorization1Id)).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync() |
|||
{ |
|||
var token = await _tokenRepository.FindByIdAsync(_testData.Token1Id); |
|||
|
|||
token.ShouldNotBeNull(); |
|||
token.Id.ShouldBe(_testData.Token1Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByReferenceIdAsync() |
|||
{ |
|||
var token = await _tokenRepository.FindByIdAsync(_testData.Token1Id); |
|||
token = await _tokenRepository.FindByReferenceIdAsync(token.ReferenceId); |
|||
|
|||
token.ShouldNotBeNull(); |
|||
token.ReferenceId.ShouldBe(token.ReferenceId); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindBySubjectAsync() |
|||
{ |
|||
(await _tokenRepository.FindBySubjectAsync("TestSubject1")).Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ListAsync() |
|||
{ |
|||
(await _tokenRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(2); |
|||
(await _tokenRepository.ListAsync(int.MaxValue, 2)).Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetPruneListAsync() |
|||
{ |
|||
var threshold = DateTime.UtcNow - TimeSpan.FromDays(14); |
|||
(await _tokenRepository.GetPruneListAsync(threshold, int.MaxValue)).Count.ShouldBe(1); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue