Reputation: 79
I want to perform NUnit or MS tests on a class for serialized and deserialized behavior.
I looked at another stackoverflow article here, but I still don't understand how to do this. Please help me to understand how to perform these tests,
Below is my part of code:
namespace PMT.Service.Common.DataContract
{
public partial class MyBankInfo
{
public string MyId { get; set; }
public string MyAccountNumber { get; set; }
public string MyAccountType { get; set; }
public string MyBankName { get; set; }
public string MyBankBranchName { get; set; }
public string MyBankCity { get; set; }
public string MyBankCityPincode { get; set; }
public string MyBankIFSCCode { get; set; }
public void Serialize(BinaryStreamWriter binaryStreamWriter)
{
binaryStreamWriter.Write(MyId);
binaryStreamWriter.Write(MyAccountNumber);
binaryStreamWriter.Write(MyAccountType);
binaryStreamWriter.Write(MyBankName);
binaryStreamWriter.Write(MyBankBranchName);
binaryStreamWriter.Write(MyBankCity);
binaryStreamWriter.Write(MyBankCityPincode);
binaryStreamWriter.Write(MyBankIFSCCode);
}
public bool Deserialize(BinaryStreamReader binaryStreamReader,out string errorString)
{
errorString = string.Empty;
try
{
MyId = binaryStreamReader.ReadString();
MyAccountNumber = binaryStreamReader.ReadString();
MyAccountType = binaryStreamReader.ReadString();
MyBankName = binaryStreamReader.ReadString();
MyBankBranchName = binaryStreamReader.ReadString();
MyBankCity = binaryStreamReader.ReadString();
MyBankCityPincode = binaryStreamReader.ReadString();
MyBankIFSCCode = binaryStreamReader.ReadString();
}
catch (Exception ex)
{
errorString = ex.Message;
}
return string.IsNullOrEmpty(errorString);
}
}
}
Upvotes: 0
Views: 3484
Reputation: 13681
There are two ways to test serialization and deserialization: separately or both together.
Separate tests are best if the serialized data is created by or used by some other software that you don't have control over. In that case, exact formats have to be verified. This is also the hard way.
If your data is only serialized and deserialized by your own class, then you can test both at once:
Upvotes: 1