title: How to perform Moq testing for abstract class in C# for virtual methods inside it?
body: <p>I would like to perform testing for below abstract <code>Streaming</code> class which has two virtual methods that are overridden in the <code>Asset</code> class in same project. Here the <code>SerializeBinary()</code> method converts an object into binary streams and <code>DeserializeFromBinary()</code> method does the opposite of <code>SerializeBinary()</code>.</p>
  
  <p>How to write test class for comparing both using Moq?</p>
  
  <p>I go through from <a href="https://stackoverflow.com/questions/15197141/how-to-properly-test-an-abstract-class">here:</a></p>
  
  <p>This is part of my code:</p>
  
  <p><code>Streaming</code> class:</p>
  
  <pre><code>public abstract class Streaming
  {
          private static int _streamingIDExponent = 41;
          public const string MonthLookup = "ABCDEFGHIJK";
          public const string ExpiryStringFormat = "ddMMMyyyy";
          public const double DefaultTicksPerPoint = 3;
          private long _StreamingID;
          private int _minQty = DefaultMinimumQty;
  
          public virtual void SerializeBinary(BinaryStreamWriter binaryStreamWriter)
          {
                   binaryStreamWriter.Write(_StreamingID);
                   binaryStreamWriter.Write(_ex_StreamingID);
                   binaryStreamWriter.Write(_minQty);
                   binaryStreamWriter.Write(_extendedProperties.Count);
  
                   foreach (KeyValuePair&lt;StreamingPropertyName, StreamingProperty&gt; dictionaryEntry in _extendedProperties)
                   {
                       dictionaryEntry.Value.SerializeBinary(binaryStreamWriter);
                   }
  }
  
  public virtual bool DeserializeFromBinary(BinaryStreamReader binaryStreamReader, out string errorString)
  {
           errorString = string.Empty;
  
           try
           {
                 _StreamingID = binaryStreamReader.ReadInt64();
                 _exStreamingID = binaryStreamReader.ReadInt64();
                 _minQty = binaryStreamReader.ReadInt32();    
           }
           catch (Exception oEx)
           {
                 errorString = oEx.Message;
           }
  
           return string.IsNullOrEmpty(errorString);
  }
  </code></pre>
  
  <p><code>Asset</code> class:</p>
  
  <pre><code>public class Asset : Streaming
  {
      public override void SerializeBinary(BinaryStreamWriter binaryStreamWriter)
      {
          base.SerializeBinary(binaryStreamWriter);
      }
  
      public override bool DeserializeFromBinary(BinaryStreamReader binaryStreamReader, out string errorString)
      {
              if (!base.DeserializeFromBinary(binaryStreamReader, out errorString))
                     return false;
  
              try
              {
                    return true;
              }
              catch (Exception oEx)
              {
                   errorString = oEx.Message;
                   return false;
              }
       }
   }
  </code></pre>