4,815 questions
how to fix AutoFixture.ObjectCreationExceptionWithPath: AutoFixture was unable to create an instance from AutoMapper.IMapper
Mehran Kordavani
20
Reputation points
i have below code for xunit testing in asp .net core
using AutoFixture.Xunit2;using AutoMapper;using FluentAssertions;using Moq;using MyRBV.AppService.Cars;using MyRBV.AppService.Contract.Cars;using MyRBV.DomainService.Cruds;using MyRBV.Model.Cars;namespace AppService.Test.Cars;public class CarServiceTest{ private readonly ICarService _service; private readonly IMapper _mapper; public CarServiceTest([Frozen] Func<IMapper> mapper) { _mapper = mapper(); _service = new CarService(GetDomain(), _mapper); } //[Fact] [Theory, AutoData] public async Task Add_CheckInvalidCarName_ThrowsValidationException(Func<IMapper> mapper) { var car = new CarDto("abghjkl;jhl;kjhkl;'lkjh" + "sdfghjksdfgsfghgfdsfghdsfg" + "sdfgdsfgsfgdsfgdsfghdsfgdsfg" + "sadfgdsfgdsfgsfgdsfgdsfgdsfg" + "sdfghdfsghdsfgdsfghdfgdghdfg"); var action = new Func<Task<CarDto>>(() => _service.Add(car)); await action.Should().ThrowAsync<ArgumentOutOfRangeException>(); } private ICrudDomainService<Car> GetDomain() { var domainMock = new Mock<ICrudDomainService<Car>>(); domainMock.Setup(domain => domain.Add(It.IsAny<Car>())); return domainMock.Object; }}
when i run my text i get below error
AutoFixture.ObjectCreationExceptionWithPath: AutoFixture was unable to create an instance from AutoMapper.IMapper because it's an interface. There's n...
anyone have any idea to help me?
Developer technologies | ASP.NET | ASP.NET Core
Sign in to answer