Skip to content

Commit

Permalink
Fixed an issue with the DCS Deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Ellis committed Apr 10, 2021
1 parent eec3002 commit 5c9767c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion NHTSAVehicleAPI/Schema/Model.cs
Expand Up @@ -13,7 +13,7 @@ namespace NHTSAVehicleAPI.Schema
/// Vehicle Model.
/// </summary>
[DataContract]
[DebuggerDisplay("{this.ModelNAme}")]
[DebuggerDisplay("{this.ModelName}")]
public class Model : Make
{
/// <summary>
Expand Down
10 changes: 3 additions & 7 deletions NHTSAVehicleAPI/SerializeConfig.cs
Expand Up @@ -25,15 +25,11 @@ public static T Deserialize(string fileName)
{
T type;
var serializer = new DataContractSerializer(typeof(T));
using (var stream = new MemoryStream())
using (var sr = new StreamReader(fileName))
{
using (var writer = new StreamWriter(stream))
using (var xmlr = XmlReader.Create(sr))
{
writer.Write(fileName);
writer.Flush();
stream.Position = 0;

type = (T)serializer.ReadObject(stream);
type = (T)serializer.ReadObject(xmlr);
}
}

Expand Down
23 changes: 23 additions & 0 deletions NHTSAVehicleAPITests/UnitTest1.cs
Expand Up @@ -18,6 +18,29 @@ namespace NHTSAVehicleAPITest
[TestClass]
public class UnitTest1
{
/// <summary>
/// Test deserializing a data file (using the XML Serializer) and then test
/// serializing/deserializing using the data contract serializer.
/// </summary>
[TestMethod]
[TestCategory(TestGroups.Validate)]
[TestCategory(TestGroups.Serialization)]
[DeploymentItem(@"Data/GetModelsForMake_Honda.xml", "Data")]
public void TestDataContractSerializerMethods()
{
const string RealDataFile = @"Data/GetModelsForMake_Honda.xml";

var deserializedResults = SerializeConfig<GetModelsForMake>.DeserializeUsingXmlSerializer(RealDataFile);
Assert.AreEqual(810, deserializedResults.ModelsForMake.Count);

// Reserialize the data, but to a temp file
string tempFile = System.IO.Path.GetTempFileName();
SerializeConfig<GetModelsForMake>.Serialize(tempFile, deserializedResults);

var dcsResults = SerializeConfig<GetModelsForMake>.Deserialize(tempFile);
Assert.AreEqual(810, dcsResults.ModelsForMake.Count);
}

/// <summary>
/// Test a deserialization and then serialization to be sure we create the same file that
/// the NHTSA creates.
Expand Down

0 comments on commit 5c9767c

Please sign in to comment.