title: Test .NET6 minimal API with AutoMapper
body: <p>I have a .NET6 project with minimal APIs. This is the code</p>
  <pre><code>var builder = WebApplication.CreateBuilder(args);
  
  builder.Services.AddDbContext&lt;ClientContext&gt;(opt =&gt; 
    opt.UseInMemoryDatabase(&quot;Clients&quot;));
  builder.Services
    .AddTransient&lt;IClientRepository,
                  ClientRepository&gt;();
  builder.Services
    .AddAutoMapper(Assembly.GetEntryAssembly());
  
  var app = builder.Build();
  
  // Get the Automapper, we can share this too
  var mapper = app.Services.GetService&lt;IMapper&gt;();
  if (mapper == null)
  {
      throw new InvalidOperationException(
        &quot;Mapper not found&quot;);
  }
  
  app.MapPost(&quot;/clients&quot;,
    async (ClientModel model,
           IClientRepository repo) =&gt;
    {
        try
        {
            var newClient = mapper.Map&lt;Client&gt;(model);
            repo.Add(newClient);
            if (await repo.SaveAll())
            {
                return Results.Created(
                  $&quot;/clients/{newClient.Id}&quot;,
                  mapper.Map&lt;ClientModel&gt;(newClient));
            }
        }
        catch (Exception ex)
        {
            logger.LogError(
              &quot;Failed while creating client: {ex}&quot;,
              ex);
        }
        return Results.BadRequest(
          &quot;Failed to create client&quot;);
    });
  </code></pre>
  <p>This code is working. I have a simple <code>Profile</code> for <code>AutoMapper</code></p>
  <pre><code>public class ClientMappingProfile : Profile
  {
      public ClientMappingProfile()
      {
          CreateMap&lt;Client, ClientModel&gt;()
            .ForMember(c =&gt; c.Address1, o =&gt; o.MapFrom(m =&gt; m.Address.Address1))
            .ForMember(c =&gt; c.Address2, o =&gt; o.MapFrom(m =&gt; m.Address.Address2))
            .ForMember(c =&gt; c.Address3, o =&gt; o.MapFrom(m =&gt; m.Address.Address3))
            .ForMember(c =&gt; c.CityTown, o =&gt; o.MapFrom(m =&gt; m.Address.CityTown))
            .ForMember(c =&gt; c.PostalCode, o =&gt; o.MapFrom(m =&gt; m.Address.PostalCode))
            .ForMember(c =&gt; c.Country, o =&gt; o.MapFrom(m =&gt; m.Address.Country))
            .ReverseMap();
      }
  }
  </code></pre>
  <p>I wrote a <code>NUnit</code> test and a <code>xUnit</code> test. In both cases, when I call the API I receive the error</p>
  <blockquote>
  <p>Program: Error: Failed while creating client: AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.</p>
  <p>Mapping types:
  ClientModel -&gt; Client
  MinimalApis.Models.ClientModel -&gt; MinimalApis.Data.Entities.Client
  at lambda_method92(Closure , Object , Client , ResolutionContext )</p>
  </blockquote>
  <p>How can I use the Profile in the main project? The full source code is on <a href="https://github.com/erossini/Net6MinimalAPIs" rel="nofollow noreferrer">GitHub</a>.</p>