You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a testing scenario I run into the problem the mapper configuration cannot be reset between unit tests using the static API.
In my scenario some of the unit tests share the same mapper configuration. Both explicit and implicit mappings. See code below.
When I understand the documentation correctly, Mapper.ResetDefaultInstance should be used, to accomplice a configuration reset.
But it throws an InvalidOperationException with the message: variable 'peToPmData' of type 'AgileObjects.AgileMapper.ObjectPopulation.IObjectMappingData`2[ProductEntity,ProductModel]' referenced from scope '', but it is not defined, at the last statement of TestTwo.
Without the call to Mapper.ResetDefaultInstance there is a (understandable) a MappingConfigurationException on the explicit mapping statement in the setup .
How should I solve this? Moving the setup away to a (xunit) fixture (as the original code has) , will not solve my problem, because different tests in the same project need different fixtures, but the same mappings.
void Main()
{
TestOne();
TestTwo();
}
void SetUp()
{
Mapper.ResetDefaultInstance();
Mapper.WhenMapping.From<OtherEntity>().ToANew<OtherModel>().Ignore(d => d.Name);
}
void TestOne()
{
SetUp(); // some code requires specific mapping
var pe = new ProductEntity();
var pm = Mapper.Map(pe).ToANew<ProductModel>();
}
void TestTwo()
{
SetUp(); // some code requires specific mapping
var pe = new ProductEntity();
var pm = Mapper.Map(pe).ToANew<ProductModel>();
}
public class ProductModel
{
public long Id { get; private set; }
public string Name { get; private set; }
public ProductModel(long id, string name)
{
Id = id;
Name = name;
}
}
public class ProductEntity
{
public long Id { get; set; }
public string Name { get; set; }
}
public class OtherModel
{
public long Id { get; set; }
public IReadOnlyList<char> Name { get; set; }
}
public class OtherEntity
{
public long Id { get; set; }
public IList<char> Name { get; set; }
}
The text was updated successfully, but these errors were encountered:
In a testing scenario I run into the problem the mapper configuration cannot be reset between unit tests using the static API.
In my scenario some of the unit tests share the same mapper configuration. Both explicit and implicit mappings. See code below.
When I understand the documentation correctly, Mapper.ResetDefaultInstance should be used, to accomplice a configuration reset.
But it throws an InvalidOperationException with the message: variable 'peToPmData' of type 'AgileObjects.AgileMapper.ObjectPopulation.IObjectMappingData`2[ProductEntity,ProductModel]' referenced from scope '', but it is not defined, at the last statement of TestTwo.
Without the call to Mapper.ResetDefaultInstance there is a (understandable) a MappingConfigurationException on the explicit mapping statement in the setup .
How should I solve this? Moving the setup away to a (xunit) fixture (as the original code has) , will not solve my problem, because different tests in the same project need different fixtures, but the same mappings.
The text was updated successfully, but these errors were encountered: