David Smith

David Smith

  • NA
  • 2k
  • 0

Mocking Concrete Classes

Oct 29 2021 12:01 AM

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 ;
    }
}

 


Answers (3)