Exemplo n.º 1
0
        public void Matches_AnyResultSets_EngineCalledOnceResultSetBuilderTwice()
        {
            var rs = new ResultSet();
            rs.Load("a;b;c");
            var cmd = new SqlCommand();

            var rsbMock = new Mock<ResultSetBuilder>();
            rsbMock.Setup(engine => engine.Build(It.IsAny<object>()))
                .Returns(rs);
            var rsb = rsbMock.Object;

            var rscMock = new Mock<IResultSetComparer>();
            rscMock.Setup(engine => engine.Compare(It.IsAny<ResultSet>(), It.IsAny<ResultSet>()))
                .Returns(new ResultSetCompareResult() { Difference = ResultSetDifferenceType.None });
            var rsc = rscMock.Object;

            var equalToConstraint = new EqualToConstraint(rs) {Engine = rsc, ResultSetBuilder=rsb };
            equalToConstraint.ResultSetBuilder = rsb;

            //Method under test
            equalToConstraint.Matches(cmd);

            //Test conclusion
            //Test conclusion
            rscMock.Verify(engine => engine.Compare(It.IsAny<ResultSet>(), It.IsAny<ResultSet>()), Times.Once());
            rsbMock.Verify(engine => engine.Build(It.IsAny<object>()), Times.Exactly(2));
        }
Exemplo n.º 2
0
        public void Matches_MdxQueryAndDecimalResulSetWithCorrectSettings_Matching()
        {
            //Buiding object used during test
            var rs = new ResultSet();
            var objs = new List<object[]>();
            objs.Add(new object[] { "CY 2005", 1874469.00 });
            objs.Add(new object[] { "CY 2006", 4511243.0 });
            objs.Add(new object[] { "CY 2007", 4709851 });
            objs.Add(new object[] { "CY 2008", 1513940 });
            rs.Load(objs);

            var ctr = new EqualToConstraint(rs);
            ctr.Using(new ResultSetComparisonSettings(
                ResultSetComparisonSettings.KeysChoice.First,
                ResultSetComparisonSettings.ValuesChoice.Last,
                NumericAbsoluteTolerance.None)
            );

            var query = "SELECT [Measures].[Amount] ON 0, NON EMPTY([Date].[Calendar].[Calendar Year]) ON 1 FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.True);
        }
Exemplo n.º 3
0
        public void Matches_AnyIDbCommandAsActualAndAnyPathAsExpectation_EngineCompareTheTwoResultSetsPreviouslyCreated()
        {
            var rsActual = new ResultSet();
            rsActual.Load("a;b;c");
            var rsExpect = new ResultSet();
            rsExpect.Load("x;y;z");
            var cmd = new SqlCommand();

            var rsbStub = new Mock<IResultSetBuilder>();
            rsbStub.Setup(engine => engine.Build(It.IsAny<IDbCommand>()))
                .Returns(rsActual);
            rsbStub.Setup(engine => engine.Build(It.IsAny<string>()))
                .Returns(rsExpect);

            var rsbFake = rsbStub.Object;

            var rscMock = new Mock<IResultSetComparer>();
            rscMock.Setup(engine => engine.Compare(rsActual, rsExpect))
                .Returns(ResultSetCompareResult.NotMatching);
            var rsc = rscMock.Object;

            var equalToConstraint = new EqualToConstraint("my path for expectation") {ResultSetBuilder = rsbFake, Engine = rsc };

            //Method under test
            equalToConstraint.Matches(cmd);

            //Test conclusion
            //Test conclusion
            rscMock.Verify(engine => engine.Compare(rsActual, rsExpect), Times.Once());
        }
Exemplo n.º 4
0
        public void Matches_MdxQueryAndResulSetCsvFile_Matching()
        {
            //Buiding object used during test
            var filename = DiskOnFile.CreatePhysicalFile("NonEmptyAmountByYear.csv", "NBi.Testing.Integration.NUnit.Resources.NonEmptyAmountByYear.csv");

            var ctr = new EqualToConstraint(filename);

            var query = "SELECT [Measures].[Amount] ON 0, NON EMPTY([Date].[Calendar].[Calendar Year]) ON 1 FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.True);
        }
