Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Automapper Dictionary Mapping Problem
using AutoMapper;
using FluentAssertions;
using System.Collections.Generic;
using Xunit;
namespace Reporter.Tests
public class TestType
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public class TestClass<T> where T : new()
public TestClass()
Mapper.Initialize(cfg => cfg.CreateMap<Dictionary<string, string>, T>());
public T GetMappedObject(string prop1, string prop2)
return Mapper.Map<T>(new Dictionary<string, string>{
{ "Prop1", prop1 },
{ "Prop2", prop2 }
public class AutomapperTests
public void TestMapping()
var mapper = new TestClass<TestType>();
var result = mapper.GetMappedObject("value1", "value2");
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Project Sdk="Microsoft.NET.Sdk">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0"/>
<PackageReference Include="xunit" Version="2.2.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0"/>
<PackageReference Include="FakeItEasy" Version="3.4.2"/>
<PackageReference Include="FluentAssertions" Version="4.19.3"/>
<PackageReference Include="AutoMapper" Version="6.1.1"/>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.