How to use QueryXml class of NBi.Xml.Items package

Best NBi code snippet using NBi.Xml.Items.QueryXml

QueryResolverArgsBuilder.cs

Source:QueryResolverArgsBuilder.cs Github

copy

Full Screen

...29 public QueryResolverArgsBuilder(ServiceLocator serviceLocator)30 {31 this.serviceLocator = serviceLocator;32 }33 public void Setup(QueryXml queryXml, SettingsXml settingsXml, SettingsXml.DefaultScope scope, IDictionary<string, IVariable> variables)34 {35 obj = queryXml;36 Settings = settingsXml ?? SettingsXml.Empty;37 Scope = scope;38 Variables = variables;39 isSetup = true;40 }41 public void Setup(ExecutableXml executableXml, SettingsXml settingsXml, IDictionary<string, IVariable> variables)42 {43 obj = executableXml;44 Settings = settingsXml ?? SettingsXml.Empty;45 Scope = SettingsXml.DefaultScope.SystemUnderTest;46 Variables = variables;47 isSetup = true;48 }49 public void Build()50 {51 if (!isSetup)52 throw new InvalidOperationException();53 switch (obj)54 {55 case QueryXml queryXml: Build(queryXml); break;56 case ExecutableXml executableXml: Build(executableXml); break;57 }58 }59 protected void Build(QueryXml queryXml)60 {61 queryXml.Settings = Settings;62 var connectionString = new ConnectionStringHelper().Execute(queryXml, Scope);63 var parameters = BuildParameters(queryXml.GetParameters());64 var templateVariables = queryXml.GetTemplateVariables();65 var timeout = Convert.ToInt32(Math.Ceiling(queryXml.Timeout / 1000m)); //Timeout is expressed in milliseconds66 if (!string.IsNullOrEmpty(queryXml.InlineQuery))67 args = new EmbeddedQueryResolverArgs(queryXml.InlineQuery68 , connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));69 else if (!string.IsNullOrEmpty(queryXml.File))70 {71 var file = GetFullPath(Settings?.BasePath, queryXml.File);72 args = new ExternalFileQueryResolverArgs(file73 , connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));74 }75 else if (queryXml.Assembly != null)76 args = Build(queryXml.Assembly, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));77 else if (queryXml.Report != null)78 args = Build(queryXml.Report, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));79 else if (queryXml.SharedDataset != null)80 args = Build(queryXml.SharedDataset, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));81 if (args == null)82 throw new ArgumentException();83 }84 private BaseQueryResolverArgs Build(AssemblyXml xml, string connectionString, IEnumerable<IQueryParameter> parameters, IEnumerable<IQueryTemplateVariable> templateVariables, TimeSpan timeout)85 {86 var file = GetFullPath(xml?.Settings?.BasePath, xml.Path);87 return new AssemblyQueryResolverArgs(88 file, xml.Klass, xml.Method,89 xml.Static, xml.GetMethodParameters()90 , connectionString, parameters, templateVariables, timeout);91 }92 private BaseQueryResolverArgs Build(ReportXml xml, string connectionString, IEnumerable<IQueryParameter> parameters, IEnumerable<IQueryTemplateVariable> templateVariables, TimeSpan timeout)93 {94 var path = string.IsNullOrEmpty(xml.Source) ? Settings.BasePath + xml.Path : xml.Path;95 return new ReportDataSetQueryResolverArgs(96 xml.Source, path, xml.Name, xml.Dataset97 , connectionString, parameters, templateVariables, timeout);98 }99 private BaseQueryResolverArgs Build(SharedDatasetXml xml, string connectionString, IEnumerable<IQueryParameter> parameters, IEnumerable<IQueryTemplateVariable> templateVariables, TimeSpan timeout)100 {101 var path = string.IsNullOrEmpty(xml.Source) ? Settings.BasePath + xml.Path : xml.Path;102 return new SharedDataSetQueryResolverArgs(103 xml.Source, path, xml.Name104 , connectionString, parameters, templateVariables, timeout);105 }106 protected void Build(ExecutableXml executableXml)107 {108 if (executableXml is QueryXml)109 Build(executableXml as QueryXml);110 else111 {112 var connectionString = new ConnectionStringHelper().Execute(executableXml, Scope);113 var queryableXml = executableXml as QueryableXml;114 var parameters = BuildParameters(queryableXml.GetParameters());115 var templateVariables = queryableXml.GetTemplateVariables();116 var timeout = queryableXml.Timeout;117 switch (executableXml)118 {119 case AssemblyXml xml: args = Build(xml, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout)); break;120 case ReportXml xml: args = Build(xml, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout)); break;121 case SharedDatasetXml xml: args = Build(xml, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout)); break;122 }123 }...

Full Screen

Full Screen

TestSuiteBuilder.cs

Source:TestSuiteBuilder.cs Github

copy

Full Screen

...6869 var ctr = new EqualToXml();70 test.Constraints.Add(ctr);7172 ctr.Query = new QueryXml()73 {74 File = Path.Combine(expect.Directory, Path.GetFileName(query)),75 ConnectionString = expect.ConnectionString76 };7778 var sut = new Systems.ExecutionXml();79 test.Systems.Add(sut);80 ((QueryXml)sut.Item).File = query;81 ((QueryXml)sut.Item).ConnectionString = actual.ConnectionString;82 }83 }84 return testSuite;85 }8687 protected internal TestSuiteXml BuildResultSetsBased()88 {89 var testSuite = new TestSuiteXml();9091 var queries = Directory.GetFiles(actual.Directory);92 foreach (var query in queries)93 {94 if (File.Exists(Path.Combine(expect.Directory, Path.GetFileNameWithoutExtension(query) + ".csv")))95 {96 var test = new TestXml();9798 testSuite.Tests.Add(test);99 test.Name = Path.GetFileNameWithoutExtension(query);100 test.Categories.AddRange(Path.GetFileNameWithoutExtension(query).Split(new string[] { " - " }, StringSplitOptions.RemoveEmptyEntries));101102 var ctr = new EqualToXml();103 test.Constraints.Add(ctr);104 ctr.ResultSet = new ResultSetXml()105 {106 File = Path.Combine(expect.Directory, Path.GetFileNameWithoutExtension(query) + ".csv")107 };108109 var sut = new Systems.ExecutionXml();110 test.Systems.Add(sut);111 ((QueryXml)sut.Item).File = query;112 ((QueryXml)sut.Item).ConnectionString = actual.ConnectionString;113 }114 }115 return testSuite;116 }117 }118} ...

