I am trying to mock data for particular method using AutoFixture
.
_dataProvider = Substitute.For<IEstimationDataProvider>();
var rateTypes = _fixture.Build<RateType>().CreateMany(12).ToList(); ***** ERROR LINE.
_dataProvider.GetSeasonalPrices(rfg).Returns( rateTypes );
Method:
public async Task<List<RateType>> GetSeasonalPrices(string rfg)
{
var results = await _seasonalRateTypeRepository.GetByPartitionAsync(rateFactGroup);
var seasonalRate = results.First();
return new List<RateType>
{
seasonalRate.Jan,
seasonalRate.Feb,
seasonalRate.Mar,
seasonalRate.Apr,
seasonalRate.May,
seasonalRate.Jun,
seasonalRate.Jul,
seasonalRate.Aug,
seasonalRate.Sep,
seasonalRate.Oct,
seasonalRate.Nov,
seasonalRate.Dec
};
}
public enum RateType
{
OffPeakRate,
PeakRate
}
Below is the actual error:
Inner exception messages:
AutoFixture.ObjectCreationException: The decorated ISpecimenBuilder could not create a specimen based on the request: ABC.Estimation.ABC.Models.Repository.RateType. This can happen if the request represents an interface or abstract class; if this is the case, register an ISpecimenBuilder that can create specimens based on the request. If this happens in a strongly typed Build<T> expression, try supplying a factory using one of the IFactoryComposer<T> methods.
I found below solution after few try outs.
var rateTypes = _fixture.CreateMany<RateType>(12).ToList();
Not sure what exactly caused the issue though.