mirror of https://github.com/abpframework/abp.git
8 changed files with 233 additions and 1 deletions
@ -0,0 +1,26 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests |
||||
|
{ |
||||
|
public class Program |
||||
|
{ |
||||
|
public static void Main(string[] args) |
||||
|
{ |
||||
|
CreateHostBuilder(args).Build().Run(); |
||||
|
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureWebHostDefaults(webBuilder => |
||||
|
{ |
||||
|
webBuilder.UseStartup<Startup>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
{ |
||||
|
"iisSettings": { |
||||
|
"windowsAuthentication": false, |
||||
|
"anonymousAuthentication": true, |
||||
|
"iisExpress": { |
||||
|
"applicationUrl": "http://localhost:56574", |
||||
|
"sslPort": 44374 |
||||
|
} |
||||
|
}, |
||||
|
"profiles": { |
||||
|
"IIS Express": { |
||||
|
"commandName": "IISExpress", |
||||
|
"launchBrowser": true, |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
}, |
||||
|
"Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests": { |
||||
|
"commandName": "Project", |
||||
|
"launchBrowser": true, |
||||
|
"applicationUrl": "https://localhost:5001;http://localhost:5000", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.AspNetCore.TestBase\Volo.Abp.AspNetCore.TestBase.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.Core\Volo.Abp.Core.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.AspNetCore.Tests\Volo.Abp.AspNetCore.Tests.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,6 @@ |
|||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared |
||||
|
{ |
||||
|
public class AbpAspNetCoreMvcUiThemeSharedTestBase : AbpAspNetCoreTestBase<Startup> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
using Volo.Abp.AspNetCore.TestBase; |
||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpAutofacModule), |
||||
|
typeof(AbpAspNetCoreTestBaseModule), |
||||
|
typeof(AbpAspNetCoreMvcUiThemeSharedModule) |
||||
|
)] |
||||
|
public class AbpAspNetCoreMvcUiThemeSharedTestModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,113 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpPageToolbar.Button; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.PageToolbars; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.PageToolbars |
||||
|
{ |
||||
|
public class PageToolbar_Tests : AbpAspNetCoreMvcUiThemeSharedTestBase |
||||
|
{ |
||||
|
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) |
||||
|
{ |
||||
|
services.Configure<AbpPageToolbarOptions>(options => |
||||
|
{ |
||||
|
options.Configure("TestPage1", toolbar => |
||||
|
{ |
||||
|
toolbar.Contributors.Add(new MyToolbarContributor()); |
||||
|
toolbar.Contributors.Add(new MyToolbarContributor2()); |
||||
|
toolbar.AddComponent<MyPageComponent5>(); |
||||
|
toolbar.AddButton(new FixedLocalizableString("My button"), order: -1); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void AbpPageToolbarOptions_Should_Contain_Contributors() |
||||
|
{ |
||||
|
var options = GetRequiredService<IOptions<AbpPageToolbarOptions>>().Value; |
||||
|
options.Toolbars.Count.ShouldBe(1); |
||||
|
options.Toolbars.ShouldContainKey("TestPage1"); |
||||
|
options.Toolbars["TestPage1"].Contributors.Count.ShouldBe(4); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task PageToolbarManager_Should_Return_ToolbarItems() |
||||
|
{ |
||||
|
var pageToolbarManager = GetRequiredService<IPageToolbarManager>(); |
||||
|
var items = await pageToolbarManager.GetItemsAsync("TestPage1"); |
||||
|
items.Length.ShouldBe(5); |
||||
|
items[0].ComponentType.ShouldBe(typeof(AbpPageToolbarButtonViewComponent)); |
||||
|
items[1].ComponentType.ShouldBe(typeof(MyPageComponent2)); |
||||
|
items[2].ComponentType.ShouldBe(typeof(MyPageComponent3)); |
||||
|
items[3].ComponentType.ShouldBe(typeof(MyPageComponent4)); |
||||
|
items[4].ComponentType.ShouldBe(typeof(MyPageComponent5)); |
||||
|
} |
||||
|
|
||||
|
public class MyToolbarContributor : IPageToolbarContributor |
||||
|
{ |
||||
|
public Task ContributeAsync(PageToolbarContributionContext context) |
||||
|
{ |
||||
|
context.Items.Add(new PageToolbarItem(typeof(MyPageComponent1))); |
||||
|
context.Items.Add(new PageToolbarItem(typeof(MyPageComponent2))); |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class MyToolbarContributor2 : IPageToolbarContributor |
||||
|
{ |
||||
|
public Task ContributeAsync(PageToolbarContributionContext context) |
||||
|
{ |
||||
|
context.Items.RemoveAll(i => i.ComponentType == typeof(MyPageComponent1)); |
||||
|
context.Items.Add(new PageToolbarItem(typeof(MyPageComponent3))); |
||||
|
context.Items.Add(new PageToolbarItem(typeof(MyPageComponent4))); |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class MyPageComponent1 : AbpViewComponent |
||||
|
{ |
||||
|
public IViewComponentResult InvokeAsync() |
||||
|
{ |
||||
|
return Content("MyPageComponent1"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class MyPageComponent2 : AbpViewComponent |
||||
|
{ |
||||
|
public IViewComponentResult InvokeAsync() |
||||
|
{ |
||||
|
return Content("MyPageComponent2"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class MyPageComponent3 : AbpViewComponent |
||||
|
{ |
||||
|
public IViewComponentResult InvokeAsync() |
||||
|
{ |
||||
|
return Content("MyPageComponent3"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class MyPageComponent4 : AbpViewComponent |
||||
|
{ |
||||
|
public IViewComponentResult InvokeAsync() |
||||
|
{ |
||||
|
return Content("MyPageComponent4"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class MyPageComponent5 : AbpViewComponent |
||||
|
{ |
||||
|
public IViewComponentResult InvokeAsync() |
||||
|
{ |
||||
|
return Content("MyPageComponent4"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared |
||||
|
{ |
||||
|
public class Startup |
||||
|
{ |
||||
|
public void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
services.AddApplication<AbpAspNetCoreMvcUiThemeSharedTestModule>(); |
||||
|
} |
||||
|
|
||||
|
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |
||||
|
{ |
||||
|
app.InitializeApplication(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue