コード例 #1
0
ファイル: StructureExistsBuilder.cs プロジェクト: zyh329/nbi
 protected global::NUnit.Framework.Constraints.Constraint InstantiateConstraint(ExistsXml ctrXml)
 {
     var ctr = new ExistsConstraint();
     //Ignore-case if requested
     if (ctrXml.IgnoreCase)
         ctr = ctr.IgnoreCase;
     return ctr;
 }
コード例 #2
0
        protected NBiConstraint InstantiateConstraint(ExistsXml ctrXml, StructureXml sutXml)
        {
            var expected = sutXml.Item.Caption;

            var ctr = new ExistsConstraint(expected);
            //Ignore-case if requested
            if (ctrXml.IgnoreCase)
                ctr = ctr.IgnoreCase;
            return ctr;
        }
コード例 #3
0
ファイル: ExistsConstraintTest.cs プロジェクト: zyh329/nbi
        public void ExistsConstraint_ExistingPerspectiveButWrongCaseWithIgnoreCaseFalse_Failure()
        {
            var discovery = new DiscoveryRequestFactory().BuildDirect(
                        ConnectionStringReader.GetAdomd()
                        , DiscoveryTarget.Perspectives
                        , new List<IFilter>() {
                            new CaptionFilter("Adventure Works".ToLower(), DiscoveryTarget.Perspectives)
                        });

            var ctr = new ExistsConstraint();

            //Method under test
            Assert.Throws<AssertionException>(delegate { Assert.That(discovery, ctr); });
        }
コード例 #4
0
ファイル: ExistsConstraintTest.cs プロジェクト: zyh329/nbi
        public void ExistsConstraint_ExistingPerspectiveButWrongCaseWithIgnoreCaseTrue_Success()
        {
            var discovery = new DiscoveryRequestFactory().BuildDirect(
                        ConnectionStringReader.GetAdomd()
                        , DiscoveryTarget.Perspectives
                        , new List<IFilter>() {
                            new CaptionFilter("Adventure Works", DiscoveryTarget.Perspectives),
                            new CaptionFilter("Date", DiscoveryTarget.Dimensions)
                        });

            var ctr = new ExistsConstraint();
            ctr = ctr.IgnoreCase;

            //Method under test
            Assert.That(discovery, ctr);
        }
コード例 #5
0
        public void Matches_Default_Success()
        {
            var description = new CommandDescription(Target.MeasureGroups,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                        });

            var actuals = new string[] { "a", "b", "c" };

            var commandStub = new Mock<IStructureDiscoveryCommand>();
            commandStub.Setup(cmd => cmd.Execute()).Returns(actuals);
            commandStub.Setup(cmd => cmd.Description).Returns(description);

            var existsConstraint = new ExistsConstraint("a");

            //Method under test
            Assert.That(commandStub.Object, existsConstraint);
        }
コード例 #6
0
ファイル: ExistsConstraintTest.cs プロジェクト: zyh329/nbi
        public void Matches_GivenDiscoveryRequestFailing_InvestigateCommandCalledOnce()
        {
            var request = new DiscoveryRequestFactory().BuildDirect(
                        "connectionString",
                        DiscoveryTarget.MeasureGroups,
                        new List<IFilter>()
                            {
                                new CaptionFilter("perspective-name", DiscoveryTarget.Perspectives)
                                , new CaptionFilter("measure-group", DiscoveryTarget.MeasureGroups)
                                , new CaptionFilter("measure", DiscoveryTarget.Measures)
                        });

            var elements = new List<IField>();

            var commandExactStub = new Mock<AdomdDiscoveryCommand>("connectionString");
            commandExactStub.Setup(f => f.Execute())
                .Returns(elements);

            var commandExternalMock = new Mock<AdomdDiscoveryCommand>("connectionString");
            commandExternalMock.Setup(f => f.Execute())
                .Returns(elements);

            var factoryStub = new Mock<AdomdDiscoveryCommandFactory>();
            factoryStub.Setup(f => f.BuildExact(request))
                .Returns(commandExactStub.Object);

            factoryStub.Setup(f => f.BuildExternal(It.IsAny<MetadataDiscoveryRequest>()))
                .Returns(commandExternalMock.Object);
            var factory = factoryStub.Object;

            var ctr = new ExistsConstraint() { CommandFactory = factory };

            //Method under test
            try
            {
                Assert.That(request, ctr);
            }
            catch { }

            //Test conclusion
            commandExternalMock.Verify(c => c.Execute(), Times.Once());
        }
コード例 #7
0
        public void Matches_GivenCommand_ExecuteCalledOnce()
        {
            var description = new CommandDescription(Target.Dimensions,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                        });

            var actuals = new string[] { "Actual dimension 1", "Actual dimension 2", "Actual dimension 3" };

            var commandMock = new Mock<IStructureDiscoveryCommand>();
            commandMock.Setup(cmd => cmd.Execute()).Returns(actuals);
            commandMock.Setup(cmd => cmd.Description).Returns(description);

            var existConstraint = new ExistsConstraint("expected-dimension-caption");

            //Method under test
            existConstraint.Matches(commandMock.Object);

            //Test conclusion
            commandMock.Verify(cmd => cmd.Execute(), Times.Once());
        }
コード例 #8
0
        public void WriteTo_FailingAssertionForDimensionWithMinorMistake_TextContainsTheSuggestionOfValue()
        {
            var description = new CommandDescription(Target.MeasureGroups,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                        });

            var actuals = new string[] { "expected-dimension-catpion" };

            var commandStub = new Mock<IStructureDiscoveryCommand>();
            commandStub.Setup(cmd => cmd.Execute()).Returns(actuals);
            commandStub.Setup(cmd => cmd.Description).Returns(description);

            var existsConstraint = new ExistsConstraint("expected-dimension-caption");

            //Method under test
            string assertionText = null;
            try
            {
                Assert.That(commandStub.Object, existsConstraint);
            }
            catch (AssertionException ex)
            {
                assertionText = ex.Message;
            }

            //Test conclusion
            Console.WriteLine(assertionText);
            Assert.That(assertionText, Is.StringContaining("The value 'expected-dimension-catpion' is close to your expectation."));
        }
コード例 #9
0
        public void WriteTo_FailingAssertionForPerspectiveWithNot_TextContainsFewKeyInfo()
        {
            var description = new CommandDescription(Target.MeasureGroups,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                        });

            var actuals = new string[] { "expected-measure-group-caption", "other expected-measure-group-caption" };

            var commandStub = new Mock<IStructureDiscoveryCommand>();
            commandStub.Setup(cmd => cmd.Execute()).Returns(actuals);
            commandStub.Setup(cmd => cmd.Description).Returns(description);

            var existsConstraint = new ExistsConstraint("expected-measure-group-caption");
            var notExistsConstraint = new NotConstraint(existsConstraint);

            //Method under test
            string assertionText = null;
            try
            {
                Assert.That(commandStub.Object, notExistsConstraint);
            }
            catch (AssertionException ex)
            {
                assertionText = ex.Message;
            }

            //Test conclusion
            Console.WriteLine(assertionText);
            Assert.That(assertionText, Is.StringContaining("not find"));
        }
コード例 #10
0
        public void WriteTo_FailingAssertionForHierarchy_TextContainsCaptionOfExpectedHierarchyAndCaptionOfFilters()
        {
            var description = new CommandDescription(Target.Hierarchies,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                                , new CaptionFilter(Target.Dimensions, "dimension-caption")
                        });

            var actuals = new string[] { "Actual hierarchy 1", "Actual hierarchy 2", "Actual hierarchy 3" };

            var commandStub = new Mock<IStructureDiscoveryCommand>();
            commandStub.Setup(cmd => cmd.Execute()).Returns(actuals);
            commandStub.Setup(cmd => cmd.Description).Returns(description);

            var existsConstraint = new ExistsConstraint("expected-hierarchy-caption");

            //Method under test
            string assertionText = null;
            try
            {
                Assert.That(commandStub.Object, existsConstraint);
            }
            catch (AssertionException ex)
            {
                assertionText = ex.Message;
            }

            //Test conclusion
            Console.WriteLine(assertionText);
            Assert.That(assertionText, Is.StringContaining("perspective-name").And
                                            .StringContaining("dimension-caption").And
                                            .StringContaining("expected-hierarchy-caption"));
        }
コード例 #11
0
ファイル: ExistsConstraintTest.cs プロジェクト: zyh329/nbi
        public void Matches_GivenDiscoveryRequest_CommandCalledOnce()
        {
            var request = new DiscoveryRequestFactory().BuildDirect(
                        "connectionString",
                        DiscoveryTarget.MeasureGroups,
                        new List<IFilter>()
                            {
                                new CaptionFilter("perspective-name", DiscoveryTarget.Perspectives)
                                , new CaptionFilter("measure-group", DiscoveryTarget.MeasureGroups)
                                , new CaptionFilter("measure", DiscoveryTarget.Measures)
                        });

            var elStub = new Mock<IField>();
            var el1 = elStub.Object;
            var el2 = elStub.Object;
            var elements = new List<IField>();
            elements.Add(el1);
            elements.Add(el2);

            var commandMock = new Mock<AdomdDiscoveryCommand>("connectionString");
            commandMock.Setup(f => f.Execute())
                .Returns(elements);

            var factoryStub = new Mock<AdomdDiscoveryCommandFactory>();
            factoryStub.Setup(f => f.BuildExact(request))
                .Returns(commandMock.Object);
            var factory = factoryStub.Object;

            var ctr = new ExistsConstraint() { CommandFactory = factory };

            //Method under test
            ctr.Matches(request);

            //Test conclusion
            commandMock.Verify(c => c.Execute(), Times.Once());
        }
コード例 #12
0
ファイル: ExistsConstraintTest.cs プロジェクト: zyh329/nbi
        public void WriteTo_FailingAssertionForPerspective_TextContainsNameOfExpectedPerspective()
        {
            var request = new DiscoveryRequestFactory().BuildDirect(
                        "connectionString",
                        DiscoveryTarget.Perspectives,
                        new List<IFilter>()
                            {
                                new CaptionFilter("expected-perspective-name", DiscoveryTarget.Perspectives)
                        });

            var elements = new List<IField>();

            var commandExactStub = new Mock<AdomdDiscoveryCommand>("connectionString");
            commandExactStub.Setup(f => f.Execute())
                .Returns(elements);

            var commandExternalStub = new Mock<AdomdDiscoveryCommand>("connectionString");
            commandExternalStub.Setup(f => f.Execute())
                .Returns(elements);

            var factoryStub = new Mock<AdomdDiscoveryCommandFactory>();
            factoryStub.Setup(f => f.BuildExact(request))
                .Returns(commandExactStub.Object);

            factoryStub.Setup(f => f.BuildExternal(It.IsAny<MetadataDiscoveryRequest>()))
                .Returns(commandExternalStub.Object);
            var factory = factoryStub.Object;

            var existsConstraint = new ExistsConstraint() { CommandFactory = factory };

            //Method under test
            string assertionText = null;
            try
            {
                Assert.That(request, existsConstraint);
            }
            catch (AssertionException ex)
            {
                assertionText = ex.Message;
            }

            //Test conclusion
            Console.WriteLine(assertionText);
            Assert.That(assertionText, Is.StringContaining("expected-perspective-name"));
        }
コード例 #13
0
ファイル: ExistsConstraintTest.cs プロジェクト: zyh329/nbi
        public void WriteTo_FailingAssertionForDimensionWithMinorMistake_TextContainsTheSuggestionOfValue()
        {
            var request = new DiscoveryRequestFactory().BuildDirect(
                        "connectionString",
                        DiscoveryTarget.Dimensions,
                        new List<IFilter>()
                            {
                                new CaptionFilter("perspective-name", DiscoveryTarget.Perspectives)
                                , new CaptionFilter("expected-dimension-caption", DiscoveryTarget.Dimensions)
                        });

            var commandExactStub = new Mock<AdomdDiscoveryCommand>("connectionString");
            commandExactStub.Setup(f => f.Execute())
                .Returns(new List<Dimension>());

            var commandExternalStub = new Mock<AdomdDiscoveryCommand>("connectionString");
            commandExternalStub.Setup(f => f.Execute())
                 .Returns(new List<Dimension>()
                    {
                        new Dimension("Dimension", "expected-dimension-catpion") , //two letters permutted
                        new Dimension("Toto", "Toto")
                    });

            var factoryStub = new Mock<AdomdDiscoveryCommandFactory>();
            factoryStub.Setup(f => f.BuildExact(request))
                .Returns(commandExactStub.Object);

            factoryStub.Setup(f => f.BuildExternal(It.IsAny<MetadataDiscoveryRequest>()))
                .Returns(commandExternalStub.Object);
            var factory = factoryStub.Object;

            var existsConstraint = new ExistsConstraint() { CommandFactory = factory };

            //Method under test
            string assertionText = null;
            try
            {
                Assert.That(request, existsConstraint);
            }
            catch (AssertionException ex)
            {
                assertionText = ex.Message;
            }

            //Test conclusion
            Console.WriteLine(assertionText);
            Assert.That(assertionText, Is.StringContaining("The value 'expected-dimension-catpion' is close to your expectation."));
        }
コード例 #14
0
ファイル: ExistsConstraintTest.cs プロジェクト: zyh329/nbi
        public void Matches_GivenDiscoveryRequest_FactoryCalledOnceWithParametersComingFromRequest()
        {
            var request = new DiscoveryRequestFactory().BuildDirect(
                        "connectionString",
                        DiscoveryTarget.Dimensions,
                        new List<IFilter>()
                            {
                                new CaptionFilter("perspective-name", DiscoveryTarget.Perspectives)
                                , new CaptionFilter("expected-dimension-caption", DiscoveryTarget.Dimensions)
                        });

            var elStub = new Mock<IField>();
            var el1 = elStub.Object;
            var el2 = elStub.Object;
            var elements = new List<IField>();
            elements.Add(el1);
            elements.Add(el2);

            var commandStub = new Mock<AdomdDiscoveryCommand>("connectionString");
            commandStub.Setup(f => f.Execute())
                .Returns(elements);

            var factoryMock = new Mock<AdomdDiscoveryCommandFactory>();
            factoryMock.Setup(f => f.BuildExact(request))
                .Returns(commandStub.Object);
            var factory = factoryMock.Object;

            var ctr = new ExistsConstraint() { CommandFactory = factory };

            //Method under test
            ctr.Matches(request);

            //Test conclusion
            factoryMock.Verify(f => f.BuildExact(request), Times.Once());
        }