Full Screen

Full Screen

ExecutionXmlTest.cs

Source:ExecutionXmlTest.cs Github

copy

Full Screen

...33 34 //Instantiate a Test Case and specify to find the sql in the file created above35 var testCase = new ExecutionXml()36 {37 Item = new QueryXml() { File = filename }38 };3940 // A Stream is needed to read the text file from the assembly.41 string expectedContent;42 using (Stream stream = Assembly.GetExecutingAssembly()43 .GetManifestResourceStream("NBi.Testing.Unit.Xml.Resources.QueryFile.sql"))44 using (StreamReader reader = new StreamReader(stream))45 expectedContent = reader.ReadToEnd();46 47 Assert.AreEqual(expectedContent, (testCase.Item as QueryableXml).GetQuery());48 }4950 [Test]51 public void GetQuery_FilenameNotSpecified_RetrieveContentOfInlineQuery()52 {53 //Instantiate a System Under Test54 var systemUnderTest = new ExecutionXml() 55 {56 Item = new QueryXml() { InlineQuery = "SELECT * FROM Product" }57 };5859 Assert.That(((QueryXml)systemUnderTest.Item).GetQuery(), Is.EqualTo("SELECT * FROM Product"));60 Assert.That(((QueryXml)systemUnderTest.Item).InlineQuery, Is.Not.Null.And.Not.Empty.And.ContainsSubstring("SELECT"));61 Assert.That(((QueryXml)systemUnderTest.Item).File, Is.Null);62 }6364 [Test]65 public void GetQuery_FileNameSpecified_RetrieveContentOfFile()66 {67 //Create the queryfile to read68 var filename = "Select all products.sql";69 DiskOnFile.CreatePhysicalFile(filename, "NBi.Testing.Unit.Xml.Resources.SelectAllProducts.sql");7071 var systemUnderTest = new ExecutionXml()72 {73 Item = new QueryXml() { 74 File = filename, 75 Settings = new NBi.Xml.Settings.SettingsXml() { BasePath=DiskOnFile.GetDirectoryPath() }76 }77 };7879 // Check the properties of the object.80 Assert.That(((QueryXml)systemUnderTest.Item).File, Is.Not.Null.And.Not.Empty);81 Assert.That(((QueryXml)systemUnderTest.Item).InlineQuery, Is.Null);82 Assert.That(((QueryXml)systemUnderTest.Item).GetQuery(), Is.Not.Null.And.Not.Empty.And.ContainsSubstring("SELECT"));83 84 }858687 [Test]88 public void GetQuery_FilenameSpecified_RetrieveContentWithEuroSymbol()89 {90 //create a text file on disk91 var filename = DiskOnFile.CreatePhysicalFile("QueryFile€.mdx", "NBi.Testing.Unit.Xml.Resources.QueryFileEuro.mdx");9293 //Instantiate a Test Case and specify to find the sql in the file created above94 var testCase = new ExecutionXml()95 {96 Item = new QueryXml() { File = filename }97 };9899 // A Stream is needed to read the text file from the assembly.100 string expectedContent = "select [measure].[price €/Kg] on 0;";101102 Assert.AreEqual(expectedContent, ((QueryableXml)testCase.Item).GetQuery());103 }104 105 } ...

