0
我想对序列化和反序列化行为的类执行NUnit或MS测试。如何执行单元测试序列化和C#中的类的反序列化?
我看着另一个stackoverflow文章here,但我仍然不明白如何做到这一点。请帮助我了解如何执行这些测试,
下面是我的部分代码:
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);
}
}
}
你可以分享到目前为止你写的单元测试代码吗? –
@ChetanRanpariya我是新的测试,我没有写这个测试用例。 –
我无法帮助您为此做好现成的解决方案。您可以访问https://www.infragistics.com/community/blogs/dhananjay_kumar/archive/2015/07/27/getting-started-with-net-unit-testing-using-nunit.aspx和https:// www .nunit.org/index.php?p = quickStart&r = 2.2来了解如何使用NUnit编写单元测试。 –