AutoFixture.ObjectCreationException 创建列表时

AutoFixture.ObjectCreationException when create a list

我正在尝试使用 AutoFixture.

模拟特定方法的数据
 _dataProvider = Substitute.For<IEstimationDataProvider>();

var rateTypes = _fixture.Build<RateType>().CreateMany(12).ToList();  ***** ERROR LINE.

_dataProvider.GetSeasonalPrices(rfg).Returns( rateTypes );

方法:

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
}

下面是实际错误:

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.

经过几次尝试,我找到了以下解决方案。

var rateTypes = _fixture.CreateMany<RateType>(12).ToList();

虽然不确定到底是什么导致了这个问题。