0

There is a unit test required for a specific function[ExecuteSelectQuery] which happens to be as such:

  internal abstract class DataRequestProcessor 
    {
    protected DataView ExecuteSelectQuery(SqlDataSource dataSource)
    {
    //do some stuff
   // need to mock this function
    }
    }
    
    internal class AccountDataRequestProcessor  : DataRequestProcessor 
    {
    
    public InfoClass GetSomeDetail(ApiRequest<object> apiRequest)
    {
    ....
    ExecuteSelectQuery(dataSource);
    .....
    }
    }

I thought of going with Interface but DataRequestProcessor simply says to change protection level. Same with if I try to inherit AccountDataRequestProcessor in test class "inconsistent accessibility base class is less accessible than derived class" . Is there a way to Mock the function[ExecuteSelectQuery] when it is called from unit test of class[GetSomeDetail] ? I am using xunit, with 4.5.2 .net framework , c# 7.3

2
  • you cannot mock a protected member. Furthermor in order to be mockable the function needs to be either abstract (implitely includes interface-methods as well) or virtual. Commented Mar 4, 2022 at 14:41
  • 1, 2 Commented Mar 4, 2022 at 19:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.