Exemple #1
0
        /// <summary>
        ///     Called if a failure occurs saving the specified entities.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <param name="state">The state passed between the before save and after save callbacks.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void OnSaveFailed(IEnumerable <IEntity> entities, IDictionary <string, object> state)
        {
            if (entities == null)
            {
                return;
            }

            foreach (long entity in entities.Select(e => e.Id))
            {
                _auditLogEventTarget.WriteSaveAuditLogEntries(false, entity, state);
            }
        }
        public void TestOnChangePasswordPolicy()
        {
            bool success = true;

            const int  oldMinPasswordLength         = 15;
            const int  newMinPasswordLength         = 16;
            const int  oldMaxPasswordAge            = 10;
            const int  newMaxPasswordAge            = 11;
            const bool oldMustContainUpperCaseChars = true;
            const bool newMustContainUpperCaseChars = false;
            const bool oldMustContainLowerCaseChars = true;
            const bool newMustContainLowerCaseChars = false;
            const bool oldMustContainDigits         = true;
            const bool newMustContainDigits         = false;
            const bool oldMustContainSpecialChars   = true;
            const bool newMustContainSpecialChars   = false;
            const int  oldAccountLockoutDuration    = 22;
            const int  newAccountLockoutDuration    = 23;
            const int  oldAccountLockoutThreshold   = 32;
            const int  newAccountLockoutThreshold   = 33;

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

            mockAuditLog.Setup(al => al.OnChangePasswordPolicy(success,
                                                               oldMinPasswordLength,
                                                               newMinPasswordLength,
                                                               oldMaxPasswordAge,
                                                               newMaxPasswordAge,
                                                               oldMustContainUpperCaseChars,
                                                               newMustContainUpperCaseChars,
                                                               oldMustContainLowerCaseChars,
                                                               newMustContainLowerCaseChars,
                                                               oldMustContainDigits,
                                                               newMustContainDigits,
                                                               oldMustContainSpecialChars,
                                                               newMustContainSpecialChars,
                                                               oldAccountLockoutDuration,
                                                               newAccountLockoutDuration,
                                                               oldAccountLockoutThreshold,
                                                               newAccountLockoutThreshold));

            var eventTarget = new AuditLogPasswordPolicyEventTarget(mockAuditLog.Object);

            var passwordPolicy = new PasswordPolicy
            {
                MaximumPasswordAge             = oldMaxPasswordAge,
                MinimumPasswordLength          = oldMinPasswordLength,
                MustContainDigits              = oldMustContainDigits,
                MustContainLowerCaseCharacters = oldMustContainLowerCaseChars,
                MustContainSpecialCharacters   = oldMustContainSpecialChars,
                MustContainUpperCaseCharacters = oldMustContainUpperCaseChars,
                AccountLockoutDuration         = oldAccountLockoutDuration,
                AccountLockoutThreshold        = oldAccountLockoutThreshold
            };

            passwordPolicy.Save();

            passwordPolicy.MaximumPasswordAge             = newMaxPasswordAge;
            passwordPolicy.MinimumPasswordLength          = newMinPasswordLength;
            passwordPolicy.MustContainDigits              = newMustContainDigits;
            passwordPolicy.MustContainLowerCaseCharacters = newMustContainLowerCaseChars;
            passwordPolicy.MustContainSpecialCharacters   = newMustContainSpecialChars;
            passwordPolicy.MustContainUpperCaseCharacters = newMustContainUpperCaseChars;
            passwordPolicy.AccountLockoutDuration         = newAccountLockoutDuration;
            passwordPolicy.AccountLockoutThreshold        = newAccountLockoutThreshold;

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

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

            mockAuditLog.VerifyAll();
        }