AutoFixture.ObjectCreationException при создании списка - PullRequest
0 голосов
/ 06 марта 2019

Я пытаюсь смоделировать данные для конкретного метода, используя 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.

1 Ответ

1 голос
/ 07 марта 2019

Я нашел решение ниже после нескольких попыток.

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

Не уверен, что именно вызвало проблему.

...