Refactored Identity tests and fixed ProxyHelper

pull/208/head
Halil İbrahim Kalkan 8 years ago
parent 4f1e692757
commit 421ca9a38e

@ -7,18 +7,17 @@ namespace Volo.Abp.DynamicProxy
{
/// <summary>
/// Returns dynamic proxy target object if this is a proxied object, otherwise returns the given object.
/// It supports Castle Dynamic Proxies.
/// </summary>
public static object UnProxy(object obj)
{
//TODO: This code depends on Castle, so we should find a better way.
if (obj.GetType().Namespace != "Castle.Proxies")
{
return obj;
}
var targetField = obj.GetType().GetTypeInfo()
.GetFields()
var targetField = obj.GetType()
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
.FirstOrDefault(f => f.Name == "__target");
if (targetField == null)

@ -16,6 +16,7 @@
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Identity.Application\Volo.Abp.Identity.Application.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Identity.EntityFrameworkCore\Volo.Abp.Identity.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Volo.Abp.Identity.Tests\Volo.Abp.Identity.Tests.csproj" />
</ItemGroup>
<ItemGroup>

@ -1,12 +1,7 @@
using Volo.Abp.TestBase;
namespace Volo.Abp.Identity
namespace Volo.Abp.Identity
{
public class AbpIdentityApplicationTestBase : AbpIntegratedTest<AbpIdentityApplicationTestModule>
public class AbpIdentityApplicationTestBase : AbpIdentityCommonTestBase<AbpIdentityApplicationTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

@ -1,55 +1,20 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
namespace Volo.Abp.Identity
{
[DependsOn(
typeof(AbpIdentityApplicationModule),
typeof(AbpIdentityEntityFrameworkCoreModule),
typeof(AbpAutofacModule))]
typeof(AbpAutofacModule),
typeof(AbpIdentityDomainTestModule))]
public class AbpIdentityApplicationTestModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<AbpIdentityApplicationTestModule>();
services.AddEntityFrameworkInMemoryDatabase();
var databaseName = Guid.NewGuid().ToString();
services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(context =>
{
context.DbContextOptions.UseInMemoryDatabase(databaseName);
});
});
services.Configure<UnitOfWorkDefaultOptions>(options =>
{
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
private static void SeedTestData(ApplicationInitializationContext context)
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
.GetRequiredService<AbpIdentityTestDataBuilder>()
.Build();
}
}
}
}

@ -12,6 +12,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Identity.Domain\Volo.Abp.Identity.Domain.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Identity.EntityFrameworkCore\Volo.Abp.Identity.EntityFrameworkCore.csproj" />

@ -0,0 +1,14 @@
using Volo.Abp.Modularity;
using Volo.Abp.TestBase;
namespace Volo.Abp.Identity
{
public abstract class AbpIdentityCommonTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

@ -0,0 +1,7 @@
namespace Volo.Abp.Identity
{
public abstract class AbpIdentityDomainTestBase : AbpIdentityCommonTestBase<AbpIdentityDomainTestModule>
{
}
}

@ -0,0 +1,55 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
namespace Volo.Abp.Identity
{
[DependsOn(
typeof(AbpIdentityDomainModule),
typeof(AbpIdentityEntityFrameworkCoreModule),
typeof(AbpAutofacModule))]
public class AbpIdentityDomainTestModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddEntityFrameworkInMemoryDatabase();
var databaseName = Guid.NewGuid().ToString();
services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(context =>
{
context.DbContextOptions.UseInMemoryDatabase(databaseName);
});
});
services.Configure<UnitOfWorkDefaultOptions>(options =>
{
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
});
services.AddAssemblyOf<AbpIdentityDomainTestModule>();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
private static void SeedTestData(ApplicationInitializationContext context)
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
.GetRequiredService<AbpIdentityTestDataBuilder>()
.Build();
}
}
}
}

@ -1,32 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Modularity;
namespace Volo.Abp.Identity
{
[DependsOn(typeof(AbpIdentityDomainModule), typeof(AbpIdentityEntityFrameworkCoreModule))]
public class AbpIdentityTestModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddEntityFrameworkInMemoryDatabase();
services.Configure<DbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = Guid.NewGuid().ToString();
});
services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(context =>
{
context.DbContextOptions.UseInMemoryDatabase(context.ConnectionString);
});
});
}
}
}

@ -2,12 +2,12 @@
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.TestBase;
using Volo.Abp.DynamicProxy;
using Xunit;
namespace Volo.Abp.Identity
{
public class Initialize_Tests : AbpIntegratedTest<AbpIdentityTestModule>
public class Identity_Repository_Resolve_Tests : AbpIdentityDomainTestBase
{
[Fact]
public void Should_Resolve_UserManager()
@ -24,12 +24,13 @@ namespace Volo.Abp.Identity
[Fact] //Move this test to Volo.Abp.EntityFrameworkCore.Tests since it's actually testing the EF Core repository registration!
public void Should_Resolve_Repositories()
{
(ServiceProvider.GetRequiredService<IIdentityUserRepository>() is EfCoreIdentityUserRepository).ShouldBeTrue();
var x = ServiceProvider.GetRequiredService<IIdentityUserRepository>();
(ProxyHelper.UnProxy(ServiceProvider.GetRequiredService<IIdentityUserRepository>()) is EfCoreIdentityUserRepository).ShouldBeTrue();
(ServiceProvider.GetRequiredService<IBasicRepository<IdentityUser, Guid>>() is EfCoreIdentityUserRepository).ShouldBeTrue();
(ProxyHelper.UnProxy(ServiceProvider.GetRequiredService<IBasicRepository<IdentityUser, Guid>>()) is EfCoreIdentityUserRepository).ShouldBeTrue();
//(ServiceProvider.GetRequiredService<IRepository<IdentityUser>>() is EfCoreIdentityUserRepository).ShouldBeTrue();
(ServiceProvider.GetRequiredService<IRepository<IdentityUser, Guid>>() is EfCoreIdentityUserRepository).ShouldBeTrue();
(ProxyHelper.UnProxy(ServiceProvider.GetRequiredService<IRepository<IdentityUser, Guid>>()) is EfCoreIdentityUserRepository).ShouldBeTrue();
//(ServiceProvider.GetRequiredService<IQueryableRepository<IdentityUser>>() is EfCoreIdentityUserRepository).ShouldBeTrue();
}
}

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.Identity
{
public class PermissionManager_Tests
{
}
}
Loading…
Cancel
Save