public void GetConstraint_Build_CorrectConstraint()
        {
            var sutXml = new MembersXml();
            var item = new HierarchyXml();
            sutXml.Item = item;
            var ctrXml = new MatchPatternXml();

            var discoFactoStubFactory = new Mock<DiscoveryRequestFactory>();
            discoFactoStubFactory.Setup(dfs =>
                dfs.Build(
                    It.IsAny<string>(),
                    It.IsAny<string>(),
                    It.IsAny<List<string>>(),
                    It.IsAny<List<PatternValue>>(),
                    It.IsAny<string>(),
                    It.IsAny<string>(),
                    It.IsAny<string>(),
                    It.IsAny<string>()))
                    .Returns(new MembersDiscoveryRequest());
            var discoFactoStub = discoFactoStubFactory.Object;

            var builder = new MembersMatchPatternBuilder(discoFactoStub);
            builder.Setup(sutXml, ctrXml);
            builder.Build();
            var ctr = builder.GetConstraint();

            Assert.That(ctr, Is.InstanceOf<MatchPatternConstraint>());
        }
        protected override void SpecificSetup(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml)
        {
            if (!(ctrXml is MatchPatternXml))
                throw new ArgumentException("Constraint must be a 'MatchPatternXml'");

            ConstraintXml = (MatchPatternXml)ctrXml;
        }
        protected NBiConstraint InstantiateConstraint(MatchPatternXml ctrXml)
        {
            var ctr = new NBi.NUnit.Member.MatchPatternConstraint();
            if (!string.IsNullOrEmpty(ctrXml.Regex))
                ctr = ctr.Regex(ctrXml.Regex);

            return ctr;
        }
        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;
        }
        public void GetSystemUnderTest_Build_CorrectIDbCommand()
        {
            var sutXmlStubFactory = new Mock<ExecutionXml>();
            var itemXmlStubFactory = new Mock<QueryableXml>();
            itemXmlStubFactory.Setup(i => i.GetQuery()).Returns("query");
            itemXmlStubFactory.Setup(i => i.GetParameters()).Returns(new List<QueryParameterXml>());
            itemXmlStubFactory.Setup(i => i.GetVariables()).Returns(new List<QueryTemplateVariableXml>());
            sutXmlStubFactory.Setup(s => s.Item).Returns(itemXmlStubFactory.Object);
            var sutXml = sutXmlStubFactory.Object;
            sutXml.Item = itemXmlStubFactory.Object;

            var ctrXml = new MatchPatternXml();

            var builder = new ExecutionMatchPatternBuilder();
            builder.Setup(sutXml, ctrXml);
            builder.Build();
            var sut = builder.GetSystemUnderTest();

            Assert.That(sut, Is.InstanceOf<IDbCommand>());
        }
        public void Instantiate_ExecutionMatchPattern_TestCase()
        {
            var sutXml = new ExecutionXml();
            var ctrXml = new MatchPatternXml();

            var builderMockFactory = new Mock<ITestCaseBuilder>();
            builderMockFactory.Setup(b => b.Setup(sutXml, ctrXml, TestConfiguration.Default));
            builderMockFactory.Setup(b => b.Build());
            builderMockFactory.Setup(b => b.GetSystemUnderTest()).Returns(new SqlCommand());
            builderMockFactory.Setup(b => b.GetConstraint()).Returns(new NBi.NUnit.Query.MatchPatternConstraint());
            var builder = builderMockFactory.Object;

            var testCaseFactory = new TestCaseFactory();
            testCaseFactory.Register(typeof(ExecutionXml), typeof(MatchPatternXml), builder);

            var tc = testCaseFactory.Instantiate(sutXml, ctrXml);

            Assert.That(tc, Is.Not.Null);
            builderMockFactory.VerifyAll();
        }
        public void Serialize_MatchPatternWithCurrencyFormatLight_CurrencyFormatButNoOtherElement()
        {
            var matchPattern = new MatchPatternXml();
            matchPattern.CurrencyFormat.CurrencyPattern = NBi.Core.Format.CurrencyPattern.PrefixSpace;
            matchPattern.CurrencyFormat.CurrencySymbol = "£";

            var manager = new XmlManager();
            var str = manager.XmlSerializeFrom<MatchPatternXml>(matchPattern);

            var xml = new System.Xml.XmlDocument();
            xml.LoadXml(str);
            var node = xml.ChildNodes[1];

            Assert.That(node.ChildNodes[0].Name, Is.EqualTo("currency-format"));
            Assert.That(node.ChildNodes[0].Attributes["currency-pattern"], Is.Not.Null);
            Assert.That(node.ChildNodes[0].Attributes["currency-pattern"].Value, Is.EqualTo("$ n"));
            Assert.That(node.ChildNodes[0].Attributes["currency-symbol"], Is.Not.Null);
            Assert.That(node.ChildNodes[0].Attributes["currency-symbol"].Value, Is.EqualTo("£"));
            Assert.That(node.ChildNodes[0].Attributes["decimal-digits"], Is.Not.Null);
            Assert.That(node.ChildNodes[0].Attributes["decimal-digits"].Value, Is.EqualTo("0"));
            Assert.That(node.ChildNodes, Has.Count.EqualTo(1));
            Assert.That(node.ChildNodes[0].Attributes, Has.Count.EqualTo(3));
        }
        public void IsHandling_MembersMatchPattern_True()
        {
            var sutXml = new MembersXml();
            var ctrXml = new MatchPatternXml();
            var testCaseFactory = new TestCaseFactory();

            var actual = testCaseFactory.IsHandling(sutXml.GetType(), ctrXml.GetType());

            Assert.That(actual, Is.True);
        }
