Exemplo n.º 1
0
        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.º 2
0
        public void Matches_RegexWronglySpecified_Validated()
        {
            var members = new MemberResult();

            members.Add("000-000-0000");
            members.Add("2126661234");

            var matchPatternConstraint = new MatchPatternConstraint();

            matchPatternConstraint = matchPatternConstraint.Regex(@"^[2-9]\d{2}-\d{3}-\d{4}$");

            //Method under test
            var res = matchPatternConstraint.Matches(members);

            //Test conclusion
            Assert.That(res, Is.False);
        }
Exemplo n.º 3
0
        public void Matches_RegexCorrectlySpecified_Validated()
        {
            var members = new MemberResult();

            members.Add("800-555-5555");
            members.Add("212-666-1234");

            var matchPatternConstraint = new MatchPatternConstraint();

            matchPatternConstraint = matchPatternConstraint.Regex(@"^[2-9]\d{2}-\d{3}-\d{4}$");

            //Method under test
            var res = matchPatternConstraint.Matches(members);

            //Test conclusion
            Assert.That(res, Is.True);
        }
Exemplo n.º 4
0
        public void Matches_RegexCorrectlySpecified_Validated()
        {
            var cells = new FormattedResults();

            cells.Add("$185,125.12");
            cells.Add("$125.12");
            cells.Add("$125.00");

            var matchPatternConstraint = new MatchPatternConstraint();

            matchPatternConstraint = matchPatternConstraint.Regex(@"^\$?[0-9]{1,3}(?:,?[0-9]{3})*\.[0-9]{2}$");

            //Method under test
            var res = matchPatternConstraint.Matches(cells);

            //Test conclusion
            Assert.That(res, Is.True);
        }
Exemplo n.º 5
0
        public void Matches_RegexWronglySpecified_Validated()
        {
            var cells = new List <string>()
            {
                "$185,125.12",
                "$125.12",
                "$125"
            };

            var matchPatternConstraint = new MatchPatternConstraint();

            matchPatternConstraint = matchPatternConstraint.Regex(@"^\$?[0-9]{1,3}(?:,?[0-9]{3})*\.[0-9]{2}$");

            //Method under test
            var res = matchPatternConstraint.Matches(cells);

            //Test conclusion
            Assert.That(res, Is.False);
        }
Exemplo n.º 6
0
        public void WriteDescription_OneItemHasFailed_CorrectKeywordsForActualValue()
        {
            var cells = new FormattedResults();

            cells.Add("$185,125.12");
            cells.Add("$125.12");
            cells.Add("$125");

            var matchPatternConstraint = new MatchPatternConstraint();

            matchPatternConstraint = matchPatternConstraint.Regex(@"^\$?[0-9]{1,3}(?:,?[0-9]{3})*\.[0-9]{2}$");

            //Method under test
            var res = matchPatternConstraint.Matches(cells);

            var msg = new MessageWriter();

            matchPatternConstraint.WriteActualValueTo(msg);

            //Test conclusion
            Assert.That(msg.Message, Is.StringContaining("$125")
                        .And.StringContaining("doesn't validate this pattern"));
        }
Exemplo n.º 7
0
        public void WriteDescription_OneItemHasFailed_CorrectKeywordsForPredicate()
        {
            var cells = new List <string>()
            {
                "$185,125.12",
                "$125.12",
                "$125"
            };

            var matchPatternConstraint = new MatchPatternConstraint();

            matchPatternConstraint = matchPatternConstraint.Regex(@"^\$?[0-9]{1,3}(?:,?[0-9]{3})*\.[0-9]{2}$");

            //Method under test
            var res = matchPatternConstraint.Matches(cells);

            var msg = new MessageWriter();

            matchPatternConstraint.WriteDescriptionTo(msg);

            //Test conclusion
            Assert.That(msg.Predicate, Is.StringContaining("cell")
                        .And.StringContaining("regex"));
        }
Exemplo n.º 8
0
        public void WriteTo_FailingAssertionForRegex_TextContainsFewKeyInfo()
        {
            var cmd = new DiscoveryRequestFactory().Build(
                "connectionString",
                "member-caption",
                "perspective-name",
                "dimension-caption",
                "hierarchy-caption",
                null);

            var member1 = new NBi.Core.Analysis.Member.Member()
            {
                Caption = "217-487-1125"
            };
            var member2 = new NBi.Core.Analysis.Member.Member()
            {
                Caption = "000-000-0000"
            };
            var member3 = new NBi.Core.Analysis.Member.Member()
            {
                Caption = "444-222-3333"
            };
            var member4 = new NBi.Core.Analysis.Member.Member()
            {
                Caption = "4442223333"
            };
            var members = new MemberResult();

            members.Add(member1);
            members.Add(member2);
            members.Add(member3);
            members.Add(member4);

            var meStub = new Mock <MembersAdomdEngine>();

            meStub.Setup(engine => engine.GetMembers(cmd))
            .Returns(members);
            var me = meStub.Object;

            var matchPatternConstraint = new MatchPatternConstraint()
            {
                MembersEngine = me
            };

            matchPatternConstraint = matchPatternConstraint.Regex(@"^[2-9]\d{2}-\d{3}-\d{4}$");

            //Method under test
            string assertionText = null;

            try
            {
                Assert.That(cmd, matchPatternConstraint);
            }
            catch (AssertionException ex)
            {
                assertionText = ex.Message;
            }

            //Test conclusion
            Assert.That(assertionText, Is.StringContaining("perspective-name").And
                        .StringContaining("dimension-caption").And
                        .StringContaining("hierarchy-caption").And
                        .StringContaining("member-caption").And
                        .StringContaining("children").And
                        .StringContaining("regex pattern").And
                        .StringContaining(@"^[2-9]\d{2}-\d{3}-\d{4}$").And
                        .StringContaining(@"But was:    2 elements").And
                        .StringContaining(@"000-000-0000").And
                        .Not.StringContaining(@"444-222-3333"));
        }