title: How to Perform Unit testing for Serialization and Deserialization of a class in C#?
body: <p>I want to perform NUnit or MS tests on a class for serialized and deserialized behavior.</p>
  
  <p>I looked at another stackoverflow article <a href="https://stackoverflow.com/questions/236599/how-to-unit-test-if-my-object-is-really-serializable">here</a>, but I still don't understand how to do this. Please help me to understand how to perform these tests,</p>
  
  <p><strong>Below is my part of code:</strong></p>
  
  <pre><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);
          }
      }
  }
  </code></pre>