コード例 #1
0
        public void TestOnChangeUserAccountStatus()
        {
            bool   success  = true;
            string userName = "******" + Guid.NewGuid();

            var mockAuditLog = new Mock <IAuditLog>(MockBehavior.Strict);

            mockAuditLog.Setup(al => al.OnChangeUserAccountStatus(success, userName, UserAccountStatusEnum_Enumeration.Active.ToString(), UserAccountStatusEnum_Enumeration.Disabled.ToString()));

            var eventTarget = new AuditLogUserAccountEventTarget(mockAuditLog.Object);

            var user = new UserAccount {
                Name = userName
            };

            user.AccountStatus_Enum = UserAccountStatusEnum_Enumeration.Active;
            user.Save();

            user.AccountStatus_Enum = UserAccountStatusEnum_Enumeration.Disabled;

            IDictionary <string, object> state = new Dictionary <string, object>();

            eventTarget.GatherAuditLogEntityDetailsForSave(user, state);
            eventTarget.WriteSaveAuditLogEntries(success, user.Id, state);

            mockAuditLog.VerifyAll();
        }
コード例 #2
0
        public void TestOnChangeUserAccountPassword()
        {
            bool   success  = true;
            string userName = "******" + Guid.NewGuid();

            var mockAuditLog = new Mock <IAuditLog>(MockBehavior.Strict);

            mockAuditLog.Setup(al => al.OnChangeUserAccountPassword(success, userName));

            var eventTarget = new AuditLogUserAccountEventTarget(mockAuditLog.Object);

            var user = new UserAccount {
                Name = userName
            };

            user.Password = "******";
            user.Save();

            user.Password = "******";

            IDictionary <string, object> state = new Dictionary <string, object>();

            eventTarget.GatherAuditLogEntityDetailsForSave(user, state);
            eventTarget.WriteSaveAuditLogEntries(success, user.Id, state);

            mockAuditLog.VerifyAll();
        }
コード例 #3
0
        public void TestOnChangeUserAccountExpiry()
        {
            bool     success           = true;
            string   userName          = "******" + Guid.NewGuid();
            DateTime oldExpirationDate = DateTime.UtcNow;
            DateTime newExpirationDate = DateTime.UtcNow.AddDays(1);

            var mockAuditLog = new Mock <IAuditLog>(MockBehavior.Strict);

            mockAuditLog.Setup(al => al.OnChangeUserAccountExpiry(success, userName, oldExpirationDate, newExpirationDate));

            var eventTarget = new AuditLogUserAccountEventTarget(mockAuditLog.Object);

            var user = new UserAccount {
                Name = userName
            };

            user.AccountExpiration = oldExpirationDate;
            user.Save();

            user.AccountExpiration = newExpirationDate;

            IDictionary <string, object> state = new Dictionary <string, object>();

            eventTarget.GatherAuditLogEntityDetailsForSave(user, state);
            eventTarget.WriteSaveAuditLogEntries(success, user.Id, state);

            mockAuditLog.VerifyAll();
        }
コード例 #4
0
        /// <summary>
        ///     Called after saving of the specified enumeration of entities has taken place.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <param name="state">The state.</param>
        public void OnAfterSave(IEnumerable <IEntity> entities, IDictionary <string, object> state)
        {
            if (entities == null)
            {
                return;
            }

            object invalidObjects;

            foreach (long entityId in entities.Select(e => e.Id))
            {
                _auditLogEventTarget.WriteSaveAuditLogEntries(true, entityId, state);
            }

            /////
            // Invalidate the changed users in that role.
            /////
            if (state.TryGetValue(InvalidRolesKey, out invalidObjects))
            {
                if (invalidObjects != null)
                {
                    // ResolveInvalidObjects(invalidObjects as ISet<long>, invalidRole => EntityAccessControlCacheInvalidator.InvalidateRole(new EntityRef(invalidRole)));
                }

                state.Remove(InvalidRolesKey);
            }

            /////
            // Invalidate the changed permission grants for that role.
            /////
            if (state.TryGetValue(InvalidPermissionsKey, out invalidObjects))
            {
                if (invalidObjects != null)
                {
                    // ResolveInvalidObjects(invalidObjects as ISet<long>, invalidPermission => EntityAccessControlCacheInvalidator.InvalidatePermission(new EntityRef(invalidPermission)));
                }

                state.Remove(InvalidPermissionsKey);
            }
        }
コード例 #5
0
        public void TestOnChangeUserRoleMembers()
        {
            bool   success   = true;
            string userName  = "******" + Guid.NewGuid();
            string roleName1 = "Role1" + Guid.NewGuid();
            string roleName2 = "Role2" + Guid.NewGuid();

            ISet <string> addedMembers = new SortedSet <string> {
                userName
            };

            var mockAuditLog = new Mock <IAuditLog>(MockBehavior.Strict);

            mockAuditLog.Setup(al => al.OnChangeUserRoleMembers(success, roleName1, It.Is <ISet <string> >(m => m.Count <= 0), It.Is <ISet <string> >(m => m.SetEquals(addedMembers))));

            mockAuditLog.Setup(al => al.OnChangeUserRoleMembers(success, roleName2, It.Is <ISet <string> >(m => m.SetEquals(addedMembers)), It.Is <ISet <string> >(m => m.Count <= 0)));

            var eventTarget = new AuditLogUserAccountEventTarget(mockAuditLog.Object);

            var role1 = new Role {
                Name = roleName1
            };
            var role2 = new Role {
                Name = roleName2
            };

            var user = new UserAccount {
                Name = userName
            };

            user.UserHasRole.Add(role1);
            user.Save();

            user.UserHasRole.Remove(role1);
            user.UserHasRole.Add(role2);

            IDictionary <string, object> state = new Dictionary <string, object>();

            eventTarget.GatherAuditLogEntityDetailsForSave(user, state);
            eventTarget.WriteSaveAuditLogEntries(success, user.Id, state);

            mockAuditLog.VerifyAll();
        }