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

Shalini Raj
  • 177
  • 2
  • 19
  • 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`. – MakePeaceGreatAgain Mar 04 '22 at 14:41
  • [1](https://stackoverflow.com/a/68959562/5045688), [2](https://stackoverflow.com/a/63503831/5045688) – Alexander Petrov Mar 04 '22 at 19:12

0 Answers0