Beispiel #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();
        }
Beispiel #2
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();
        }
Beispiel #3
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();
        }
Beispiel #4
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();
        }