Skip to content

Commit

Permalink
3. Data Streams : Serialization #117
Browse files Browse the repository at this point in the history
- Finished working on.
- UT 👍
  • Loading branch information
mpostol committed Aug 7, 2018
1 parent ff6eb48 commit 68ba187
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Instrumentation\Catalog.xslt" />
<None Include="Instrumentation\Catalog.xslt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


using System.Diagnostics;
using System.Xml.Serialization;
using TP.DataStreams.Serialization;

namespace TP.DataStreams.Instrumentation
Expand All @@ -16,15 +17,15 @@ namespace TP.DataStreams.Instrumentation
/// </summary>
public partial class Catalog : IStylesheetNameProvider
{

#region IStylesheetNameProvider Members
/// <summary>
/// The stylesheet name
/// </summary>
public string StylesheetName
{
get { return "catalog.xslt"; }
}
[XmlIgnore]
public string StylesheetName { get; set; } = "catalog.xslt";
#endregion

[Conditional("DEBUG")]
internal void AddTestingData()
{
Expand All @@ -49,4 +50,24 @@ internal void AddTestingData()
CD = new CatalogCD[] { _cd1, _cd2 };
}
}

partial class CatalogCD
{
public static bool operator ==(CatalogCD left, CatalogCD right)
{
return left.Equals(right);
}
public static bool operator !=(CatalogCD left, CatalogCD right)
{
return !left.Equals(right);
}
public override bool Equals(object obj)
{
CatalogCD _catalogCD = obj as CatalogCD;
if (object.ReferenceEquals(_catalogCD, null))
throw new System.ArgumentException(nameof(obj), "wrong parameter type");
return $"{Artist}, {Company}, {Country}, {Price}, {Title}" == $"{_catalogCD.Artist}, {_catalogCD.Company}, {_catalogCD.Country}, {_catalogCD.Price}, {_catalogCD.Title}";
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exml="http://tempuri.org/CreateXMLFile.xsd">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exml="http://Viculu34.org/Catalog.xsd">
<xsl:template match="/">
<html>
<body>
Expand All @@ -10,16 +10,16 @@
<th>Artist</th>
<th>Price</th>
</tr>
<xsl:for-each select="exml:Catalog/exml:cd">
<xsl:for-each select="exml:Catalog/exml:CD">
<tr>
<td>
<xsl:value-of select="exml:title"/>
<xsl:value-of select="exml:Title"/>
</td>
<td>
<xsl:value-of select="exml:artist"/>
<xsl:value-of select="exml:Artist"/>
</td>
<td>
<xsl:value-of select="exml:price"/>
<xsl:value-of select="exml:Price"/>
</td>
</tr>
</xsl:for-each>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void ReadWRiteTest()
string _fileName = @"Instrumentation\catalog.xml";
XmlFile.WriteXmlFile<Catalog>(_catalog2Write, _fileName, FileMode.Create);
Catalog _recoveredCatalog = XmlFile.ReadXmlFile<Catalog>(_fileName);
Assert.IsTrue(_catalog2Write.CD[0].Equals(_recoveredCatalog.CD[0]));
Assert.IsTrue(_catalog2Write.CD[1].Equals(_recoveredCatalog.CD[1]));
Assert.IsTrue(_catalog2Write.CD[0] == _recoveredCatalog.CD[0]);
Assert.IsTrue(_catalog2Write.CD[1] == _recoveredCatalog.CD[1]);

}

Expand Down

0 comments on commit 68ba187

Please sign in to comment.