Exemplo n.º 1
0
        public void ExtractQuery_NonExistingReport_CorrectExceptionReturned()
        {
            var request = new NBi.Core.Report.ReportDataSetRequest(
                string.Empty
                , ReportFileDirectory
                , "Not Existing"
                , "DataSet1"
                );

            var parser = new FileReportingParser();
            var ex     = Assert.Throws <ArgumentException>(() => parser.ExtractCommand(request));

            Assert.That(ex.Message, Does.Contain("No report found"));
        }
Exemplo n.º 2
0
        public void ExtractQuery_NonExistingDataSetMoreThanOneExisting_CorrectExceptionReturned()
        {
            var request = new NBi.Core.Report.ReportDataSetRequest(
                string.Empty
                , ReportFileDirectory
                , "Currency_Rates"
                , "Non Existing"
                );

            var parser = new FileReportingParser();
            var ex     = Assert.Throws <ArgumentException>(() => parser.ExtractCommand(request));

            Assert.That(ex.Message, Does.Contain("DataSet1").And.Contain("DataSet2"));
        }
Exemplo n.º 3
0
        public void ExtractSProc_ExistingReport_CorrectSProcReturned()
        {
            var request = new NBi.Core.Report.ReportDataSetRequest(
                string.Empty
                , ReportFileDirectory
                , "Currency_List - SProc"
                , "Currency"
                );

            var parser = new FileReportingParser();
            var query  = parser.ExtractCommand(request);

            Assert.That(query.Text,
                        Is.EqualTo("usp_CurrencyGetAll"));
            Assert.That(query.CommandType, Is.EqualTo(CommandType.StoredProcedure));
        }
Exemplo n.º 4
0
        public void ExtractQuery_ExistingReportAndSharedDataSet_CorrectQueryReturned()
        {
            var request = new NBi.Core.Report.ReportDataSetRequest(
                string.Empty
                , ReportFileDirectory
                , "Employee_Sales_Summary"
                , "SalesEmployees2008R2"
                );

            var parser = new FileReportingParser();
            var query  = parser.ExtractCommand(request);

            Assert.That(query.Text,
                        Does.Contain("SELECT").And
                        .Contain("[Sales].[SalesPerson]").And
                        .Contain("[HumanResources].[Employee]"));
            Assert.That(query.CommandType, Is.EqualTo(CommandType.Text));
        }
Exemplo n.º 5
0
        private Exception BuildDataSetNotFoundException(ReportDataSetRequest request, XmlDocument docXml, string xpath, XmlNamespaceManager nsmgr)
        {
            var nodes        = docXml.SelectNodes(xpath, nsmgr);
            var dataSetFound = new List <String>();

            foreach (XmlNode node in nodes)
            {
                dataSetFound.Add(node.Attributes["Name"].Value);
            }

            if (dataSetFound.Count() > 1)
            {
                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(", ", dataSetFound.ToArray())));
            }
            else
            {
                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 named '{3}'", request.Path, request.ReportName, request.DataSetName, dataSetFound[0]));
            }
        }
Exemplo n.º 6
0
        public ReportingCommand ExtractCommand(ReportDataSetRequest request)
        {
            var otherDataSets = new List <string>();
            var query         = SearchDataSet(
                request.Source
                , request.Path
                , request.ReportName
                , request.DataSetName
                , ref otherDataSets);

            if (query == null)
            {
                var reference = SearchSharedDataSet(
                    request.Source
                    , request.Path
                    , request.ReportName
                    , request.DataSetName
                    , ref otherDataSets);
                if (!string.IsNullOrEmpty(reference))
                {
                    query = ReadQueryFromSharedDataSet(request.Source, request.Path, reference);
                }
            }

            if (query != null)
            {
                return(query);
            }

            if (otherDataSets.Count() == 0)
            {
                throw new ArgumentException(string.Format("No report found on path '{0}' with name '{1}'", request.Path, request.ReportName));
            }
            else if (otherDataSets.Count() == 1)
            {
                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]));
            }
            else
            {
                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())));
            }
        }
Exemplo n.º 7
0
        public ReportingCommand ExtractCommand(ReportDataSetRequest request)
        {
            var reportName = request.ReportName.EndsWith(".rdl") ? request.ReportName : request.ReportName + ".rdl";

            var fullPath = string.Format("{0}{1}{2}", request.Source, request.Path, reportName);

            if (!File.Exists(fullPath))
            {
                throw new ArgumentException(string.Format("No report found on path '{0}{1}' with name '{2}'", request.Source, request.Path, request.ReportName));
            }

            //Load the xml
            var docXml = new XmlDocument();

            docXml.Load(fullPath);
            var root = docXml.FirstChild;

            if (root.NodeType == XmlNodeType.XmlDeclaration)
            {
                root = root.NextSibling;
            }

            //Check that the data set exist
            var xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]", request.DataSetName);
            //var xpath = "//Report";

            var nsmgr = new XmlNamespaceManager(docXml.NameTable);

            nsmgr.AddNamespace("rd", root.GetNamespaceOfPrefix(string.Empty));

            var node = docXml.SelectSingleNode(xpath, nsmgr);

            if (node == null)
            {
                throw BuildDataSetNotFoundException(request, docXml, "//rd:Report/rd:DataSets/rd:DataSet", nsmgr);
            }

            //Search in the xml the DataSet and especially the CommandText within this dataset
            xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:Query/rd:CommandText", request.DataSetName);

            node = docXml.SelectSingleNode(xpath, nsmgr);
            if (node != null)
            {
                var text          = node.InnerText; // Weve fond the query
                var reportCommand = new ReportingCommand()
                {
                    Text = text
                };

                xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:Query/rd:CommandType", request.DataSetName);
                node  = docXml.SelectSingleNode(xpath, nsmgr);
                if (node == null)
                {
                    reportCommand.CommandType = CommandType.Text;
                }
                else
                {
                    reportCommand.CommandType = (CommandType)Enum.Parse(typeof(CommandType), node.InnerText);
                }
                return(reportCommand);
            }

            //If not found then we'll check if it's not a shared dataset
            xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:SharedDataSet/rd:SharedDataSetReference", request.DataSetName);
            node  = docXml.SelectSingleNode(xpath, nsmgr);
            if (node == null)
            {
                throw new ArgumentException(string.Format("The data set named '{0}' has been found but no command text or shared dataset reference has been found", request.DataSetName));
            }

            var sharedDataSetName = node.InnerText + ".rsd";
            var subRequest        = new SharedDatasetRequest
                                    (
                request.Source,
                request.Path,
                sharedDataSetName
                                    );

            return(ExtractCommand(subRequest));
        }