Best NBi code snippet using NBi.Core.Report.ReportingCommand
DatabaseReportingParser.cs
Source:DatabaseReportingParser.cs
...8namespace NBi.Core.Report9{10 public class DatabaseReportingParser : IReportingParser11 {12 public ReportingCommand ExtractCommand(ReportDataSetRequest request)13 {14 var otherDataSets = new List<string>();15 var query = SearchDataSet(16 request.Source17 , request.Path18 , request.ReportName19 , request.DataSetName20 , ref otherDataSets);21 if (query == null)22 {23 var reference = SearchSharedDataSet(24 request.Source25 , request.Path26 , request.ReportName27 , request.DataSetName28 , ref otherDataSets);29 if (!string.IsNullOrEmpty(reference))30 query = ReadQueryFromSharedDataSet(request.Source, request.Path, reference);31 }32 if (query != null)33 return query;34 if (otherDataSets.Count() == 0)35 throw new ArgumentException(string.Format("No report found on path '{0}' with name '{1}'", request.Path, request.ReportName));36 else if (otherDataSets.Count() == 1)37 throw new ArgumentException(string.Format("The requested dataset ('{2}') wasn't found for the report on path '{0}' with name '{1}'. The dataset for this report is {3}", request.Path, request.ReportName, request.DataSetName, otherDataSets[0]));38 else39 throw new ArgumentException(string.Format("The requested dataset ('{2}') wasn't found for the report on path '{0}' with name '{1}'. The datasets for this report are {3}", request.Path, request.ReportName, request.DataSetName, String.Join(", ", otherDataSets.ToArray())));40 }41 public ReportingCommand ExtractCommand(SharedDatasetRequest request)42 {43 var query = ReadQueryFromSharedDataSet(request.Source, request.Path, request.SharedDatasetName);44 if (query != null)45 return query;46 throw new ArgumentException(string.Format("The requested shared dataset ('{1}') wasn't found on path '{0}'.", request.Path, request.SharedDatasetName));47 }48 private ReportingCommand SearchDataSet(string source, string reportPath, string reportName, string dataSetName, ref List<string> otherDataSets)49 {50 using (var conn = new SqlConnection())51 {52 //create connection and define sql query53 conn.ConnectionString = source;54 var cmd = new SqlCommand();55 cmd.Connection = conn;56 cmd.CommandText = ReadQueryFromContent("ListDataSet");57 //create the three parameters for the sql query58 var paramReportPath = new SqlParameter("ReportPath", System.Data.SqlDbType.NVarChar, 425);59 paramReportPath.Value = reportPath;60 cmd.Parameters.Add(paramReportPath);61 var paramReportName = new SqlParameter("ReportName", System.Data.SqlDbType.NVarChar, 425);62 paramReportName.Value = reportName;63 cmd.Parameters.Add(paramReportName);64 //execute the command65 conn.Open();66 var dr = cmd.ExecuteReader();67 68 while (dr.Read())69 if (dr.GetString(2) == dataSetName)70 {71 var command = new ReportingCommand();72 command.CommandType = (CommandType)Enum.Parse(typeof(CommandType), dr.GetString(4)); //CommandType73 command.Text = dr.GetString(5); //CommandText74 return command;75 }76 else77 otherDataSets.Add(dr.GetString(2));78 }79 return null;80 }81 private string SearchSharedDataSet(string source, string reportPath, string reportName, string dataSetName, ref List<string> otherDataSets)82 {83 using (var conn = new SqlConnection())84 {85 //create connection and define sql query86 conn.ConnectionString = source;87 var cmd = new SqlCommand();88 cmd.Connection = conn;89 cmd.CommandText = ReadQueryFromContent("ListSharedDataSet");90 //create the three parameters for the sql query91 var paramReportPath = new SqlParameter("ReportPath", System.Data.SqlDbType.NVarChar, 425);92 paramReportPath.Value = reportPath;93 cmd.Parameters.Add(paramReportPath);94 var paramReportName = new SqlParameter("ReportName", System.Data.SqlDbType.NVarChar, 425);95 paramReportName.Value = reportName;96 cmd.Parameters.Add(paramReportName);97 //execute the command98 conn.Open();99 var dr = cmd.ExecuteReader();100 while (dr.Read())101 if (dr.GetString(2) == dataSetName)102 return dr.GetString(3);103 else104 otherDataSets.Add(dr.GetString(2));105 }106 return null;107 }108 private ReportingCommand ReadQueryFromSharedDataSet(string source, string path, string reference)109 {110 using (var conn = new SqlConnection())111 {112 //create connection and define sql query113 conn.ConnectionString = source;114 var cmd = new SqlCommand();115 cmd.Connection = conn;116 cmd.CommandText = ReadQueryFromContent("QueryFromSharedDataSet");117 //create the two parameters for the sql query118 var paramPath = new SqlParameter("SharedDataSetPath", System.Data.SqlDbType.NVarChar, 425);119 paramPath.Value = path;120 cmd.Parameters.Add(paramPath);121 var paramReference = new SqlParameter("SharedDataSetName", System.Data.SqlDbType.NVarChar, 425);122 paramReference.Value = reference;123 cmd.Parameters.Add(paramReference);124 //execute the command125 conn.Open();126 var dr = cmd.ExecuteReader();127 128 if (dr.Read())129 {130 var command = new ReportingCommand();131 command.CommandType = (CommandType)Enum.Parse(typeof(CommandType), dr.GetString(2)) ; //CommandType132 command.Text = dr.GetString(3); //CommandText133 return command;134 }135 }136 return null;137 }138 private string ReadQueryFromContent(string name)139 {140 var value = string.Empty;141 using (Stream stream = Assembly.GetExecutingAssembly()142 .GetManifestResourceStream("NBi.Core.Report.ReportServer" + name + ".sql"))143 using (StreamReader reader = new StreamReader(stream))144 {...
SharedDataSetQueryResolverTest.cs
Source:SharedDataSetQueryResolverTest.cs
...28 public void Execute_Args_CommandInstantiated()29 {30 var reportingParserStub = new Mock<IReportingParser>();31 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<SharedDatasetRequest>())).Returns(32 new ReportingCommand() { Text="select * from myTable;", CommandType=CommandType.Text });33 var factoryStub = new Mock<ReportingParserFactory>();34 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);35 var resolver = new SharedDataSetQueryResolver(BuildArgs(), factoryStub.Object);36 var cmd = resolver.Execute();37 Assert.That(cmd, Is.Not.Null);38 }39 [Test]40 public void Execute_Args_ConnectionStringAssigned()41 {42 var reportingParserStub = new Mock<IReportingParser>();43 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<SharedDatasetRequest>())).Returns(44 new ReportingCommand() { Text = "select * from myTable;", CommandType = CommandType.Text });45 var factoryStub = new Mock<ReportingParserFactory>();46 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);47 var resolver = new SharedDataSetQueryResolver(BuildArgs(), factoryStub.Object);48 var query = resolver.Execute();49 Assert.That(query.ConnectionString, Is.Not.Null.And.Not.Empty);50 Assert.That(query.ConnectionString, Is.EqualTo(ConnectionStringReader.GetSqlClient()));51 }52 [Test]53 public void Execute_Args_CommandTextAssigned()54 {55 var reportingParserStub = new Mock<IReportingParser>();56 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<SharedDatasetRequest>())).Returns(57 new ReportingCommand() { Text = "select * from myTable;", CommandType = CommandType.Text });58 var factoryStub = new Mock<ReportingParserFactory>();59 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);60 var resolver = new SharedDataSetQueryResolver(BuildArgs(), factoryStub.Object);61 var query = resolver.Execute();62 Assert.That(query.Statement, Is.EqualTo("select * from myTable;"));63 }64 [Test]65 public void Execute_Args_CommandTypeAssigned()66 {67 var reportingParserStub = new Mock<IReportingParser>();68 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<SharedDatasetRequest>())).Returns(69 new ReportingCommand() { Text = "myStoredProcedure", CommandType = CommandType.StoredProcedure });70 var factoryStub = new Mock<ReportingParserFactory>();71 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);72 var resolver = new SharedDataSetQueryResolver(BuildArgs(), factoryStub.Object);73 var query = resolver.Execute();74 Assert.That(query.Statement, Is.EqualTo("myStoredProcedure"));75 Assert.That(query.CommandType, Is.EqualTo(CommandType.StoredProcedure));76 }77 [Test]78 public void Execute_Args_ReportingParserCalledOnce()79 {80 var reportingParserMock = new Mock<IReportingParser>();81 reportingParserMock.Setup(x => x.ExtractCommand(It.IsAny<SharedDatasetRequest>())).Returns(82 new ReportingCommand() { Text = "myStoredProcedure", CommandType = CommandType.StoredProcedure });83 var factoryStub = new Mock<ReportingParserFactory>();84 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserMock.Object);85 var resolver = new SharedDataSetQueryResolver(BuildArgs(), factoryStub.Object);86 var cmd = resolver.Execute();87 reportingParserMock.Verify(x => x.ExtractCommand(It.IsAny<SharedDatasetRequest>()), Times.Once);88 }89 [Test]90 public void Execute_Args_ParametersAssigned()91 {92 var reportingParserStub = new Mock<IReportingParser>();93 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<SharedDatasetRequest>())).Returns(94 new ReportingCommand() { Text = "select * from myTable;", CommandType = CommandType.Text });95 var factoryStub = new Mock<ReportingParserFactory>();96 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);97 var resolver = new SharedDataSetQueryResolver(BuildArgs(), factoryStub.Object);98 var cmd = resolver.Execute();99 Assert.That(cmd.Parameters, Has.Count.EqualTo(1));100 }101 102 }103}...
ReportDataSetQueryResolverTest.cs
Source:ReportDataSetQueryResolverTest.cs
...28 public void Execute_Args_CommandInstantiated()29 {30 var reportingParserStub = new Mock<IReportingParser>();31 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<ReportDataSetRequest>())).Returns(32 new ReportingCommand() { Text = "select * from myTable;", CommandType = CommandType.Text });33 var factoryStub = new Mock<ReportingParserFactory>();34 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);35 var resolver = new ReportDataSetQueryResolver(BuildArgs(), factoryStub.Object);36 var cmd = resolver.Execute();37 Assert.That(cmd, Is.Not.Null);38 }39 [Test]40 public void Execute_Args_ConnectionStringAssigned()41 {42 var reportingParserStub = new Mock<IReportingParser>();43 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<ReportDataSetRequest>())).Returns(44 new ReportingCommand() { Text = "select * from myTable;", CommandType = CommandType.Text });45 var factoryStub = new Mock<ReportingParserFactory>();46 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);47 var resolver = new ReportDataSetQueryResolver(BuildArgs(), factoryStub.Object);48 var query = resolver.Execute();49 Assert.That(query.ConnectionString, Is.Not.Null.And.Not.Empty);50 Assert.That(query.ConnectionString, Is.EqualTo(ConnectionStringReader.GetSqlClient()));51 }52 [Test]53 public void Execute_Args_CommandTextAssigned()54 {55 var reportingParserStub = new Mock<IReportingParser>();56 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<ReportDataSetRequest>())).Returns(57 new ReportingCommand() { Text = "select * from myTable;", CommandType = CommandType.Text });58 var factoryStub = new Mock<ReportingParserFactory>();59 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);60 var resolver = new ReportDataSetQueryResolver(BuildArgs(), factoryStub.Object);61 var query = resolver.Execute();62 Assert.That(query.Statement, Is.EqualTo("select * from myTable;"));63 }64 [Test]65 public void Execute_Args_CommandTypeAssigned()66 {67 var reportingParserStub = new Mock<IReportingParser>();68 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<ReportDataSetRequest>())).Returns(69 new ReportingCommand() { Text = "myStoredProcedure", CommandType = CommandType.StoredProcedure });70 var factoryStub = new Mock<ReportingParserFactory>();71 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);72 var resolver = new ReportDataSetQueryResolver(BuildArgs(), factoryStub.Object);73 var query = resolver.Execute();74 Assert.That(query.Statement, Is.EqualTo("myStoredProcedure"));75 Assert.That(query.CommandType, Is.EqualTo(CommandType.StoredProcedure));76 }77 public void Execute_Args_ReportingParserCalledOnce()78 {79 var reportingParserMock = new Mock<IReportingParser>();80 reportingParserMock.Setup(x => x.ExtractCommand(It.IsAny<ReportDataSetRequest>())).Returns(81 new ReportingCommand() { Text = "myStoredProcedure", CommandType = CommandType.StoredProcedure });82 var factoryStub = new Mock<ReportingParserFactory>();83 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserMock.Object);84 var resolver = new ReportDataSetQueryResolver(BuildArgs(), factoryStub.Object);85 var query = resolver.Execute();86 reportingParserMock.Verify(x => x.ExtractCommand(It.IsAny<ReportDataSetRequest>()), Times.Once);87 }88 [Test]89 public void Execute_Args_ParametersAssigned()90 {91 var reportingParserStub = new Mock<IReportingParser>();92 reportingParserStub.Setup(x => x.ExtractCommand(It.IsAny<ReportDataSetRequest>())).Returns(93 new ReportingCommand() { Text = "select * from myTable;", CommandType = CommandType.Text });94 var factoryStub = new Mock<ReportingParserFactory>();95 factoryStub.Setup(x => x.Instantiate(It.IsAny<string>())).Returns(reportingParserStub.Object);96 var resolver = new ReportDataSetQueryResolver(BuildArgs(), factoryStub.Object);97 var query = resolver.Execute();98 Assert.That(query.Parameters, Has.Count.EqualTo(1));99 }100 }101}...
ReportingCommand
Using AI Code Generation
1using NBi.Core.Report;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 public void Execute()10 {11 var command = new ReportingCommand("select * from [Sheet1$]");12 var result = command.Execute("C:\\Users\\Public\\Documents\\Microsoft Reporting Services\\ReportServer\\Sample Reports\\SalesPerson.xlsx");13 }14 }15}16using NBi.Core.Report;17using System;18using System.Collections.Generic;19using System.Linq;20using System.Text;21using System.Threading.Tasks;22{23 {24 public void Execute()25 {26 var command = new ReportingCommand("select * from [Sheet1$]");27 var result = command.Execute("C:\\Users\\Public\\Documents\\Microsoft Reporting Services\\ReportServer\\Sample Reports\\SalesPerson.xlsx");28 }29 }30}31using NBi.Core.Report;32using System;33using System.Collections.Generic;34using System.Linq;35using System.Text;36using System.Threading.Tasks;37{38 {39 public void Execute()40 {41 var command = new ReportingCommand("select * from [Sheet1$]");42 var result = command.Execute("C:\\Users\\Public\\Documents\\Microsoft Reporting Services\\ReportServer\\Sample Reports\\SalesPerson.xlsx");43 }44 }45}46using NBi.Core.Report;47using System;48using System.Collections.Generic;49using System.Linq;50using System.Text;51using System.Threading.Tasks;52{53 {54 public void Execute()55 {56 var command = new ReportingCommand("select * from [Sheet1$]");57 var result = command.Execute("C:\\Users\\Public\\Documents\\Microsoft Reporting Services\\ReportServer\\Sample Reports\\SalesPerson.xlsx");58 }59 }60}
ReportingCommand
Using AI Code Generation
1ReportingCommand command = new ReportingCommand();2command.ConnectionString = "Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True";3command.CommandTimeout = 60;4command.Command = @"SELECT * FROM [Sales].[vSalesPerson]";5command.ReportPath = @"C:\Users\mike\Documents\Visual Studio 2012\Projects\NBiTest\NBiTest\Report.rdlc";6command.ReportParameters = new Dictionary<string, string>();7command.ReportParameters.Add("param1", "value1");8command.ReportParameters.Add("param2", "value2");9command.ReportParameters.Add("param3", "value3");10command.ReportParameters.Add("param4", "value4");11command.ReportParameters.Add("param5", "value5");12command.ReportParameters.Add("param6", "value6");13command.ReportParameters.Add("param7", "value7");14command.ReportParameters.Add("param8", "value8");15command.ReportParameters.Add("param9", "value9");16command.ReportParameters.Add("param10", "value10");17command.ReportParameters.Add("param11", "value11");18command.ReportParameters.Add("param12", "value12");19command.ReportParameters.Add("param13", "value13");20command.ReportParameters.Add("param14", "value14");21command.ReportParameters.Add("param15", "value15");22command.ReportParameters.Add("param16", "value16");23command.ReportParameters.Add("param17", "value17");24command.ReportParameters.Add("param18", "value18");25command.ReportParameters.Add("param19", "value19");26command.ReportParameters.Add("param20", "value20");27command.ReportParameters.Add("param21", "value21");28command.ReportParameters.Add("param22", "value22");29command.ReportParameters.Add("param23", "value23");30command.ReportParameters.Add("param24", "value24");31command.ReportParameters.Add("param25", "value25");32command.ReportParameters.Add("param26", "value26");33command.ReportParameters.Add("param27", "value27");34command.ReportParameters.Add("param28", "value28");35command.ReportParameters.Add("param29", "value29");36command.ReportParameters.Add("param30", "value30");37command.ReportParameters.Add("param31", "value31");38command.ReportParameters.Add("param32", "value32");39command.ReportParameters.Add("param
ReportingCommand
Using AI Code Generation
1using System.Collections.Generic;2using System.Linq;3using System.Text;4using System.Threading.Tasks;5using NBi.Core.Report;6using NBi.Core.Report.Delimited;7using NBi.Core.Report.Html;8using NBi.Core.Report.Excel;9using NBi.Core.Report.Ods;10{11 {12 static void Main(string[] args)13 {14 var command = new ReportingCommand();15 command.TemplatePath = "C:\\Users\\admin\\Desktop\\report.xlsx";16 command.OutputPath = "C:\\Users\\admin\\Desktop\\report_output.xlsx";17 command.ResultPath = "C:\\Users\\admin\\Desktop\\result.csv";18 command.ResultType = ResultType.Delimited;19 command.TemplateType = ReportType.Excel;20 command.OutputType = ReportType.Excel;21 command.OutputType = ReportType.Excel;22 command.Delimiter = ';';23 command.WorksheetName = "Sheet1";24 command.OutputWorksheetName = "Sheet1";25 command.ColumnNames = new List<string> { "Id", "Name", "Surname" };26 command.TemplateColumnNames = new List<string> { "Id", "Name", "Surname" };27 command.OutputColumnNames = new List<string> { "Id", "Name", "Surname" };28 command.Execute();29 Console.ReadLine();30 }31 }32}
ReportingCommand
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Report;7using NBi.Core.Report.Delimited;8using NBi.Core.Report.Html;9using NBi.Core.Report.Excel;10using NBi.Core.Report.Ods;11{12 {13 static void Main(string[] args)14 {15 var command = new ReportingCommand();16 command.TemplatePath = "C:\\Users\\admin\\Desktop\\report.xlsx";17 command.OutputPath = "C:\\Users\\admin\\Desktop\\report_output.xlsx";18 command.ResultPath = "C:\\Users\\admin\\Desktop\\result.csv";19 command.ResultType = ResultType.Delimited;
ReportingCommand
Using AI Code Generation
1Note that you can also use the command-line tool to execute your test-suite. For morp infoemation, ee the NBi documentat= R.eportType.Excel;2 command.OutputType = ReportType.Excel;3 command.OutputType = ReportType.Excel;4 command.Delimiter = ';';5 command.WorksheetName = "Sheet1";6 command.OutputWorksheetName = "Sheet1";7 command.ColumnNames = new List<string> { "Id", "Name", "Surname" };8 command.TemplateColumnNames = new List<string> { "Id", "Name", "Surname" };9 command.OutputColumnNames = new List<string> { "Id", "Name", "Surname" };10 command.Execute();11 Console.ReadLine();12 }13 }14}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!