From 68ba18797af9dc15517ee6905535b1af33731416 Mon Sep 17 00:00:00 2001 From: MPostol Date: Tue, 7 Aug 2018 21:48:00 +0200 Subject: [PATCH] 3. Data Streams : Serialization #117 - Finished working on. - UT :+1: --- .../DataStreams.UnitTest.csproj | 4 ++- .../Instrumentation/Catalog.xsd.cs | 29 ++++++++++++++++--- .../Instrumentation/Catalog.xslt | 10 +++---- .../SerializationUnitTest.cs | 4 +-- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Lecture/P03.DataStreams/DataStreams.UnitTest/DataStreams.UnitTest.csproj b/Lecture/P03.DataStreams/DataStreams.UnitTest/DataStreams.UnitTest.csproj index c73b7c44..cfe3117f 100644 --- a/Lecture/P03.DataStreams/DataStreams.UnitTest/DataStreams.UnitTest.csproj +++ b/Lecture/P03.DataStreams/DataStreams.UnitTest/DataStreams.UnitTest.csproj @@ -79,7 +79,9 @@ - + + Always + diff --git a/Lecture/P03.DataStreams/DataStreams.UnitTest/Instrumentation/Catalog.xsd.cs b/Lecture/P03.DataStreams/DataStreams.UnitTest/Instrumentation/Catalog.xsd.cs index f1200d86..fa3c2fb4 100644 --- a/Lecture/P03.DataStreams/DataStreams.UnitTest/Instrumentation/Catalog.xsd.cs +++ b/Lecture/P03.DataStreams/DataStreams.UnitTest/Instrumentation/Catalog.xsd.cs @@ -7,6 +7,7 @@ using System.Diagnostics; +using System.Xml.Serialization; using TP.DataStreams.Serialization; namespace TP.DataStreams.Instrumentation @@ -16,15 +17,15 @@ namespace TP.DataStreams.Instrumentation /// public partial class Catalog : IStylesheetNameProvider { + #region IStylesheetNameProvider Members /// /// The stylesheet name /// - public string StylesheetName - { - get { return "catalog.xslt"; } - } + [XmlIgnore] + public string StylesheetName { get; set; } = "catalog.xslt"; #endregion + [Conditional("DEBUG")] internal void AddTestingData() { @@ -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}"; + } + } + } diff --git a/Lecture/P03.DataStreams/DataStreams.UnitTest/Instrumentation/Catalog.xslt b/Lecture/P03.DataStreams/DataStreams.UnitTest/Instrumentation/Catalog.xslt index 3fc1bf59..1f2abb64 100644 --- a/Lecture/P03.DataStreams/DataStreams.UnitTest/Instrumentation/Catalog.xslt +++ b/Lecture/P03.DataStreams/DataStreams.UnitTest/Instrumentation/Catalog.xslt @@ -1,5 +1,5 @@  - + @@ -10,16 +10,16 @@ Artist Price - + - + - + - + diff --git a/Lecture/P03.DataStreams/DataStreams.UnitTest/SerializationUnitTest.cs b/Lecture/P03.DataStreams/DataStreams.UnitTest/SerializationUnitTest.cs index 9c8eb052..dc0a0737 100644 --- a/Lecture/P03.DataStreams/DataStreams.UnitTest/SerializationUnitTest.cs +++ b/Lecture/P03.DataStreams/DataStreams.UnitTest/SerializationUnitTest.cs @@ -47,8 +47,8 @@ public void ReadWRiteTest() string _fileName = @"Instrumentation\catalog.xml"; XmlFile.WriteXmlFile(_catalog2Write, _fileName, FileMode.Create); Catalog _recoveredCatalog = XmlFile.ReadXmlFile(_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]); }