Beispiel #9
0
        public void Instantiate_MembersMatchPattern_TestCase()
        {
            var sutXml = new MembersXml();
            var ctrXml = new MatchPatternXml();
            var builderMockFactory = new Mock<ITestCaseBuilder>();
            builderMockFactory.Setup(b => b.Setup(sutXml, ctrXml));
            builderMockFactory.Setup(b => b.Build());
            builderMockFactory.Setup(b => b.GetSystemUnderTest()).Returns(new object());
            builderMockFactory.Setup(b => b.GetConstraint()).Returns(new NBi.NUnit.Member.MatchPatternConstraint());
            var builder = builderMockFactory.Object;

            var testCaseFactory = new TestCaseFactory();
            testCaseFactory.Register(typeof(MembersXml), typeof(MatchPatternXml), builder);

            var tc = testCaseFactory.Instantiate(sutXml, ctrXml);

            Assert.That(tc, Is.Not.Null);
            builderMockFactory.VerifyAll();
        }
        public void Serialize_MatchPatternWithRegex_RegexButNoOtherElement()
        {
            var matchPattern = new MatchPatternXml();
            matchPattern.Regex = "^regex+";

            var manager = new XmlManager();
            var str = manager.XmlSerializeFrom<MatchPatternXml>(matchPattern);

            var xml = new System.Xml.XmlDocument();
            xml.LoadXml(str);
            var node = xml.ChildNodes[1];

            Assert.That(node.ChildNodes[0].Name, Is.EqualTo("regex"));
            Assert.That(node.ChildNodes[0].InnerText, Is.EqualTo("^regex+"));
            Assert.That(node.ChildNodes, Has.Count.EqualTo(1));
        }
        public void Serialize_MatchPatternWithNumericFormat_NumericFormatButNoOtherElement()
        {
            var matchPattern = new MatchPatternXml();
            matchPattern.NumericFormat.DecimalDigits = 2;

            var manager = new XmlManager();
            var str = manager.XmlSerializeFrom<MatchPatternXml>(matchPattern);

            var xml = new System.Xml.XmlDocument();
            xml.LoadXml(str);
            var node = xml.ChildNodes[1];

            Assert.That(node.ChildNodes[0].Name, Is.EqualTo("numeric-format"));
            Assert.That(node.ChildNodes[0].Attributes["decimal-digits"], Is.Not.Null);
            Assert.That(node.ChildNodes[0].Attributes["decimal-digits"].Value, Is.EqualTo("2"));
            Assert.That(node.ChildNodes, Has.Count.EqualTo(1));
            Assert.That(node.ChildNodes[0].Attributes, Has.Count.EqualTo(1));
        }