Skip to content

Commit

Permalink
Merge 27c5e0a into 87a4948
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo authored Sep 10, 2020
2 parents 87a4948 + 27c5e0a commit 9d424d5
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ExtendedXmlSerializer/ExtensionModel/Xml/XmlReader.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;
using System.Xml;
using ExtendedXmlSerializer.ContentModel.Content;
using ExtendedXmlSerializer.ContentModel.Format;
using ExtendedXmlSerializer.ContentModel.Identification;
using System.Reflection;
using System.Xml;

namespace ExtendedXmlSerializer.ExtensionModel.Xml
{
Expand Down Expand Up @@ -43,6 +43,7 @@ public string Content()
{
switch (_reader.NodeType)
{

case XmlNodeType.Attribute:
return _reader.Value;
default:
Expand All @@ -61,7 +62,7 @@ public string Content()

var result = isNull ? null : _reader.Value;

if (!string.IsNullOrEmpty(result))
if (!string.IsNullOrEmpty(result) || _reader.NodeType == XmlNodeType.CDATA)
{
_reader.Read();
Set();
Expand Down
74 changes: 74 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue442Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.Tests.ReportedIssues.Shared.Issue442;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue442Tests
{
[Fact]
public void Verify()
{
const string content = @"<Device fb=""FB_Pneumatic2Pos"" commandStruct=""E_Pneumatic_Cmd"">
<Definition><![CDATA[ ""#InstanceName#""(PlcCycleTime := ""DB_Time"".PlcCycleTime,
OpMode := ""DB_#Station#_Station"".OpMode,
Inactive := FALSE,
I_SensorA := #I_SensorA#,
I_SensorB := #I_SensorB#,
C_TwoCoils := #C_TwoCoils#,
C_ForceVentilate := #C_ForceVentilate#,
C_Clamping := #C_Clamping#,
C_PL := ""E_PL"".#C_PL#,
C_TimeVentilate := T#200ms,
C_TimeoutDuration := T#3s,
C_WaitTimePosA := T#0ms,
C_WaitTimePosB := T#0ms,
Q_ValveA => #Q_ValveA#,
Q_ValveB => #Q_ValveB#,
Q_ValveOpenClamping => #Q_ValveOpenClamping#);]]></Definition>
<DeviceDataDb><![CDATA[]]></DeviceDataDb>
<ServiceHandler><![CDATA[ ""FC_Pneumatic2Pos_Service_3Rows""(DeviceNo := #DeviceNo#,
Row := #Row#,
RowVisible := TRUE,
DeviceName_Textlist := ""E_Service3Row_DeviceNames"".""#DeviceName#"",
ButtonTextPosA_Textlist := ""E_Service_ButtonText"".""#ActionA#"",
ButtonTextPosB_Textlist := ""E_Service_ButtonText"".""#ActionB#"",
I_PosA_2 := #I_SensorA2#,
I_PosB_2 := #I_SensorB2#,
IDB := #InstanceName#,
Btn_DeActivateService := ""DB_#Station#_Station"".Buttons.Service);]]></ServiceHandler>
<ParameterDb><![CDATA[]]></ParameterDb>
<Releases><![CDATA[ ""#InstanceName#"".ReleasePosA := FALSE;
""#InstanceName#"".ReleasePosB := FALSE;]]></Releases>
<CommandStart><![CDATA[]]></CommandStart>
<WatchAndForceTable>
<Capacity>16</Capacity>
<WatchAndForceTableEntry name=""Cmd"" />
<WatchAndForceTableEntry name=""Execute"" />
<WatchAndForceTableEntry name=""ExecState"" />
<WatchAndForceTableEntry name=""ErrorCode"" />
<WatchAndForceTableEntry name=""_State[1]"" />
<WatchAndForceTableEntry name=""_StateName"" />
<WatchAndForceTableEntry name=""I_SensorA"" />
<WatchAndForceTableEntry name=""I_SensorB"" />
<WatchAndForceTableEntry name=""_ValveA"" />
<WatchAndForceTableEntry name=""_ValveB"" />
<WatchAndForceTableEntry name=""_ValveOpenClamping"" />
</WatchAndForceTable>
</Device>";

var serializer = new ConfigurationContainer().InspectingType<SiemensDeviceTemplate>()
.EnableImplicitTyping(typeof(SiemensDeviceTemplate))
.Create()
.ForTesting();

serializer.Deserialize<SiemensDeviceTemplate>(content)
.WatchAndForceTableEntires.Should()
.NotBeNull()
.And.Subject.Should()
.NotBeEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace ExtendedXmlSerializer.Tests.ReportedIssues.Shared.Issue442
{
public interface IDeviceTemplate {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using ExtendedXmlSerializer.ContentModel.Content;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace ExtendedXmlSerializer.Tests.ReportedIssues.Shared.Issue442
{
[XmlRoot("Device", Namespace = "")]
public class SiemensDeviceTemplate : IDeviceTemplate
{
[XmlAttribute("fb")]
public string FB { get; set; }

[Verbatim]
[XmlElement("Definition")]
public string Definition { get; set; }

[Verbatim]
[XmlElement("DeviceDataDb")]
public string DeviceDataDb { get; set; }

[Verbatim]
[XmlElement("ServiceHandler")]
public string ServiceHandler { get; set; }

[Verbatim]
[XmlElement("ParameterDb")]
public string ParameterDb { get; set; }

[Verbatim]
[XmlElement(ElementName = "Releases")]
public string Releases { get; set; }

[XmlAttribute("commandStruct")]
public string CommandStruct { get; set; }

[Verbatim]
[XmlElement("CommandStart")]
public string CommandStart { get; set; }

[XmlElement("WatchAndForceTable")]
public List<WatchAndForceTableTemplate> WatchAndForceTableEntires { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Xml.Serialization;

namespace ExtendedXmlSerializer.Tests.ReportedIssues.Shared.Issue442
{
[XmlRoot("WatchAndForceTableEntry")]
public class WatchAndForceTableTemplate
{
[XmlAttribute("name")]
public string Name { get; set; }
}
}

0 comments on commit 9d424d5

Please sign in to comment.