Full Screen

Full Screen

QueryXml

Using AI Code Generation

copy

Full Screen

1var queryXml = new QueryXml();2queryXml.ConnectionString = @"Data Source=.\SQL2014;Initial Catalog=AdventureWorks2014;Integrated Security=True";3queryXml.Statement = @"select * from [Person].[Person]";4var queryXml = new QueryXml();5queryXml.ConnectionString = @"Data Source=.\SQL2014;Initial Catalog=AdventureWorks2014;Integrated Security=True";6queryXml.Statement = @"select * from [Person].[Person]";7var queryXml = new QueryXml();8queryXml.ConnectionString = @"Data Source=.\SQL2014;Initial Catalog=AdventureWorks2014;Integrated Security=True";9queryXml.Statement = @"select * from [Person].[Person]";10var queryXml = new QueryXml();11queryXml.ConnectionString = @"Data Source=.\SQL2014;Initial Catalog=AdventureWorks2014;Integrated Security=True";12queryXml.Statement = @"select * from [Person].[Person]";13var queryXml = new QueryXml();14queryXml.ConnectionString = @"Data Source=.\SQL2014;Initial Catalog=AdventureWorks2014;Integrated Security=True";15queryXml.Statement = @"select * from [Person].[Person]";16var queryXml = new QueryXml();17queryXml.ConnectionString = @"Data Source=.\SQL2014;Initial Catalog=AdventureWorks2014;Integrated Security=True";18queryXml.Statement = @"select * from [Person].[Person]";19var queryXml = new QueryXml();20queryXml.ConnectionString = @"Data Source=.\SQL2014;Initial Catalog=AdventureWorks2014;Integrated Security=True";21queryXml.Statement = @"select * from [Person].[Person]";22var queryXml = new QueryXml();23queryXml.ConnectionString = @"Data Source=.\SQL2014;Initial

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run NBi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful