/// <summary>Can delete activity.</summary>
        public virtual void CanDeleteActivityRole()
        {
            var role = new IdentityRoleEntity
            {
                ApplicationId  = 0,
                Description    = "MyRole",
                Identifier     = Guid.NewGuid(),
                NormalizedName = "myrole",
                Name           = "MyRole"
            };

            using (var iUow = _identityDataService.StartUnitOfWork())
            {
                role = iUow.RoleRepository.Add(role);
                iUow.Commit();
            }

            try
            {
                using (var uow = DataService.StartUnitOfWork())
                {
                    var activity = new ActivityEntity
                    {
                        Name                = "MyActivity",
                        ResourceName        = "MyResource",
                        ResourceDisplayName = "MyDisplayName",
                        GroupName           = "MyGroupName",
                        GroupDisplayName    = "MyGroupDisplayName"
                    };
                    activity = uow.ActivityRepository.Add(activity);

                    var aRole = new ActivityRoleEntity
                    {
                        ActivityId = activity.Id,
                        RoleId     = role.Id,
                        Allow      = true
                    };

                    uow.ActivityRoleRepository.Add(aRole);

                    aRole.Allow = false;
                    uow.ActivityRoleRepository.Delete(aRole);

                    Assert.AreEqual(null, uow.ActivityRoleRepository.Get(aRole.Id));
                }
            }
            finally
            {
                using (var iUow = _identityDataService.StartUnitOfWork())
                {
                    iUow.RoleRepository.Delete(role);
                    iUow.Commit();
                }
            }
        }
        /// <summary>   Saves an updated rights for. </summary>
        /// <param name="roleId">   Identifier for the role. </param>
        /// <param name="rights">   The rights. </param>
        private void SaveUpdatedRightsFor(int roleId, Dictionary <int, int> rights)
        {
            using (var uow = _authorizationDataService.StartUnitOfWork())
            {
                var existing = uow.ActivityRoleRepository.ByRole(roleId).ToList();
                foreach (var right in rights)
                {
                    var current = existing.SingleOrDefault(e => e.RoleId == roleId && e.ActivityId == right.Key);
                    if (current != null) // update or delete
                    {
                        if (right.Value != 0)
                        {
                            current.Allow = GetTristateValue(right.Value);
                            uow.ActivityRoleRepository.Update(current);
                        }

                        {
                            uow.ActivityRoleRepository.Delete(current);
                        }
                    }
                    else // create
                    {
                        if (right.Value != 0) // only for values other than "not defined"
                        {
                            var newEntry = new ActivityRoleEntity
                            {
                                ActivityId = right.Key,
                                RoleId     = roleId,
                                Allow      = GetTristateValue(right.Value)
                            };
                            uow.ActivityRoleRepository.Add(newEntry);
                        }
                    }
                }
                uow.Commit();
            }
        }