Exemplo n.º 5
0
        public void Matches_IDbCommandAsActualAndPathAsExpectation_ResulSetBuildersCreateResultSetsUsingActualAndExpectationProvided()
        {
            var rsActual = new ResultSet();
            rsActual.Load("a;b;1");
            var rsExpect = new ResultSet();
            rsExpect.Load("x;y;2");
            var cmd = new SqlCommand();

            var rsbMock = new Mock<IResultSetBuilder>();
            rsbMock.Setup(engine => engine.Build(cmd))
                .Returns(rsActual);
            rsbMock.Setup(engine => engine.Build("my path for expectation"))
                .Returns(rsExpect);
            var rsb = rsbMock.Object;

            var equalToConstraint = new EqualToConstraint("my path for expectation") {ResultSetBuilder = rsb };

            //Method under test
            equalToConstraint.Matches(cmd);

            //Test conclusion
            //Test conclusion
            rsbMock.Verify(engine => engine.Build(cmd), Times.Once());
            rsbMock.Verify(engine => engine.Build("my path for expectation"), Times.Once());
        }
Exemplo n.º 6
0
        public void Matches_TwoIdenticalResultSets_ReturnTrue()
        {
            var rs = new ResultSet();
            rs.Load("a;X;1");

            var cmd = new SqlCommand();

            var rsbMock = new Mock<IResultSetBuilder>();
            rsbMock.Setup(engine => engine.Build(It.IsAny<IDbCommand>()))
                .Returns(rs);
            rsbMock.Setup(engine => engine.Build(rs))
                .Returns(rs);
            var rsb = rsbMock.Object;

            var equalToConstraint = new EqualToConstraint(rs) { ResultSetBuilder = rsb };

            //Method under test
            var res = equalToConstraint.Matches(cmd);

            //Test conclusion
            rsbMock.Verify(engine => engine.Build(rs), Times.Once());
            Assert.That(res, Is.True);
        }
Exemplo n.º 7
0
        public void Matches_TwoDifferentResultSets_ReturnFalse()
        {
            var rsActual = new ResultSet();
            rsActual.Load("a;b;1");
            var rsExpect = new ResultSet();
            rsExpect.Load("a;X;1");

            var cmd = new SqlCommand();

            var rsbMock = new Mock<IResultSetBuilder>();
            rsbMock.Setup(engine => engine.Build(It.IsAny<IDbCommand>()))
                .Returns(rsActual);
            rsbMock.Setup(engine => engine.Build(rsExpect))
                .Returns(rsExpect);
            var rsb = rsbMock.Object;

            var equalToConstraint = new EqualToConstraint(rsExpect) {ResultSetBuilder = rsb };

            //Method under test
            var res = equalToConstraint.Matches(cmd);

            //Test conclusion
            rsbMock.Verify(engine => engine.Build(rsExpect), Times.Once());
            Assert.That(res, Is.False);
        }
