Ejemplo n.º 1
0
        public virtual void SetUp()
        {
            _mockRepository = new MockRepository();
            _textBox        = new TextBox();
            _textBox.ID     = "TextBox";
            Control namingContainer = _mockRepository.StrictMultiMock <Control> (typeof(INamingContainer));

            SetupResult.For(namingContainer.FindControl("TextBox")).Return(_textBox);
            _validator = new NumericValidatorMock(namingContainer);
            _validator.ControlToValidate = _textBox.ID;

            _mockRepository.ReplayAll();

            _cultureBackup = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        }
Ejemplo n.º 2
0
        public void TestParameterConditionOrPasses(
            string parameterName,
            float parameterValue,
            float lowerBound,
            float upperBound,
            NumericValidator <float> validatorBase)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter value is less than or equal to the lower bound or greater than or equal to the upper bound"
            .x(() => validatorBase.IsLessThanOrEqualTo(lowerBound).Or.IsGreaterThanOrEqualTo(upperBound).OtherwiseThrowException());

            "Should not result in an exception"
            .x(() => validatorBase.CurrentException.Should().BeNull());
        }
Ejemplo n.º 3
0
        public void TestParameterLessThanFails(
            string parameterName,
            double parameterValue,
            double valueToCompare,
            NumericValidator <double> validatorBase,
            Action act)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter value is less than the value to compare against"
            .x(() => act = () => validatorBase.IsLessThan(valueToCompare).OtherwiseThrowException());

            "Should throw an exception"
            .x(() => act.ShouldThrow <ArgumentOutOfRangeException>()
               .WithMessage(string.Format(Resources.MustBeLessThanX + "\r\nParameter name: {1}", valueToCompare, parameterName)));
        }
Ejemplo n.º 4
0
        public void TestParameterNotEqualToFails(
            string parameterName,
            long parameterValue,
            long valueToCompare,
            NumericValidator <long> validatorBase,
            Action act)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter value is equal to the value to compare against"
            .x(() => act = () => validatorBase.IsNotEqualTo(valueToCompare).OtherwiseThrowException());

            "Should throw an exception"
            .x(() => act.ShouldThrow <ArgumentEqualityException>()
               .WithMessage(string.Format(Resources.MustNotBeEqualToX + "\r\nParameter name: {1}", valueToCompare, parameterName)));
        }
Ejemplo n.º 5
0
        public void TestParameterGreaterThanOrEqualToFails(
            string parameterName,
            decimal parameterValue,
            decimal valueToCompare,
            NumericValidator <decimal> validatorBase,
            Action act)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter value is greater than or equal to the value to compare against"
            .x(() => act = () => validatorBase.IsGreaterThanOrEqualTo(valueToCompare).OtherwiseThrowException());

            "Should throw an exception"
            .x(() => act.ShouldThrow <ArgumentOutOfRangeException>()
               .WithMessage(string.Format(Resources.MustBeGreaterThanOrEqualToX + "\r\nParameter name: {1}", valueToCompare, parameterName)));
        }
Ejemplo n.º 6
0
        public void TestParameterConditionAndFailsLower(
            string parameterName,
            long parameterValue,
            long lowerBound,
            long upperBound,
            NumericValidator <long> validatorBase,
            Action act)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter value is greater or equal to the lower bound and less than or equal to the upper bound"
            .x(() => act = () => validatorBase.IsGreaterThanOrEqualTo(lowerBound).And.IsLessThanOrEqualTo(upperBound).OtherwiseThrowException());

            "Should throw an exception"
            .x(() => act.ShouldThrow <ArgumentOutOfRangeException>()
               .WithMessage(string.Format(Resources.MustBeGreaterThanOrEqualToX + "\r\nParameter name: {1}", lowerBound, parameterName)));
        }
