Mocking Concrete Classes

pianoboy11 1 Reputation point
2021-10-28T23:59:06.157+00:00

I have old legacy code, that I am no longer allowed to change at this moment in time but we have to write test using mock. The software code is using all concrete classes. What is next best form of practice to use for mocking concrete classes? Do we use moq? if so, can you provide good examples of best practices?

For example:

How would i mock and test this concrete class below?

public class ColorConcreteClass
{
   public  byte[] colorPayload {get; set;}

    public ColorConcreteClass()
   {
        colorPayload = new byte[0];
   }

      public ColorConcreteClass Clone()
    {
            ColorConcreteClass colorConcreateClass = new ColorConcreteClass();

          if(colorPayload  != null)
          {
                colorConcreateClass.colorPayload   = ToArray();
          }

         return colorConcreateClass ;

   }

}
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
0 comments No comments
{count} votes