コード例 #1
0
        /// <summary>
        /// Validation rules for details.
        /// </summary>
        /// <exception cref="ninja.model.Exceptions.BusinessException"></exception>
        internal void Validate()
        {
            AbstractValidationHandler detailValidationDescription = new InvoiceDetailValidationDescription()
            {
                PropertyName = "Description", PropertyValue = this.Description
            };
            AbstractValidationHandler detailValidationAmount = new InvoiceDetailValidationAmount()
            {
                PropertyName = "Amount", PropertyValue = this.Amount
            };
            AbstractValidationHandler detailValidationUnitPrice = new InvoiceDetailValidationUnitPrice()
            {
                PropertyName = "UnitPrice", PropertyValue = this.UnitPrice
            };

            detailValidationDescription
            .SetNext(detailValidationAmount)
            .SetNext(detailValidationUnitPrice)
            ;
            try
            {
                ValidationChain.ExecuteValidationChain(detailValidationDescription);
            }
            catch (BusinessException be)
            {
                throw new BusinessException($"{be.Message} Please check the row {Id}");
            }
        }
コード例 #2
0
 public BookingDataSaver(ISqlExecutor sqlExecutor, IMapper mapper)
 {
     this._executor        = sqlExecutor;
     this._mapper          = mapper;
     this._validationChain = new BookingNotNullRule();
     this.LoadValidationRules(sqlExecutor);
 }
コード例 #3
0
 /// <summary>
 ///  Add a new item.
 /// </summary>
 /// <param name="item">Item to be inserted in the validation chain</param>
 public void AddItem(ValidationChain <T> item)
 {
     if (_currentItem == null)
     {
         _currentItem = item;
         First        = _currentItem;
     }
     else
     {
         _currentItem.SetNext(item);
         _currentItem = item;
     }
 }
コード例 #4
0
        public static void CopyCallsForChain(ValidationGraph graph, ValidationChain chain)
        {
            var modelType = chain.ModelType.BaseType;
            while(modelType != null && modelType != typeof(Object))
            {
                var properties = modelType.GetPublicProperties();
                foreach (var property in properties)
                {
                    if (!chain.CallsFor(property.Name).Any())
                    {
                        var parentChain = graph.FindChain(modelType).CallsFor(property.Name);
                        foreach (var call in parentChain)
                        {
                            chain.AddCall(call);
                        }
                    }
                }

                modelType = modelType.BaseType;
            }
        }
コード例 #5
0
        /// <summary>
        /// Does the validate.
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        internal void DoValidate()
        {
            AbstractValidationHandler invoiceValidationType = new InvoiceValidationType()
            {
                PropertyName = "Type", PropertyValue = this.Type
            };
            AbstractValidationHandler invoiceValidationPOS = new InvoiceValidationPointOfSale()
            {
                PropertyName = "PointOfSale", PropertyValue = this.PointOfSale
            };
            AbstractValidationHandler invoiceValiationNumber = new InvoiceValidationNumber()
            {
                PropertyName = "Number", PropertyValue = this.Number
            };
            AbstractValidationHandler invoiceValidationDate = new InvoiceValidationDate()
            {
                PropertyName = "Date", PropertyValue = this.Date
            };
            AbstractValidationHandler invoiceValidationDetail = new InvoiceValidationDetails()
            {
                PropertyName = "Detail", PropertyValue = this.Detail.Count
            };

            invoiceValidationType
            .SetNext(invoiceValidationPOS)
            .SetNext(invoiceValiationNumber)
            .SetNext(invoiceValidationDate)
            .SetNext(invoiceValidationDetail);

            ValidationChain.ExecuteValidationChain(invoiceValidationType);

            foreach (InvoiceDetail detail in Detail)
            {
                detail.Validate();
            }
        }
コード例 #6
0
 public void SetUp()
 {
     sut = new ValidationChain();
 }
コード例 #7
0
        static ValidationChainTest()
        {
            ConstructorArgumentValidationTestScenarios
            .RemoveAllScenarios()
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <ValidationChain>
            {
                Name             = "constructor should throw ArgumentNullException when parameter 'steps' is null scenario",
                ConstructionFunc = () =>
                {
                    var referenceObject = A.Dummy <ValidationChain>();

                    var result = new ValidationChain(
                        null,
                        referenceObject.EndMessageOp,
                        referenceObject.EndValidity);

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentNullException),
                ExpectedExceptionMessageContains = new[] { "steps", },
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <ValidationChain>
            {
                Name             = "constructor should throw ArgumentException when parameter 'steps' is an empty enumerable scenario",
                ConstructionFunc = () =>
                {
                    var referenceObject = A.Dummy <ValidationChain>();

                    var result = new ValidationChain(
                        new List <ValidationStep>(),
                        referenceObject.EndMessageOp,
                        referenceObject.EndValidity);

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentException),
                ExpectedExceptionMessageContains = new[] { "steps", "is an empty enumerable", },
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <ValidationChain>
            {
                Name             = "constructor should throw ArgumentException when parameter 'steps' contains a null element scenario",
                ConstructionFunc = () =>
                {
                    var referenceObject = A.Dummy <ValidationChain>();

                    var result = new ValidationChain(
                        new ValidationStep[0].Concat(referenceObject.Steps).Concat(new ValidationStep[] { null }).Concat(referenceObject.Steps).ToList(),
                        referenceObject.EndMessageOp,
                        referenceObject.EndValidity);

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentException),
                ExpectedExceptionMessageContains = new[] { "steps", "contains at least one null element", },
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <ValidationChain>
            {
                Name             = "constructor should throw ArgumentOutOfRangeException when parameter 'endValidity' is Validity.Unknown",
                ConstructionFunc = () =>
                {
                    var referenceObject = A.Dummy <ValidationChain>();

                    var result = new ValidationChain(
                        referenceObject.Steps,
                        referenceObject.EndMessageOp,
                        Validity.Unknown);

                    return(result);
                },
                ExpectedExceptionType            = typeof(ArgumentOutOfRangeException),
                ExpectedExceptionMessageContains = new[] { "endValidity", "Unknown" },
            });
        }