mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Adding SpecFlow bindings for integration testing user's permissions
Enables automated testing of urls and redirects with querystring Adds bindings for: -Creating account with a fixed set of permissions -Login of a user -Success criteria for seeing text on a page -Success criteria for being denied access to a page --HG-- branch : dev extra : rebase_source : 66e7b33cf7a596050d27eda6351605ed86420af2
This commit is contained in:
@@ -15,41 +15,6 @@ namespace Orchard.Specs.Bindings {
|
||||
[Binding]
|
||||
public class ContentRights : BindingBase {
|
||||
|
||||
[When(@"I have a role ""(.*)\"" with permissions ""(.*)\""")]
|
||||
public void WhenIHaveARoleWithPermissions(string roleName, string permissions) {
|
||||
var webApp = Binding<WebAppHosting>();
|
||||
webApp.Host.Execute(() => {
|
||||
using ( var environment = MvcApplication.CreateStandaloneEnvironment("Default") ) {
|
||||
var roleService = environment.Resolve<IRoleService>();
|
||||
|
||||
roleService.CreateRole(roleName);
|
||||
|
||||
foreach ( var permissionName in permissions.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries) ) {
|
||||
roleService.CreatePermissionForRole(roleName, permissionName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[When(@"I have a user ""(.*)\"" with roles ""(.*)\""")]
|
||||
public void GivenIHaveCreatedAUser(string username, string roles) {
|
||||
|
||||
var webApp = Binding<WebAppHosting>();
|
||||
webApp.Host.Execute(() => {
|
||||
using ( var environment = MvcApplication.CreateStandaloneEnvironment("Default") ) {
|
||||
var memberShipService = environment.Resolve<IMembershipService>();
|
||||
var roleService = environment.Resolve<IRoleService>();
|
||||
var userRoleRepository = environment.Resolve<IRepository<UserRolesPartRecord>>();
|
||||
var user = memberShipService.CreateUser(new CreateUserParams(username, "qwerty123!", username + "@foo.com", "", "", true));
|
||||
|
||||
foreach ( var roleName in roles.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries) ) {
|
||||
var role = roleService.GetRoleByName(roleName);
|
||||
userRoleRepository.Create(new UserRolesPartRecord { UserId = user.Id, Role = role });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Then(@"""(.*)\"" should be able to ""(.*)\"" a ""(.*)\"" owned by ""(.*)\""")]
|
||||
public void UserShouldBeAbleToForOthers(string username, string action, string contentType, string otherName) {
|
||||
|
||||
|
Reference in New Issue
Block a user