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()); }
public void Matches_MdxQueryAndResulSetWithCorrectSettings_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, new NumericAbsoluteTolerance(500, SideTolerance.Both) ) ); 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); }
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)); }
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); }
public void Matches_TwoQueriesOfThreeSecondsSequential_SlowerThanSixSeconds() { var command = new SqlCommand(); command.Connection = new SqlConnection(ConnectionStringReader.GetSqlClient()); command.CommandText = "WAITFOR DELAY '00:00:03';SELECT 1;"; var command2 = new SqlCommand(); command2.Connection = new SqlConnection(ConnectionStringReader.GetSqlClient()); command2.CommandText = "WAITFOR DELAY '00:00:03';SELECT 1;"; var ctr = new EqualToConstraint(command2); ctr = ctr.Sequential(); //Method under test var chrono = DateTime.Now; Assert.That(command, ctr); var elapsed = DateTime.Now.Subtract(chrono); Assert.That(elapsed.Seconds, Is.GreaterThanOrEqualTo(6)); }
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); }
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); }
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); }
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()); }
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); }
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); }
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); }
public static EqualToConstraint EqualTo(IEnumerable<IRow> rows) { var ctr = new EqualToConstraint(rows); return ctr; }
public static EqualToConstraint EqualTo(IDbCommand command) { var ctr = new EqualToConstraint(command); return ctr; }
public static EqualToConstraint EqualTo(ResultSet resultSet) { var ctr = new EqualToConstraint(resultSet); return ctr; }
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); }
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); }
protected global::NUnit.Framework.Constraints.Constraint InstantiateConstraint() { EqualToConstraint ctr = null; if (ConstraintXml.GetCommand() != null) { var commandText = ConstraintXml.GetCommand().CommandText; var connectionString = ConstraintXml.GetCommand().Connection.ConnectionString; IEnumerable<IQueryParameter> parameters = null; IEnumerable<IQueryTemplateVariable> variables = null; if (ConstraintXml.Query != null) { parameters = ConstraintXml.Query.GetParameters(); variables = ConstraintXml.Query.GetVariables(); } var commandBuilder = new CommandBuilder(); var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables); ctr = new EqualToConstraint(cmd); } else if (ConstraintXml.ResultSet != null) { if (!string.IsNullOrEmpty(ConstraintXml.ResultSet.File)) { Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in external file!"); ctr = new EqualToConstraint(ConstraintXml.ResultSet.GetFile()); } else if (ConstraintXml.ResultSet.Rows!=null) { Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in embedded resultSet!"); ctr = new EqualToConstraint(ConstraintXml.ResultSet.Rows); } } if (ctr==null) throw new ArgumentException(); //Manage settings for comparaison ResultSetComparisonSettings settings = new ResultSetComparisonSettings( ConstraintXml.KeysDef, ConstraintXml.ValuesDef, ToleranceFactory.BuildNumeric(ConstraintXml.Tolerance), ConstraintXml.ColumnsDef ); ctr.Using(settings); if (ConstraintXml.ParallelizeQueries) ctr = ctr.Parallel(); else ctr = ctr.Sequential(); //Manage persistance //EqualToConstraint.PersistanceItems persi = 0; //if (ConstraintXml.GetCommand() != null) // persi += (int)EqualToConstraint.PersistanceItems.actual; //if (SystemUnderTestXml is QueryXml) // persi += (int)EqualToConstraint.PersistanceItems.expected; //if (!(persi==0 || ConstraintXml.Query==null || string.IsNullOrEmpty(ConstraintXml.Test.Name))) // ctr.Persist(ConstraintXml.Persistance, persi, ConstraintXml.Test.Name); return ctr; }
protected NBiConstraint InstantiateConstraint() { EqualToConstraint ctr = null; if (ConstraintXml.GetCommand() != null) { var commandText = ConstraintXml.GetCommand().CommandText; var connectionString = ConstraintXml.GetCommand().Connection.ConnectionString; IEnumerable<IQueryParameter> parameters = null; IEnumerable<IQueryTemplateVariable> variables = null; if (ConstraintXml.Query != null) { parameters = ConstraintXml.Query.GetParameters(); variables = ConstraintXml.Query.GetVariables(); } var commandBuilder = new CommandBuilder(); var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables); ctr = new EqualToConstraint(cmd); } else if (ConstraintXml.ResultSet != null) { if (!string.IsNullOrEmpty(ConstraintXml.ResultSet.File)) { Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in external file!"); ctr = new EqualToConstraint(ConstraintXml.ResultSet.GetFile()); if (ConstraintXml.Settings.CsvProfile != null) ctr=ctr.CsvProfile(ConstraintXml.Settings.CsvProfile); } else if (ConstraintXml.ResultSet.Rows!=null) { Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in embedded resultSet!"); ctr = new EqualToConstraint(ConstraintXml.ResultSet.Rows); } } else if (ConstraintXml.XmlSource != null) { if (!string.IsNullOrEmpty(ConstraintXml.XmlSource.GetFile())) { Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, string.Format("Xml file at '{0}'", ConstraintXml.XmlSource.GetFile())); var selects = new List<AbstractSelect>(); var factory = new SelectFactory(); foreach (var select in ConstraintXml.XmlSource.XPath.Selects) selects.Add(factory.Instantiate(select.Value, select.Attribute)); var engine = new XPathFileEngine(ConstraintXml.XmlSource.GetFile(), ConstraintXml.XmlSource.XPath.From.Value, selects); ctr = new EqualToConstraint(engine); } else throw new ArgumentException("File's can't be empty when declaring an xml-source."); } if (ctr==null) throw new ArgumentException(); //Manage settings for comparaison var settings = new ResultSetComparisonSettings( ConstraintXml.KeysDef, ConstraintXml.ValuesDef, ConstraintXml.ValuesDefaultType, new NumericToleranceFactory().Instantiate(ConstraintXml.Tolerance), ConstraintXml.ColumnsDef ); ctr.Using(settings); if (ConstraintXml.ParallelizeQueries) ctr = ctr.Parallel(); else ctr = ctr.Sequential(); //Manage persistance //EqualToConstraint.PersistanceItems persi = 0; //if (ConstraintXml.GetCommand() != null) // persi += (int)EqualToConstraint.PersistanceItems.actual; //if (SystemUnderTestXml is QueryXml) // persi += (int)EqualToConstraint.PersistanceItems.expected; //if (!(persi==0 || ConstraintXml.Query==null || string.IsNullOrEmpty(ConstraintXml.Test.Name))) // ctr.Persist(ConstraintXml.Persistance, persi, ConstraintXml.Test.Name); return ctr; }