question

pianoboy11-3815 avatar image
0 Votes"
pianoboy11-3815 asked

Mocking Concrete Classes

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


dotnet-cli
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers