public StructureDiscoveryCommand Instantiate(Target target, TargetType type, IEnumerable<CaptionFilter> filters)
        {
            if (!(connection is AdomdConnection))
                throw new ArgumentException();

            var builder = InstantiateBuilder(target, type);
            builder.Build(filters);

            var cmd = connection.CreateCommand();
            cmd.CommandText = builder.GetCommandText();
            var postFilters = builder.GetPostFilters();

            var description = new CommandDescription(target, filters);

            OlapCommand command = null;
            if ((target == Target.MeasureGroups && type == TargetType.Object) || target == Target.Perspectives)
                command = new DistinctOlapCommand(cmd, postFilters, description);
            else if (target == Target.Dimensions && type == TargetType.Object)
                command = new DimensionCommand(cmd, postFilters, description);
            else if (target == Target.Dimensions && type == TargetType.Relation)
                command = new DimensionRelationCommand(cmd, postFilters, description);
            else
                command = new OlapCommand(cmd, postFilters, description);

            return command;
        }
        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);
        }
        public void WriteTo_FailingAssertionForListOfLevels_TextContainsFewKeyInfo()
        {
            var exp = new string[] { "Expected level 1", "Expected level 2" };

            var description = new CommandDescription(
                        Target.Levels,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                                , new CaptionFilter(Target.Dimensions, "dimension-caption")
                                , new CaptionFilter(Target.Hierarchies, "hierarchy-caption" )
                        });

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

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

            var containsConstraint = new EquivalentToConstraint(exp);

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

            //Test conclusion
            Assert.That(assertionText, Is.StringContaining("exact").And
                                            .StringContaining("perspective-name").And
                                            .StringContaining("dimension-caption").And
                                            .StringContaining("hierarchy-caption").And
                                            .StringContaining("levels").And
                                            .StringContaining("Expected level 1").And
                                            .StringContaining("Expected level 2"));
        }
        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());
        }
        public void Matches_GivenCommand_CommandExecuteCalledOnce()
        {
            var exp = "Expected hierarchy";
            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" };

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

            var containsConstraint = new ContainConstraint(exp) {};

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

            //Test conclusion
            commandMock.Verify(cmd => cmd.Execute(), Times.Once());
        }
 public RelationalCommand(IDbCommand command, IEnumerable<IPostCommandFilter> postFilters, CommandDescription description)
     : base(command, postFilters, description)
 {
 }
        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."));
        }
        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"));
        }
        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"));
        }
 protected internal StructureDiscoveryCommand(IDbCommand command, IEnumerable<IPostCommandFilter> postFilters, CommandDescription description)
 {
     this.command = command;
     this.postFilters = postFilters;
     this.description = description;
 }
 protected internal DimensionRelationCommand(IDbCommand command, IEnumerable<IPostCommandFilter> postFilters, CommandDescription description)
     : base(command, postFilters, description)
 {
 }
 public DistinctOlapCommand(IDbCommand command, IEnumerable<IPostCommandFilter> postFilters, CommandDescription description)
     : base(command, postFilters, description)
 {
 }
Beispiel #13
0
 protected internal StructureDiscoveryCommand(IDbCommand command, IEnumerable <IPostCommandFilter> postFilters, CommandDescription description)
 {
     this.command     = command;
     this.postFilters = postFilters;
     this.description = description;
 }
        public void WriteTo_FailingAssertionForTwoPerspectives_TextContainsFewKeyInfo()
        {
            var exp = new string[] { "Expected perspective 1", "Expected perspective 2" } ;
            var description = new CommandDescription(Target.Perspectives,
                        new CaptionFilter[] { });

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

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

            var containsConstraint = new ContainConstraint(exp) { };

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

            //Test conclusion
            Assert.That(assertionText, Is.StringContaining("find the perspectives named").And
                                            .StringContaining("Expected perspective 1").And
                                            .StringContaining("Expected perspective 2").And
                                            .StringContaining(".").And
                                            .StringContaining("Actual perspective 1").And
                                            .StringContaining("Actual perspective 2").And
                                            .Not.StringContaining("contain"));
        }
        public void WriteTo_FailingAssertionForOneMeasureGroup_TextContainsFewKeyInfo()
        {
            var exp = "Expected measure";
            var description = new CommandDescription(Target.Hierarchies,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                                , new CaptionFilter(Target.MeasureGroups, "measure-group-caption")
                        });

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

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

            var containsConstraint = new ContainConstraint(exp) { };

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

            //Test conclusion
            Assert.That(assertionText, Is.StringContaining("perspective-name").And
                                            .StringContaining("measure-group-caption").And
                                            .StringContaining("Expected measure"));
        }