Example #1
0
        /// <summary>
        /// Maps the database outputs.
        /// </summary>
        /// <param name="outputDescription">The output description.</param>
        /// <param name="theService">The service.</param>
        /// <param name="addFields">if set to <c>true</c> [add fields].</param>
        public void MapDbOutputs(IOutputDescription outputDescription, ref DbService theService, bool addFields)
        {

            // only fetch paths with valid data to map ;)
            var outputsToMap = outputDescription.DataSourceShapes[0].Paths.Where(p => !string.IsNullOrEmpty(p.DisplayPath) && p.DisplayPath != "DocumentElement");
            
            var rsFields = new List<RecordsetField>(theService.Recordset.Fields);
            #pragma warning disable 219
            int recordsetIndex = 0;
            #pragma warning restore 219

            foreach(var path in outputsToMap)
            {
                // Remove bogus names and dots
                var name = path.DisplayPath.Replace("NewDataSet", "").Replace(".Table.", "").Replace("DocumentElement","");
                var alias = path.DisplayPath.Replace("NewDataSet", "").Replace(".Table.", "").Replace(".","").Replace("DocumentElement", "");

                var idx = name.IndexOf("()", StringComparison.InvariantCultureIgnoreCase);
                if(idx >= 0)
                {
                    name = name.Remove(0, idx + 2);
                    if (name.StartsWith("."))
                        name = name.Substring(1);
                }

                var field = new RecordsetField { Name = name, Alias = string.IsNullOrEmpty(path.OutputExpression) ? alias : path.OutputExpression, Path = path };

                RecordsetField rsField;
                if(!addFields && (rsField = rsFields.FirstOrDefault(f => f.Path != null ? f.Path.ActualPath == path.ActualPath : f.Name == field.Name)) != null)
                {
                    field.Alias = rsField.Alias;
                }
           
                theService.Recordset.Fields.Add(field);

                // 2013.12.11 - COMMUNITY BUG - 341463 - data with empty cells displays incorrectly
                var data = path.SampleData.Split(new[] { GlobalConstants.AnytingToXmlCommaToken }, StringSplitOptions.None);
                var recordIndex = 0;

                foreach (var item in data)
                {
                    theService.Recordset.SetValue(recordIndex, recordsetIndex, item);
                    recordIndex++;
                }

                recordsetIndex++;
            }

        }
        // ReSharper disable InconsistentNaming
        public void DbService_ToXml_WhenRecordSetHasBlankFields_ExpectNotPartOfOutputDescription()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var dbService = new DbService();
            var dbSource = new DbSource { ResourceName = "Source" };
            var resourceId = Guid.NewGuid();
            dbSource.ResourceID = resourceId;
            dbService.Source = dbSource;
            var serviceMethod = new ServiceMethod { Name = "Method" };
            dbService.Method = serviceMethod;
            var recordset = new Recordset { Name = "SomeRecSet" };
            var recordsetField = new RecordsetField { Alias = "SomeAlias", Name = "" };
            recordset.Fields.Add(recordsetField);
            dbService.Recordset = recordset;

            // ReSharper disable InconsistentNaming
            const string expected = @"<Service ID=""00000000-0000-0000-0000-000000000000"" Name="""" ResourceType=""DbService"" IsValid=""false"">
  <Actions>
    <Action Name=""SomeRecSet"" Type=""InvokeStoredProc"" SourceID=""{0}"" SourceName=""Source"" ExecuteAction="""" SourceMethod=""Method"">
      <Inputs />
      <Outputs />
      <OutputDescription><![CDATA[<z:anyType xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:d1p1=""http://schemas.datacontract.org/2004/07/Unlimited.Framework.Converters.Graph.Ouput"" i:type=""d1p1:OutputDescription"" xmlns:z=""http://schemas.microsoft.com/2003/10/Serialization/""><d1p1:DataSourceShapes xmlns:d2p1=""http://schemas.microsoft.com/2003/10/Serialization/Arrays""><d2p1:anyType i:type=""d1p1:DataSourceShape""><d1p1:_x003C_Paths_x003E_k__BackingField /></d2p1:anyType></d1p1:DataSourceShapes><d1p1:Format>ShapedXML</d1p1:Format></z:anyType>]]></OutputDescription>
    </Action>
  </Actions>
  <AuthorRoles />
  <Comment />
  <Tags />
  <HelpLink />
  <UnitTestTargetWorkflowService />
  <BizRule />
  <WorkflowActivityDef />
  <XamlDefinition />
  <DataList />
  <TypeOf>InvokeStoredProc</TypeOf>
  <DisplayName></DisplayName>
  <Category></Category>
  <AuthorRoles></AuthorRoles>
  <ErrorMessages />
</Service>";
            // ReSharper restore InconsistentNaming

            //------------Execute Test---------------------------
            var xElement = dbService.ToXml();
            //------------Assert Results-------------------------
            Assert.AreEqual(string.Format(expected, resourceId), xElement.ToString());
        }