protected internal TestSuiteXml BuildResultSetsBased() { var testSuite = new TestSuiteXml(); var queries = Directory.GetFiles(actual.Directory); foreach (var query in queries) { if (File.Exists(Path.Combine(expect.Directory, Path.GetFileNameWithoutExtension(query) + ".csv"))) { var test = new TestXml(); testSuite.Tests.Add(test); test.Name = Path.GetFileNameWithoutExtension(query); test.Categories.AddRange(Path.GetFileNameWithoutExtension(query).Split(new string[] { " - " }, StringSplitOptions.RemoveEmptyEntries)); var ctr = new EqualToXml(); test.Constraints.Add(ctr); ctr.ResultSetOld = new ResultSetXml() { File = Path.Combine(expect.Directory, Path.GetFileNameWithoutExtension(query) + ".csv") }; var sut = new Systems.ExecutionXml(); test.Systems.Add(sut); ((QueryXml)sut.Item).File = query; ((QueryXml)sut.Item).ConnectionString = actual.ConnectionString; } } return(testSuite); }
protected override void BaseSetup(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml) { if (!(sutXml is ExecutionXml)) throw new ArgumentException("System-under-test must be a 'ExecutionXml'"); SystemUnderTestXml = (ExecutionXml)sutXml; }
public void GetQuery_FilenameNotSpecified_RetrieveContentOfInlineQuery() { //Instantiate a System Under Test var systemUnderTest = new ExecutionXml() { Item = new QueryXml() { InlineQuery = "SELECT * FROM Product" } }; Assert.That(((QueryXml)systemUnderTest.Item).GetQuery(), Is.EqualTo("SELECT * FROM Product")); Assert.That(((QueryXml)systemUnderTest.Item).InlineQuery, Is.Not.Null.And.Not.Empty.And.ContainsSubstring("SELECT")); Assert.That(((QueryXml)systemUnderTest.Item).File, Is.Null); }
protected override IDbCommand InstantiateSystemUnderTest(ExecutionXml xml) { if (xml.Item is QueryableXml) { var commandText = (xml.Item as QueryableXml).GetQuery(); var connectionString = xml.Item.GetConnectionString(); var parameters = (xml.Item as QueryableXml).GetParameters(); var variables = (xml.Item as QueryableXml).GetVariables(); var commandBuilder = new CommandBuilder(); var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables); return cmd; } throw new ArgumentException(); }
public void GetQuery_FilenameSpecified_RetrieveContentWithEuroSymbol() { //create a text file on disk var filename = DiskOnFile.CreatePhysicalFile("QueryFile€.mdx", "NBi.Testing.Unit.Xml.Resources.QueryFileEuro.mdx"); //Instantiate a Test Case and specify to find the sql in the file created above var testCase = new ExecutionXml() { Item = new QueryXml() { File = filename } }; // A Stream is needed to read the text file from the assembly. string expectedContent = "select [measure].[price €/Kg] on 0;"; Assert.AreEqual(expectedContent, ((QueryableXml)testCase.Item).GetQuery()); }
public void GetQuery_FileNameSpecified_RetrieveContentOfFile() { //Create the queryfile to read var filename = "Select all products.sql"; DiskOnFile.CreatePhysicalFile(filename, "NBi.Testing.Unit.Xml.Resources.SelectAllProducts.sql"); var systemUnderTest = new ExecutionXml() { Item = new QueryXml() { File = filename, Settings = new NBi.Xml.Settings.SettingsXml() { BasePath=DiskOnFile.GetDirectoryPath() } } }; // Check the properties of the object. Assert.That(((QueryXml)systemUnderTest.Item).File, Is.Not.Null.And.Not.Empty); Assert.That(((QueryXml)systemUnderTest.Item).InlineQuery, Is.Null); Assert.That(((QueryXml)systemUnderTest.Item).GetQuery(), Is.Not.Null.And.Not.Empty.And.ContainsSubstring("SELECT")); }
public void GetQuery_FilenameSpecified_RetrieveContentOfFile() { //create a text file on disk var filename = DiskOnFile.CreatePhysicalFile("QueryFile.sql", "NBi.Testing.Unit.Xml.Resources.QueryFile.sql"); //Instantiate a Test Case and specify to find the sql in the file created above var testCase = new ExecutionXml() { Item = new QueryXml() { File = filename } }; // A Stream is needed to read the text file from the assembly. string expectedContent; using (Stream stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("NBi.Testing.Unit.Xml.Resources.QueryFile.sql")) using (StreamReader reader = new StreamReader(stream)) expectedContent = reader.ReadToEnd(); Assert.AreEqual(expectedContent, (testCase.Item as QueryableXml).GetQuery()); }
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(); }
protected virtual IDbCommand InstantiateSystemUnderTest(ExecutionXml executionXml) { var commandBuilder = new CommandBuilder(); var connectionString = executionXml.Item.GetConnectionString(); var commandText = (executionXml.Item as QueryableXml).GetQuery(); IEnumerable<IQueryParameter> parameters=null; IEnumerable<IQueryTemplateVariable> variables = null; if (executionXml.BaseItem is QueryXml) { parameters = ((QueryXml)executionXml.BaseItem).GetParameters(); variables = ((QueryXml)executionXml.BaseItem).GetVariables(); } if (executionXml.BaseItem is ReportXml) { parameters = ((ReportXml)executionXml.BaseItem).GetParameters(); } var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables); return cmd; }
public void IsHandling_QuerySyntacticallyCorrect_True() { var sutXml = new ExecutionXml(); var ctrXml = new SyntacticallyCorrectXml(); var testCaseFactory = new TestCaseFactory(); var actual = testCaseFactory.IsHandling(sutXml.GetType(), ctrXml.GetType()); Assert.That(actual, Is.True); }
public void IsHandling_QueryRowCount_True() { var sutXml = new ExecutionXml(); var ctrXml = new RowCountXml(); var testCaseFactory = new TestCaseFactory(); var actual = testCaseFactory.IsHandling(sutXml.GetType(), ctrXml.GetType()); Assert.That(actual, Is.True); }
public void IsHandling_QueryOrdered_False() { var sutXml = new ExecutionXml(); var ctrXml = new OrderedXml(); var testCaseFactory = new TestCaseFactory(); var actual = testCaseFactory.IsHandling(sutXml.GetType(), ctrXml.GetType()); Assert.That(actual, Is.False); }
public void IsHandling_ExecutionMatchPattern_True() { var sutXml = new ExecutionXml(); var ctrXml = new MatchPatternXml(); var testCaseFactory = new TestCaseFactory(); var actual = testCaseFactory.IsHandling(sutXml.GetType(), ctrXml.GetType()); Assert.That(actual, Is.True); }
public void Instantiate_QueryOrdered_ArgumentException() { var sutXml = new ExecutionXml(); var ctrXml = new OrderedXml(); var testCaseFactory = new TestCaseFactory(); Assert.Throws<ArgumentException>(delegate { testCaseFactory.Instantiate(sutXml, ctrXml); }); }
public void Instantiate_QuerySyntacticallyCorrect_TestCase() { var sutXml = new ExecutionXml(); var ctrXml = new SyntacticallyCorrectXml(); var builderMockFactory = new Mock<ITestCaseBuilder>(); builderMockFactory.Setup(b => b.Setup(sutXml, ctrXml)); builderMockFactory.Setup(b => b.Build()); builderMockFactory.Setup(b => b.GetSystemUnderTest()).Returns(new SqlCommand()); builderMockFactory.Setup(b => b.GetConstraint()).Returns(new SyntacticallyCorrectConstraint()); var builder = builderMockFactory.Object; var testCaseFactory = new TestCaseFactory(); testCaseFactory.Register(typeof(ExecutionXml), typeof(SyntacticallyCorrectXml), builder); var tc = testCaseFactory.Instantiate(sutXml, ctrXml); Assert.That(tc, Is.Not.Null); builderMockFactory.VerifyAll(); }
protected IExecution InstantiateSystemUnderTest(ExecutionXml executionXml) { var factory = new ExecutionFactory(); var instance = factory.Get(executionXml.BaseItem as IExecutable); return instance; }