Testing app-services for features that are not enabled by default #8148
8.0.0, Angular, .NET Core
I stumbled accross the following error when trying to run tests I built for one of my app-services:
Required permissions are not granted. At least one of these permissions must be granted: PermissionName
Couldn't find an answer here.
After a couple of hours searching for a solution to this problem it began to dawn on me:
Permissions for this service are dependent on a feature that is not enabled by default (
defaultValue: false in
Enabling it by default solved the problem as expected.
Now I have the following question:
I don't want certain features to be enabled by default but still want to test the app-services - Is there a simple solution to this problem without having to manually change the
defaulValue for each feature?
The Code for my app-services and tests really isn't anything special - just some simple gets, creates, edits and deletes - and as I wrote before: this stuff is working as expected as soon as I enable the according feature the permission depends on by default (
defaultValue: true). Before, my tests failed just because the DefaultTenant didn't have these features assigned and therefore didn't have the necessary permissions.
What I would like to know is, how do I assign a certain feature to a tenant in my tests (something similar to
LoginAsDefaultTenantAdmin())? I guess, right now there is no simple way to do this. But maybe you guys have some ideas on how to do this? Also, I think it would be a good addition for ASPNETZERO as a product.
TenantManagerdomain service I can add the following to my test-class constructor:
var tenantManager = Resolve<TenantManager>(); tenantManager.SetFeatureValue(GetCurrentTenant().Id, "FeatureName", "Value");
So, this actually seems to be the solution to my problem : )
~~But I don't know if this change will be persisted for longer than just for the test run. And I can't figure out where this information is stored ... Any ideas?~~
Edit Changes won't be persisted for longer than for the run of the test itself. So, this is the way to go : )