Ejemplo n.º 7
0
        private NumericValidator CreateTypeIsNumericValidator(BocTextValueType valueType, IResourceManager resourceManager)
        {
            NumericValidator typeValidator = new NumericValidator();

            typeValidator.ID = ID + "_ValidatorType";
            typeValidator.ControlToValidate = TargetControl.ID;
            if (Property != null)
            {
                typeValidator.AllowNegative = ((IBusinessObjectNumericProperty)Property).AllowNegative;
            }
            typeValidator.DataType    = GetNumericValidatorDataType(valueType);
            typeValidator.NumberStyle = GetNumberStyle(valueType);
            if (string.IsNullOrEmpty(ErrorMessage))
            {
                typeValidator.ErrorMessage = resourceManager.GetString(GetNumericValidatorErrorMessage(GetNumericValidatorDataType(valueType)));
            }
            else
            {
                typeValidator.ErrorMessage = ErrorMessage;
            }
            return(typeValidator);
        }
        public void Constructors()
        {
            // Test fixed length properties.
            StringFieldFormatter formatter = new StringFieldFormatter(37,
                                                                      new FixedLengthManager(12), StringEncoder.GetInstance(),
                                                                      SpacePaddingRight.GetInstance(false), NumericValidator.GetInstance(),
                                                                      null, "My formatter");

            Assert.IsTrue(formatter.FieldNumber == 37);
            Assert.IsTrue(formatter.LengthManager.MaximumLength == 12);
            Assert.IsTrue(formatter.Description.Equals("My formatter"));
            Assert.IsTrue(formatter.Encoder == StringEncoder.GetInstance());
            Assert.IsTrue(formatter.Padding == SpacePaddingRight.GetInstance(false));
            Assert.IsTrue(formatter.Validator == NumericValidator.GetInstance());
            Assert.IsNull(formatter.ValueFormatter);

            // Test variable length properties without padding.
            formatter = new StringFieldFormatter(63, new VariableLengthManager(1, 800,
                                                                               StringLengthEncoder.GetInstance(5)), StringEncoder.GetInstance());

            Assert.IsTrue(formatter.FieldNumber == 63);
            Assert.IsTrue(formatter.LengthManager.MaximumLength == 800);
            Assert.IsTrue(formatter.Description.Equals(string.Empty));
            Assert.IsTrue(formatter.Encoder == StringEncoder.GetInstance());
            Assert.IsTrue(formatter.Padding == null);
            Assert.IsTrue(formatter.Validator == null);

            // Test variable length properties with padding.
            formatter = new StringFieldFormatter(48, new VariableLengthManager(1,
                                                                               999, StringLengthEncoder.GetInstance(3)), StringEncoder.GetInstance(),
                                                 SpacePaddingRight.GetInstance(false), "My formatter");

            Assert.IsTrue(formatter.FieldNumber == 48);
            Assert.IsTrue(formatter.LengthManager.MaximumLength == 999);
            Assert.IsTrue(formatter.Description.Equals("My formatter"));
            Assert.IsTrue(formatter.Encoder == StringEncoder.GetInstance());
            Assert.IsTrue(formatter.Padding == SpacePaddingRight.GetInstance(false));
            Assert.IsTrue(formatter.Validator == null);
        }
        /// <summary>
        /// It initializes the fields formatters for this message formatter.
        /// </summary>
        private void SetupFields()
        {
            MessageTypeIdentifierFormatter = new StringFieldFormatter(
                -1, new FixedLengthManager(4), StringEncoder.GetInstance(),
                ZeroPaddingLeft.GetInstance(false, true), "Message type identifier");

            FieldFormatters.Add(new BitMapFieldFormatter(0, 1, 64,
                                                         HexadecimalBinaryEncoder.GetInstance(), "Primary bitmap"));
            FieldFormatters.Add(new BitMapFieldFormatter(1, 65, 128,
                                                         HexadecimalBinaryEncoder.GetInstance(), "Secondary bitmap"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    2, new VariableLengthManager(0, 19, StringLengthEncoder.GetInstance(19)),
                                    StringEncoder.GetInstance(), NumericValidator.GetInstance(),
                                    "Primary Account Number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    3, new FixedLengthManager(6), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Processing Code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    4, new FixedLengthManager(12), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Transaction amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    5, new FixedLengthManager(12), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Reconciliation amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    6, new FixedLengthManager(12), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Cardholder billing amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    7, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Transmission date and time"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    8, new FixedLengthManager(8), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Cardholder billing fee amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    9, new FixedLengthManager(8), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Reconciliation conversion rate"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    10, new FixedLengthManager(8), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Cardholder billing conversion rate"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    11, new FixedLengthManager(6), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Systems trace audit number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    12, new FixedLengthManager(12), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Local transaction date and time"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    13, new FixedLengthManager(4), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Effective date"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    14, new FixedLengthManager(4), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Expiration date"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    15, new FixedLengthManager(6), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Settlement date"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    16, new FixedLengthManager(4), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Conversion date"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    17, new FixedLengthManager(4), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Capture date"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    18, new FixedLengthManager(4), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Merchant type"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    19, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Acquiring institution country code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    20, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Primary account number country code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    21, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Forwarding institution country code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    22, new FixedLengthManager(12), StringEncoder.GetInstance(),
                                    "Point of service data code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    23, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Card sequence number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    24, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Function code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    25, new FixedLengthManager(4), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Message reason code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    26, new FixedLengthManager(4), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Card acceptor business code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    27, new FixedLengthManager(1), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Approval code length"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    28, new FixedLengthManager(6), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Reconciliation date"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    29, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Reconciliation indicator"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    30, new FixedLengthManager(24), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Original amounts"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    31, new VariableLengthManager(0, 99, StringLengthEncoder.GetInstance(99)),
                                    StringEncoder.GetInstance(), "Acquirer reference data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    32, new VariableLengthManager(0, 11, StringLengthEncoder.GetInstance(11)),
                                    StringEncoder.GetInstance(), NumericValidator.GetInstance(),
                                    "Acquirer institution identification code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    33, new VariableLengthManager(0, 11, StringLengthEncoder.GetInstance(11)),
                                    StringEncoder.GetInstance(), NumericValidator.GetInstance(),
                                    "Forwarding institution identification code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    34, new VariableLengthManager(0, 28, StringLengthEncoder.GetInstance(28)),
                                    StringEncoder.GetInstance(), "Extended primary account number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    35, new VariableLengthManager(0, 37, StringLengthEncoder.GetInstance(37)),
                                    StringEncoder.GetInstance(), "Track 2 data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    36, new VariableLengthManager(0, 104, StringLengthEncoder.GetInstance(104)),
                                    StringEncoder.GetInstance(), "Track 3 data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    37, new FixedLengthManager(12), StringEncoder.GetInstance(),
                                    "Retrieval reference number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    38, new FixedLengthManager(6), StringEncoder.GetInstance(),
                                    "Approval code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    39, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Action code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    40, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Service code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    41, new FixedLengthManager(8), StringEncoder.GetInstance(),
                                    "Card acceptor terminal identification"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    42, new FixedLengthManager(15), StringEncoder.GetInstance(),
                                    "Card acceptor identification code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    43, new VariableLengthManager(0, 99, StringLengthEncoder.GetInstance(99)),
                                    StringEncoder.GetInstance(), "Card acceptor name/location"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    44, new VariableLengthManager(0, 99, StringLengthEncoder.GetInstance(99)),
                                    StringEncoder.GetInstance(), "Additional response data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    45, new VariableLengthManager(0, 76, StringLengthEncoder.GetInstance(76)),
                                    StringEncoder.GetInstance(), "Track 1 data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    46, new VariableLengthManager(0, 204, StringLengthEncoder.GetInstance(204)),
                                    StringEncoder.GetInstance(), "Fees amounts"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    47, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Additional data - national"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    48, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Additional data - private"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    49, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    "Transaction currency code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    50, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    "Reconciliation currency code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    51, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    "Cardholder billing currency code"));
            FieldFormatters.Add(new BinaryFieldFormatter(
                                    52, new FixedLengthManager(8), BinaryEncoder.GetInstance(),
                                    "Personal identification number (PIN) data"));
            FieldFormatters.Add(new BinaryFieldFormatter(
                                    53, new VariableLengthManager(0, 48, StringLengthEncoder.GetInstance(48)),
                                    HexadecimalBinaryEncoder.GetInstance(), "Security related control information"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    54, new VariableLengthManager(0, 120, StringLengthEncoder.GetInstance(120)),
                                    StringEncoder.GetInstance(), "Amounts, additional"));
            FieldFormatters.Add(new BinaryFieldFormatter(
                                    55, new VariableLengthManager(0, 255, StringLengthEncoder.GetInstance(255)),
                                    HexadecimalBinaryEncoder.GetInstance(), "IC card system related data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    56, new VariableLengthManager(0, 35, StringLengthEncoder.GetInstance(35)),
                                    StringEncoder.GetInstance(), NumericValidator.GetInstance(),
                                    "Original data elements"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    57, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Authorization life cycle code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    58, new VariableLengthManager(0, 11, StringLengthEncoder.GetInstance(11)),
                                    StringEncoder.GetInstance(), NumericValidator.GetInstance(),
                                    "Authorizing agent institution Id Code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    59, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Transport data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    60, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    61, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    62, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for private use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    63, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for private use"));
            FieldFormatters.Add(new BinaryFieldFormatter(
                                    64, new FixedLengthManager(8), BinaryEncoder.GetInstance(),
                                    "Message authentication code field"));
            FieldFormatters.Add(new BinaryFieldFormatter(
                                    65, new FixedLengthManager(8), BinaryEncoder.GetInstance(),
                                    "Reserved for ISO use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    66, new VariableLengthManager(0, 204, StringLengthEncoder.GetInstance(204)),
                                    StringEncoder.GetInstance(), "Amounts, original fees"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    67, new FixedLengthManager(2), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Extended payment data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    68, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Receiving institution country code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    69, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Settlement institution country code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    70, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Authorizing agent institution country code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    71, new FixedLengthManager(8), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Message number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    72, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Data record"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    73, new FixedLengthManager(6), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, false), "Action date"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    74, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Credits, number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    75, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Credits, reversal number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    76, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Debits, number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    77, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Debits, reversal number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    78, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Transfer, number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    79, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Transfer, reversal number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    80, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Inquiries, number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    81, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Authorizations, number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    82, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Inquiries, reversal number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    83, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Payments, number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    84, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Payments, reversal number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    85, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Fee collections, number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    86, new FixedLengthManager(16), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Credits, amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    87, new FixedLengthManager(16), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Credits, reversal amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    88, new FixedLengthManager(16), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Debits, amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    89, new FixedLengthManager(16), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Debits, reversal amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    90, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Authorizations, reversal number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    91, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Transaction destination institution country code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    92, new FixedLengthManager(3), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Transaction originator institution country code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    93, new VariableLengthManager(0, 11, StringLengthEncoder.GetInstance(11)),
                                    StringEncoder.GetInstance(), NumericValidator.GetInstance(),
                                    "Transaction destination institution Id Code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    94, new VariableLengthManager(0, 11, StringLengthEncoder.GetInstance(11)),
                                    StringEncoder.GetInstance(), NumericValidator.GetInstance(),
                                    "Transaction originator institution Id Code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    95, new VariableLengthManager(0, 99, StringLengthEncoder.GetInstance(99)),
                                    StringEncoder.GetInstance(), "Card issuer reference data"));
            FieldFormatters.Add(new BinaryFieldFormatter(
                                    96, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(48)),
                                    HexadecimalBinaryEncoder.GetInstance(), "Key management data"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    97, new FixedLengthManager(17), StringEncoder.GetInstance(),
                                    "Net reconciliation amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    98, new FixedLengthManager(25), StringEncoder.GetInstance(),
                                    "Payee"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    99, new VariableLengthManager(0, 11, StringLengthEncoder.GetInstance(11)),
                                    StringEncoder.GetInstance(), "Settlement institution Id code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    100, new VariableLengthManager(0, 11, StringLengthEncoder.GetInstance(11)),
                                    StringEncoder.GetInstance(), NumericValidator.GetInstance(),
                                    "Receiving institution Id code"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    101, new VariableLengthManager(0, 17, StringLengthEncoder.GetInstance(17)),
                                    StringEncoder.GetInstance(), "File name"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    102, new VariableLengthManager(0, 28, StringLengthEncoder.GetInstance(28)),
                                    StringEncoder.GetInstance(), "Account identification 1"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    103, new VariableLengthManager(0, 28, StringLengthEncoder.GetInstance(28)),
                                    StringEncoder.GetInstance(), "Account identification 2"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    104, new VariableLengthManager(0, 100, StringLengthEncoder.GetInstance(100)),
                                    StringEncoder.GetInstance(), "Transaction description"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    105, new FixedLengthManager(16), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Credits, chargeback amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    106, new FixedLengthManager(16), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Debits, chargeback amount"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    107, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Credits, chargeback number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    108, new FixedLengthManager(10), StringEncoder.GetInstance(),
                                    ZeroPaddingLeft.GetInstance(false, true), "Debits, chargeback number"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    109, new VariableLengthManager(0, 84, StringLengthEncoder.GetInstance(84)),
                                    StringEncoder.GetInstance(), "Credits, fee amounts"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    110, new VariableLengthManager(0, 84, StringLengthEncoder.GetInstance(84)),
                                    StringEncoder.GetInstance(), "Debits, fee amounts"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    111, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for ISO use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    112, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for ISO use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    113, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for ISO use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    114, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for ISO use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    115, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for ISO use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    116, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    117, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    118, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    119, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    120, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    121, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    122, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for national use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    123, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for private use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    124, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for private use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    125, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for private use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    126, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for private use"));
            FieldFormatters.Add(new StringFieldFormatter(
                                    127, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)),
                                    StringEncoder.GetInstance(), "Reserved for private use"));
            FieldFormatters.Add(new BinaryFieldFormatter(
                                    128, new FixedLengthManager(8), BinaryEncoder.GetInstance(),
                                    "Message authentication code"));
        }