Exemplo n.º 8
0
        public void Matches_SqlQueryWithDateComparedToString_Matching()
        {
            //Buiding object used during test
            var expectedQuery = "SELECT 'CY 2010',  CAST('2010-01-01' AS DATE)";

            var expectedCmd = new SqlCommand(expectedQuery, new SqlConnection(ConnectionStringReader.GetSqlClient()));

            var columns = new List<IColumnDefinition>();
            columns.Add(new Column() { Index = 1, Role = ColumnRole.Value, Type = ColumnType.DateTime });

            var ctr = new EqualToConstraint(expectedCmd);
            ctr.Using(
                    new ResultSetComparisonSettings(
                        ResultSetComparisonSettings.KeysChoice.AllExpectLast,
                        ResultSetComparisonSettings.ValuesChoice.Last,
                        columns
                    )
                );

            var query = "SELECT 'CY 2010',  '1/01/2010 00:00:00'";
            var cmd = new SqlCommand(query, new SqlConnection(ConnectionStringReader.GetSqlClient()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.True);
        }
Exemplo n.º 9
0
        public void Matches_MdxQueryWithNullComparedToSqlWithValue_NonMatching()
        {
            //Buiding object used during test
            var expectedQuery = "SELECT 'CY 2010',  0 ";

            var expectedCmd = new SqlCommand(expectedQuery, new SqlConnection(ConnectionStringReader.GetSqlClient()));

            var ctr = new EqualToConstraint(expectedCmd);
            ctr.Using(
                    new ResultSetComparisonSettings(
                        ResultSetComparisonSettings.KeysChoice.AllExpectLast,
                        ResultSetComparisonSettings.ValuesChoice.Last,
                        NumericAbsoluteTolerance.None
                    )
                );

            var query = "SELECT  [Measures].[Amount] ON 0, [Date].[Calendar].[Calendar Year].&[2010] ON 1 FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.False);
        }
Exemplo n.º 10
0
        public void Matches_MdxQueryAndSqlQueryWithCorrectSettings_Matching()
        {
            //Buiding object used during test
            var expectedQuery = "SELECT 'CY 2005',  1874469 UNION ";
            expectedQuery += " SELECT 'CY 2006', 4511243 UNION ";
            expectedQuery += " SELECT 'CY 2007', 4709851 UNION ";
            expectedQuery += " SELECT 'CY 2008', 1513940  ";

            var expectedCmd = new SqlCommand(expectedQuery, new SqlConnection(ConnectionStringReader.GetSqlClient()));

            var ctr = new EqualToConstraint(expectedCmd);
            ctr.Using(
                    new ResultSetComparisonSettings(
                        ResultSetComparisonSettings.KeysChoice.AllExpectLast,
                        ResultSetComparisonSettings.ValuesChoice.Last,
                        new List<IColumnDefinition>()
                        {
                            new Column()
                            {
                                Index = 1,
                                Role = ColumnRole.Value,
                                Type = ColumnType.Numeric,
                                Tolerance = "5"
                            }
                        }
                    )
                );

            var query = "SELECT  [Measures].[Amount] ON 0, NON EMPTY([Date].[Calendar].[Calendar Year]) ON 1 FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.True);
        }
Exemplo n.º 11
0
        public void Matches_MdxQueryAndSlighltyDifferentQueryWithCorrectSettings_NotMatching()
        {
            //Buiding object used during test
            var expectedQuery = "WITH MEMBER [Measures].NewAmount AS [Measures].[Amount]+1";
            expectedQuery += " SELECT [Measures].NewAmount ON 0, NON EMPTY([Date].[Calendar].[Calendar Year]) ON 1 FROM [Adventure Works]";
            var expectedCmd = new AdomdCommand(expectedQuery, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            var ctr = new EqualToConstraint(expectedCmd);
            ctr.Using(new ResultSetComparisonSettings(
                ResultSetComparisonSettings.KeysChoice.First,
                ResultSetComparisonSettings.ValuesChoice.Last,
                NumericAbsoluteTolerance.None)
            );

            var query = "SELECT [Measures].[Amount] ON 0, ([Date].[Calendar].[Calendar Year]-[Date].[Calendar].[Calendar Year].&[2010]) ON 1  FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.False);
        }
Exemplo n.º 12
0
        public void Matches_MdxQueryAndSlighltyDifferentQueryWithCorrectSettingsAndTolerance_Matching()
        {
            //Buiding object used during test
            var expectedQuery = "WITH MEMBER [Measures].NewAmount AS [Measures].[Amount]+1";
            expectedQuery += " SELECT [Measures].NewAmount ON 0, ([Date].[Calendar].[Calendar Year].[CY 2005]:[Date].[Calendar].[Calendar Year].[CY 2008]) ON 1  FROM [Adventure Works]";
            var expectedCmd   = new AdomdCommand(expectedQuery, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            var ctr = new EqualToConstraint(expectedCmd);
            ctr.Using(new ResultSetComparisonSettings(
                    ResultSetComparisonSettings.KeysChoice.First,
                    ResultSetComparisonSettings.ValuesChoice.Last,
                    new List<IColumnDefinition>()
                    {
                        new Column()
                        {
                            Index=1,
                            Role= ColumnRole.Value,
                            Type=ColumnType.Numeric,
                            Tolerance= "10"
                        }
                    }
                )
            );

            var query = "SELECT  [Measures].[Amount] ON 0, NON EMPTY([Date].[Calendar].[Calendar Year]) ON 1 FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.True);
        }
Exemplo n.º 13
0
        public void Matches_MdxQueryAndResulSetWithoutKeyValuesInfo_Matching()
        {
            //Buiding object used during test
            var rs = new ResultSet();
            var objs = new List<object[]>();
            objs.Add(new object[] { "CY 2005", "1874469.00" });
            objs.Add(new object[] { "CY 2006", "4511243.0" });
            objs.Add(new object[] { "CY 2007", "4709851" });
            objs.Add(new object[] { "CY 2008", "1513940" });
            rs.Load(objs);

            var ctr = new EqualToConstraint(rs);

            var query = "SELECT [Measures].[Amount] ON 0, NON EMPTY([Date].[Calendar].[Calendar Year]) ON 1 FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.True);
        }