Base solution for your next web application

Activities of "jérôme lambert"

Hi,

I try to implement unit test to test my service. I take a look on sample boilerplate and EventCloud but I keep a problem:

AutoMapper.AutoMapperMappingException : Missing type map configuration or unsupported mapping.

Mapping types:
Categories -> CategoriesDto
B2Peer.Categories.Categories -> B2Peer.Categories.Dtos.CategoriesDto

Destination path:
List`1[0]

Source value:
[Categories_5C5B363066C7796CF519C34A20336BC3DC1E95B62494C9F2F2121E0BCC11DEF3 1]

It looks like I have a problem with Effort EF6 and AutoMapper.

All works fine on my website, I have this problem with my unit testing. I set the attribute to AutoMap my Dto

[AutoMapFrom(typeof(Categories))]
    public class CategoriesDto: EntityDto<int>

Here is my categorie service:

public GetCategoriesOutput GetCategories(GetCategoriesInput input)
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var source = _cacheManager.GetCache("CategoriesCache")
                .Get("All",
                    GetCategoriesFromDatabase) as IEnumerable<CategoriesDto>;
            //var source = _categoriesRepository.GetAll();
            stopwatch.Stop();
            Logger.Info(string.Format("GetCategories Called (Performance:{0})", stopwatch.Elapsed.ToString("g")));
            return new GetCategoriesOutput
            {
                Categories = source.Where(c=> 
                    c.CategorieSecteurId > 0 && c.CategorieNom != "" && 
                    (!input.OnlyActive || c.CategorieSignifiante == "1"))
            };
        }

        [UnitOfWork]
        private IEnumerable<CategoriesDto> GetCategoriesFromDatabase()
        {
            Logger.Info("GetCategoriesFromdatabase");
            return Mapper.Map<List<CategoriesDto>>(_categoriesRepository.GetAllList());
        }

On my test, I fake the connection like the boilerplate sample show:

//Fake DbConnection using Effort!
            LocalIocManager.IocContainer.Register(
                Component.For<DbConnection>()
                    .UsingFactoryMethod(Effort.DbConnectionFactory.CreateTransient)
                    .LifestyleSingleton()
                );

            //Seed initial data
            UsingDbContext(context => new B2PeerInitialDataBuilder().Build(context));

And my test is quite simple:

private readonly ICategoriesAppService _categorieService;


        public CategoriesRepositoryTests()
        {
            _categorieService = LocalIocManager.Resolve<ICategoriesAppService>();

        }

        [Test]
        public void GetAllCategoriesTest()
        {
            var categories = _categorieService.GetCategories(new GetCategoriesInput
            {
                OnlyActive = true
            });

            //UsingDbContext(context =>
            //{
            //    var categorie = context.Categories.FirstOrDefaultAsync();
            //    Assert.That(categorie, Is.Not.Null);

            //    Assert.That(categories.Categories.Count(), Is.GreaterThan(0)); 
            //});
        }

Did I miss something in my code ?

EDIT:

If I debug using

Mapper.GetAllTypeMaps()

It returns 0 mapping.

Maybe the error comes from abp.automapper not fired ??

Showing 1 to 1 of 1 entries