Exemplo n.º 1
0
        public void Build_NumericFormatWithoutDecimalByWithDefaultGroupSeparator_CorrectRegex()
        {
            var builder = new RegexBuilder();
            var result = builder.Build(
                    new NumericFormatXml()
                    {
                        DecimalDigits = 0
                    }
                );

            Assert.That(result, Is.EqualTo(@"^?[0-9]{1,3}(?:\,?[0-9]{3})*$"));
            Assert.That("1,125", Is.StringMatching(result));
        }
Exemplo n.º 2
0
        public void Build_NumericFormatWithoutDecimal_CorrectRegex()
        {
            var builder = new RegexBuilder();
            var result = builder.Build(
                    new NumericFormatXml()
                    {
                        DecimalDigits = 0,
                        GroupSeparator = ""
                    }
                );

            Assert.That(result, Is.EqualTo(@"^?[0-9]*$"));
            Assert.That("1125", Is.StringMatching(result));
        }
        protected NBiConstraint InstantiateConstraint(MatchPatternXml matchPatternXml)
        {
            var regexBuilder = new RegexBuilder();

            var ctr = new MatchPatternConstraint();
            if (!string.IsNullOrEmpty(matchPatternXml.Regex))
                ctr = ctr.Regex(matchPatternXml.Regex);

            if (matchPatternXml.NumericFormat != null && !matchPatternXml.NumericFormat.IsEmpty)
                ctr = ctr.Regex(regexBuilder.Build(matchPatternXml.NumericFormat));

            if (matchPatternXml.CurrencyFormat != null && !matchPatternXml.CurrencyFormat.IsEmpty)
                ctr = ctr.Regex(regexBuilder.Build(matchPatternXml.CurrencyFormat));

            return ctr;
        }
Exemplo n.º 4
0
        public void Build_CurrencyFormat_CorrectRegex()
        {
            var builder = new RegexBuilder();
            var result = builder.Build(
                    new CurrencyFormatXml()
                    {
                        DecimalDigits = 2,
                        DecimalSeparator = ".",
                        GroupSeparator = ",",
                        CurrencySymbol = "$",
                        CurrencyPattern=CurrencyPattern.Prefix
                    }
                );

            Assert.That(result, Is.EqualTo(@"^\$?[0-9]{1,3}(?:\,?[0-9]{3})*\.[0-9]{2}$"));
            Assert.That("$1,125,125.21", Is.StringMatching(result));
        }
Exemplo n.º 5
0
        public void Build_CurrencyFormatSpaceEuro_CorrectRegex()
        {
            var builder = new RegexBuilder();
            var result = builder.Build(
                    new CurrencyFormatXml()
                    {
                        DecimalDigits = 2,
                        DecimalSeparator = ",",
                        GroupSeparator = " ",
                        CurrencySymbol = "€",
                        CurrencyPattern = CurrencyPattern.SuffixSpace
                    }
                );

            Assert.That(result, Is.EqualTo(@"^?[0-9]{1,3}(?:\s?[0-9]{3})*\,[0-9]{2}\s\€$"));
            Assert.That("1 125 125,21 €", Is.StringMatching(result));
        }
Exemplo n.º 6
0
        public void Build_NumericFormat_CorrectRegex()
        {
            var builder = new RegexBuilder();
            var result = builder.Build(
                    new NumericFormatXml()
                        {
                            DecimalDigits=2,
                            DecimalSeparator=".",
                            GroupSeparator=","
                        }
                );

            Assert.That(result, Is.EqualTo(@"^?[0-9]{1,3}(?:\,?[0-9]{3})*\.[0-9]{2}$"));
            Assert.That("1,125,125.21", Is.StringMatching(result));
        }