Ejemplo n.º 10
0
 public static NumericValidator <decimal> That(string nameOfParameter, decimal parameterValue)
 {
     return(NumericValidator <decimal> .GetInstance(nameOfParameter, parameterValue));
 }
Ejemplo n.º 11
0
 public static NumericValidator <float> That(string nameOfParameter, float parameterValue)
 {
     return(NumericValidator <float> .GetInstance(nameOfParameter, parameterValue));
 }
Ejemplo n.º 12
0
        public void TestParameterIsPositivePasses(string parameterName, long parameterValue, NumericValidator <long> validatorBase)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter is false"
            .x(() => validatorBase.IsPositive().OtherwiseThrowException());

            "Should not result in an exception"
            .x(() => validatorBase.CurrentException.Should().BeNull());
        }
Ejemplo n.º 13
0
        public void TestParameterGreaterThanPasses(string parameterName, long parameterValue, long valueToCompare, NumericValidator <long> validatorBase)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter value is greater than the value to compare against"
            .x(() => validatorBase.IsGreaterThan(valueToCompare).OtherwiseThrowException());

            "Should not result in an exception"
            .x(() => validatorBase.CurrentException.Should().BeNull());
        }
Ejemplo n.º 14
0
        public void TestParameterIsPositiveFails(string parameterName, long parameterValue, NumericValidator <long> validatorBase, Action act)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter is false"
            .x(() => act = () => validatorBase.IsPositive().OtherwiseThrowException());

            "Should throw an exception"
            .x(() => act.ShouldThrow <ArgumentOutOfRangeException>()
               .WithMessage(string.Format(Resources.MustBePositive + "\r\nParameter name: {0}", parameterName)));
        }
