예제 #1
0
        /// <summary>
        ///   Provides a basic sanity check that a change item is well formed.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="context">The context.</param>
        /// <returns>
        ///   <see cref="P:System.ComponentModel.DataAnnotations.ValidationResult.Success"/>
        ///   if the change is valid; otherwise, a ValidationResult
        ///   denoting the reason the change failed validation.
        /// </returns>
        public static ValidationResult SanityCheck(ChangeItem item, ValidationContext context)
        {
            switch (item.Action)
            {
                case ChangeAction.Create:
                    if (item.GetBFIM() != null)
                        return new ValidationResult("BFIM not permitted for new entries.", new[] { "BFIM" });
                    if (item.GetAFIM() == null)
                        return new ValidationResult("AFIM required for new entries.", new[] { "AFIM" });
                    break;

                case ChangeAction.Update:
                    if (item.GetBFIM() == null)
                        return new ValidationResult("BFIM required for update entries.", new[] { "BFIM" });
                    if (item.GetAFIM() == null)
                        return new ValidationResult("AFIM required for update entries.", new[] { "AFIM" });
                    break;

                case ChangeAction.Delete:
                    if (item.GetBFIM() == null)
                        return new ValidationResult("BFIM required for new entries.", new[] { "BFIM" });
                    if (item.GetAFIM() != null)
                        return new ValidationResult("AFIM not permitted for new entries.", new[] { "AFIM" });
                    break;

                default:
                    return new ValidationResult("Invalid change action", new[] { "Action" });
            }

            return ValidationResult.Success;
        }
예제 #2
0
        public void Invalid_update_without_afim_fails_validation()
        {
            var ctx = A.Dummy<ValidationContext>();
            var item = new ChangeItem<object>(ChangeAction.Update, A.Dummy<object>(), null);

            var result = ChangeValidator.SanityCheck(item, ctx);

            Assert.AreNotEqual(ValidationResult.Success, result);
            Assert.IsTrue(result.MemberNames.Contains("AFIM"));
        }
예제 #3
0
        public void Invalid_action_fails_validation()
        {
            var ctx = A.Dummy<ValidationContext>();
            var item = new ChangeItem<object>((ChangeAction)(42), A.Dummy<object>(), A.Dummy<object>());

            var result = ChangeValidator.SanityCheck(item, ctx);

            Assert.AreNotEqual(ValidationResult.Success, result);
            Assert.IsTrue(result.MemberNames.Contains("Action"));
        }
예제 #4
0
        public void Valid_create_passes_validation()
        {
            var ctx = A.Dummy<ValidationContext>();
            var item = new ChangeItem<object>(ChangeAction.Create, null, A.Dummy<object>());

            var result = ChangeValidator.SanityCheck(item, ctx);

            Assert.AreEqual(ValidationResult.Success, result);
        }
예제 #5
0
 private ChangeItem<Asset> ModifyAsset(Asset asset)
 {
     var choice = s_rng.NextDouble();
     ChangeItem<Asset> change;
     if (s_rng.NextDouble() < s_chanceDelete)
     {
         change = new ChangeItem<Asset>(ChangeAction.Delete, asset, null);
     }
     else
     {
         change = new ChangeItem<Asset>(ChangeAction.Update, asset, Dirty(asset));
     }
     return change;
 }