Hi,
I have an AuthorizationProvider, I injected the RoleManager into it, and in SetPermissions method, I used the RoleManager to grant some permissions to a role. The code is like this:
public class UserPermissionProvider : AuthorizationProvider
{
private readonly RoleManager _roleManager;
public UserPermissionProvider(RoleManager roleManager)
{
_roleManager = roleManager;
}
public override async void SetPermissions(IPermissionDefinitionContext context)
{
var somePermission = context.CreatePermission(...);
var someRole = _roleManager.GetRoleByNameAsync("SomeRole").Result;
_roleManager.GrantPermissionAsync(someRole, somePermission).Wait();
}
}
Everything is fine, until unit tests. I noticed that the SetPermission method is executed before seeding data code in my TestBase:
// SetPermission is executed event before the constructor method of TestBase!
protected XXXTestBase()
{
//Seed initial data
UsingDbContext(context => new InitialDataBuilder(context).Build());
LoginAsDefaultTenantAdmin();
}
As a result, there's no data, no "SomeRole" in the database, so the SetPermission method failed. How can I fix this problem?
Hi,
I wrote a VS extension to help with developing ABP application----ABPHelper. By now, ABPHelper has one feature:
Generate ApplicationService Methods Just input methods names, and click button, all the methods and DTO files will be generated.
You can install ABPHelper by using Extensions and Updates in Visual Studio. Or download it from Visual Studio Galleryand install it manullay.
Source code on github Any suggestion is welcome! :mrgreen:
Hi, I need to use the RoleManager in my AuthorizationProvider like this:
public class UserPermissionProvider : AuthorizationProvider
{
private readonly RoleManager _roleManager;
public UserPermissionProvider(RoleManager roleManager)
{
_roleManager = roleManager;
}
}
My app runs well as I expected, but when I run unit tests, all the tests failed. Here's the error message:
System.TypeInitializationException“Effort.DbConnectionFactory”的类型初始值设定项引发异常。 在 Effort.DbConnectionFactory.CreateTransient() 在 Castle.MicroKernel.ComponentActivator.FactoryMethodActivator
1.Instantiate(CreationContext context) 在 Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) 在 Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) 在 Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) 在 Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) 在 Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, ref Burden burden) 在 Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) 在 Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency) 在 Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) 在 Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) 在 Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) 在 Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) 在 Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) 在 Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) 在 Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) 在 Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, ref Burden burden) 在 Castle.MicroKernel.Handlers.ExtendedHandler.InvokeResolvePipeline(Int32 extensionIndex, ResolveInvocation invocation) 在 Castle.MicroKernel.Handlers.ComponentLifecycleExtension.Intercept(ResolveInvocation invocation) 在 Castle.MicroKernel.Handlers.ExtendedHandler.InvokeResolvePipeline(Int32 extensionIndex, ResolveInvocation invocation) 在 Castle.MicroKernel.Handlers.ExtendedHandler.Resolve(CreationContext context, Boolean instanceRequired) 在 Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy) 在 Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) 在 Castle.Windsor.WindsorContainer.Resolve() 在 BMS.Tests.BMSTestBase.UsingDbContext(Action
1 action) 位置 BMSTestBase.cs: line 49 在 BMS.Tests.BMSTestBase..ctor() 位置 BMSTestBase.cs: line 32 在 BMS.Tests.Users.RoleAppServiceTests..ctor() 位置 RoleAppServiceTests.cs: line 11 Effort.Exceptions.EffortExceptionThe Effort library failed to register its provider automatically, so manual registration is required.a) Call the Effort.Provider.EffortProviderConfiguration.RegisterProvider() method at entry point of the application
or
b) Add the following configuration to the App.config file: <system.data> <DbProviderFactories> <add name="Effort.Provider" > invariant="Effort.Provider" description="Effort.Provider" type="Effort.Provider.EffortProviderFactory, Effort" /> </DbProviderFactories> </system.data>
<entityFramework> <providers> <provider invariantName="Effort.Provider" > type="Effort.Provider.EffortProviderServices, Effort" /> </providers> </entityFramework> 在 Effort.Provider.EffortProviderConfiguration.RegisterDbConfigurationEventHandler() 在 Effort.Provider.EffortProviderConfiguration.RegisterProvider() 在 Effort.DbConnectionFactory..cctor() System.InvalidOperationExceptionThe Entity Framework was already using a DbConfiguration instance before an attempt was made to add an 'Loaded' event handler. 'Loaded' event handlers can only be added as part of application start up before the Entity Framework is used. See <a class="postlink" href="http://go.microsoft.com/fwlink/?LinkId=260883">http://go.microsoft.com/fwlink/?LinkId=260883</a> for more information. 在 System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.AddLoadedHandler(EventHandler`1 handler) 在 Effort.Provider.EffortProviderConfiguration.RegisterDbConfigurationEventHandler()
(sorry for the Chinese...)
It seems that unit tests can not inject the RoleManager to my AuthorizationProvider, how to solve it?
Some question about sample-blog-module
Hi, this is my first post, I’m Chinese, so forgive my English. Firstly, thank hikalkan for providing ABP framework, it’s awesome!
Recently I found sample-blog-module, I’m always interesting in module system of ABP, so I started to study it. However I encounter some questions:
Thank you.