Ejemplo n.º 15
0
        public static IRuleBuilder <T> Numeric <T>(this IRuleBuilder <T> ruleBuilder) where T : class
        {
            ruleBuilder.AddRule(NumericValidator <T> .New(ruleBuilder));

            return(ruleBuilder);
        }
Ejemplo n.º 16
0
 public static NumericValidator <sbyte> That(string nameOfParameter, sbyte parameterValue)
 {
     return(NumericValidator <sbyte> .GetInstance(nameOfParameter, parameterValue));
 }
        public void ShouldReturnErrorMessage()
        {
            var validator = new NumericValidator();

            validator.GetErrorMessage().Should().Be("Answer accepts only numbers.");
        }
Ejemplo n.º 18
0
        public virtual void TestParameterNotEqualToPasses(string parameterName, int parameterValue, int valueToCompare, NumericValidator <int> validatorBase)
        {
            "Given a new ValidatorBase"
            .x(() => validatorBase = Validate.That(parameterName, parameterValue));

            "Testing that the parameter value is equal to the value to compare against"
            .x(() => validatorBase.IsNotEqualTo(valueToCompare).OtherwiseThrowException());

            "Should not result in an exception"
            .x(() => validatorBase.CurrentException.Should().BeNull());
        }
Ejemplo n.º 19
0
 public static NumericValidator <long> That(string nameOfParameter, long parameterValue)
 {
     return(NumericValidator <long> .GetInstance(nameOfParameter, parameterValue));
 }
        public void Format()
        {
            FormatterContext formatterContext = new FormatterContext(
                FormatterContext.DefaultBufferSize);
            StringField          field = new StringField(1, "DATA");
            StringFieldFormatter formatter;
            string formattedData;

            // Test fixed length formatting.
            formatter = new StringFieldFormatter(37,
                                                 new FixedLengthManager(12), StringEncoder.GetInstance());
            formatter.Format(field, ref formatterContext);
            formattedData = formatterContext.GetDataAsString();
            Assert.IsTrue(formattedData.Equals("DATA        "));

            // Test variable length formatting without padding.
            formatterContext.Clear();
            formatter = new StringFieldFormatter(48, new VariableLengthManager(0,
                                                                               999, StringLengthEncoder.GetInstance(999)),
                                                 StringEncoder.GetInstance());
            formatter.Format(field, ref formatterContext);
            formattedData = formatterContext.GetDataAsString();
            Assert.IsTrue(formattedData.Equals("004DATA"));
            formatterContext.Clear();
            formatter.Format(new StringField(5, null), ref formatterContext);
            formattedData = formatterContext.GetDataAsString();
            Assert.IsTrue(formattedData.Equals("000"));

            // Test variable length formatting with padding.
            formatterContext.Clear();
            formatter = new StringFieldFormatter(48, new VariableLengthManager(10,
                                                                               10, StringLengthEncoder.GetInstance(10)),
                                                 StringEncoder.GetInstance(), SpacePaddingLeft.GetInstance(false),
                                                 string.Empty);
            formatter.Format(field, ref formatterContext);
            formattedData = formatterContext.GetDataAsString();
            Assert.IsTrue(formattedData.Equals("10      DATA"));

            // Test validator with fixed length formatting.
            formatterContext.Clear();
            formatter = new StringFieldFormatter(37,
                                                 new FixedLengthManager(12), StringEncoder.GetInstance(),
                                                 NumericValidator.GetInstance(), string.Empty);
            field.FieldValue = "000000001500";
            formatter.Format(field, ref formatterContext);
            formattedData = formatterContext.GetDataAsString();
            Assert.IsTrue(formattedData.Equals("000000001500"));

            // Try with an invalid value.
            formatterContext.Clear();
            field.FieldValue = "D1500";
            try {
                formatter.Format(field, ref formatterContext);
                Assert.Fail();
            } catch (StringValidationException) {
            }

            // Test validator with fixed length formatting and numeric padding.
            formatterContext.Clear();
            formatter = new StringFieldFormatter(37,
                                                 new FixedLengthManager(12), StringEncoder.GetInstance(),
                                                 ZeroPaddingLeft.GetInstance(false, true), NumericValidator.GetInstance());
            field.FieldValue = "56600";
            formatter.Format(field, ref formatterContext);
            formattedData = formatterContext.GetDataAsString();
            Assert.IsTrue(formattedData.Equals("000000056600"));

            // Try with an invalid value.
            formatterContext.Clear();
            field.FieldValue = "D1500";
            try {
                formatter.Format(field, ref formatterContext);
                Assert.Fail();
            } catch (StringValidationException) {
            }
        }
        public void Parse()
        {
            ParserContext parseContext = new ParserContext(
                ParserContext.DefaultBufferSize);
            StringField          field;
            StringFieldFormatter formatter;

            // Setup data for three complete fields an one with partial data.
            parseContext.Write("DATA        20   DATA TO BE PARSED009SOME DATA00");

            // Test fixed length parse.
            formatter = new StringFieldFormatter(37, new FixedLengthManager(12),
                                                 StringEncoder.GetInstance());
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNotNull(field);
            parseContext.ResetDecodedLength();
            Assert.IsTrue(field.FieldValue.Equals("DATA"));

            // Test variable length parse with padding.
            formatter = new StringFieldFormatter(48, new VariableLengthManager(1, 20,
                                                                               StringLengthEncoder.GetInstance(99)), StringEncoder.GetInstance(),
                                                 SpacePaddingLeft.GetInstance(false), string.Empty);
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNotNull(field);
            parseContext.ResetDecodedLength();
            Assert.IsTrue(field.FieldValue.Equals("DATA TO BE PARSED"));

            // Test variable length parse without padding.
            formatter = new StringFieldFormatter(48, new VariableLengthManager(1,
                                                                               999, StringLengthEncoder.GetInstance(999)), StringEncoder.GetInstance());
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNotNull(field);
            parseContext.ResetDecodedLength();
            Assert.IsTrue(field.FieldValue.Equals("SOME DATA"));

            // Test partial variable length parse without padding.
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNull(field);
            parseContext.Write("9MORE D");
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNull(field);
            parseContext.Write("ATA");
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNotNull(field);
            parseContext.ResetDecodedLength();
            Assert.IsTrue(field.FieldValue.Equals("MORE DATA"));

            // Test partial fixed parse with padding.
            formatter = new StringFieldFormatter(37, new FixedLengthManager(12),
                                                 StringEncoder.GetInstance());
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNull(field);
            parseContext.Write("ONE MORE");
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNull(field);
            parseContext.Write("    ");
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNotNull(field);
            parseContext.ResetDecodedLength();
            Assert.IsTrue(field.FieldValue.Equals("ONE MORE"));

            // Test variable length header with zero length.
            formatter = new StringFieldFormatter(48, new VariableLengthManager(0,
                                                                               999, StringLengthEncoder.GetInstance(999)), StringEncoder.GetInstance());
            parseContext.Write("000");
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNotNull(field);
            parseContext.ResetDecodedLength();
            Assert.IsNull(field.FieldValue);

            // Test fixed length parse with validation.
            formatter = new StringFieldFormatter(37, new FixedLengthManager(12),
                                                 StringEncoder.GetInstance(), ZeroPaddingLeft.GetInstance(false, true),
                                                 NumericValidator.GetInstance());
            parseContext.Write("000000145000");
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNotNull(field);
            parseContext.ResetDecodedLength();
            Assert.IsTrue(field.FieldValue.Equals("145000"));

            // Try with an invalid value.
            parseContext.Write("0000001450F0");
            try {
                field = ( StringField)formatter.Parse(ref parseContext);
                Assert.Fail();
            } catch (StringValidationException) {
            }

            // Test variable length parse with validation.
            parseContext.Clear();
            parseContext.ResetDecodedLength();
            formatter = new StringFieldFormatter(48, new VariableLengthManager(1,
                                                                               999, StringLengthEncoder.GetInstance(999)), StringEncoder.GetInstance(),
                                                 NumericValidator.GetInstance());
            parseContext.Write("00532000");
            field = ( StringField)formatter.Parse(ref parseContext);
            Assert.IsNotNull(field);
            parseContext.ResetDecodedLength();
            Assert.IsTrue(field.FieldValue.Equals("32000"));

            // Try with an invalid value.
            parseContext.Write("005350F0");
            try {
                field = ( StringField)formatter.Parse(ref parseContext);
                Assert.Fail();
            } catch (StringValidationException) {
            }
        }