In my unit test I am trying to setup a method to return a List when the actual method expects the return type to me a List. However I am getting this error:
Argument 1: cannot convert from 'System.Collections.Generic.List<FSVendorRepository.AccountingManagement.Models.StatementDetail.RegionalStatementDetailItem>' to 'System.Collections.Generic.List<FSVendorRepository.AccountingManagement.Models.StatementDetail.Base.StatementDetail>'
Which tells me I cannot mock my function to return a List.
Here is the code:
Base class:
namespace FSVendorRepository.AccountingManagement.Models.StatementDetail.Base {
public abstract class StatementDetail {
//Props
}
}
Derived class:
namespace FSVendorRepository.AccountingManagement.Models.StatementDetail {
public class RegionalStatementDetailItem : Base.StatementDetail {
//Props
}
}
Interface:
namespace FSVendorRepository.AccountingManagement {
public interface IAccountingManager {
List<StatementDetail> ReturnDerivedListTest();
StatementDetail ReturnDerivedClassTest();
}
}
Unit test:
public async Task ReturnStatementDetails_UserIsMasterSubRepAndIsExporting_CorrectRegionalStatementDetailsClassReturned() {
var regionalItem = new RegionalStatementDetailItem();
var liRegionalItems = new List<RegionalStatementDetailItem>();
_iMockAccountingManager.Setup(x => x.ReturnDerivedListTest()).Returns(liRegionalItems); //compile time exception
_iMockAccountingManager.Setup(x => x.ReturnDerivedClassTest()).Returns(regionalItem); //passes
}
I'm doubly confused when i created a method which returns a single instance of the base class and substituted it with the derived class and it worked.
Why doesn't think work?