mirror of https://github.com/abpframework/abp.git
11 changed files with 225 additions and 4 deletions
@ -0,0 +1,21 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.1</TargetFramework> |
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
|||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.1.0" /> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Blogging.EntityFrameworkCore\Volo.Blogging.EntityFrameworkCore.csproj" /> |
|||
<ProjectReference Include="..\Volo.Blogging.TestBase\Volo.Blogging.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Blogging.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Blogging.Blogs |
|||
{ |
|||
public class BlogRepository_Tests : BlogRepository_Tests<BloggingEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
using Microsoft.Data.Sqlite; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Storage; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Blogging.EntityFrameworkCore.Volo.Blogging.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Blogging.EntityFrameworkCore |
|||
{ |
|||
[DependsOn( |
|||
typeof(BloggingEntityFrameworkCoreModule), |
|||
typeof(BloggingTestBaseModule) |
|||
)] |
|||
public class BloggingEntityFrameworkCoreTestModule : AbpModule |
|||
{ |
|||
private SqliteConnection _sqliteConnection; |
|||
|
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
_sqliteConnection = CreateDatabaseAndGetConnection(); |
|||
|
|||
services.Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.Configure(context => |
|||
{ |
|||
context.DbContextOptions.UseSqlite(_sqliteConnection); |
|||
}); |
|||
}); |
|||
|
|||
services.AddAssemblyOf<BloggingEntityFrameworkCoreTestModule>(); |
|||
} |
|||
|
|||
private static SqliteConnection CreateDatabaseAndGetConnection() |
|||
{ |
|||
var connection = new SqliteConnection("Data Source=:memory:"); |
|||
connection.Open(); |
|||
|
|||
var options = new DbContextOptionsBuilder<BloggingDbContext>().UseSqlite(connection).Options; |
|||
using (var context = new BloggingDbContext(options)) |
|||
{ |
|||
context.GetService<IRelationalDatabaseCreator>().CreateTables(); |
|||
} |
|||
|
|||
return connection; |
|||
} |
|||
|
|||
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
|||
{ |
|||
_sqliteConnection.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.1</TargetFramework> |
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Blogging.Domain\Volo.Blogging.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
|||
<PackageReference Include="NSubstitute" Version="3.1.0" /> |
|||
<PackageReference Include="Shouldly" Version="3.0.0" /> |
|||
<PackageReference Include="xunit" Version="2.3.1" /> |
|||
<PackageReference Include="xunit.extensibility.execution" Version="2.3.1" /> |
|||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,27 @@ |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using NSubstitute; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public abstract class BloggingTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected Guid? CurrentUserId { get; set; } |
|||
|
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
|
|||
protected override void AfterAddApplication(IServiceCollection services) |
|||
{ |
|||
var currentUser = Substitute.For<ICurrentUser>(); |
|||
currentUser.Id.Returns(ci => CurrentUserId); |
|||
services.AddSingleton(currentUser); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
[DependsOn( |
|||
typeof(BloggingDomainModule), |
|||
typeof(AbpTestBaseModule), |
|||
typeof(AbpAutofacModule) |
|||
)] |
|||
public class BloggingTestBaseModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<BloggingTestBaseModule>(); |
|||
} |
|||
|
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
SeedTestData(context); |
|||
} |
|||
|
|||
private static void SeedTestData(ApplicationInitializationContext context) |
|||
{ |
|||
using (var scope = context.ServiceProvider.CreateScope()) |
|||
{ |
|||
scope.ServiceProvider |
|||
.GetRequiredService<BloggingTestDataBuilder>() |
|||
.Build(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class BloggingTestDataBuilder : ITransientDependency |
|||
{ |
|||
public void Build() |
|||
{ |
|||
//TODO
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging.Blogs |
|||
{ |
|||
public abstract class BlogRepository_Tests<TStartupModule> : BloggingTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected IBlogRepository BlogRepository { get; } |
|||
|
|||
protected BlogRepository_Tests() |
|||
{ |
|||
BlogRepository = GetRequiredService<IBlogRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByShortNameAsync_Temp() |
|||
{ |
|||
var blog = await BlogRepository.FindByShortNameAsync("default"); |
|||
blog.ShouldBeNull(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue