Skip to content

Instantly share code, notes, and snippets.

@forki
Created February 20, 2011 17:32
Show Gist options
  • Save forki/836131 to your computer and use it in GitHub Desktop.
Save forki/836131 to your computer and use it in GitHub Desktop.
Automatic AutoMapper tests
public abstract class when_mapping_to_another_type_and_back<T, S>
{
protected static T Model;
protected static T Mapped;
Because of = () => Mapped = Model.MapTo<S>().MapTo<T>();
protected static void VerifyAllProperties()
{
foreach (var property in typeof (T).GetProperties())
{
var modelProperty = property.GetValue(Model, null);
var mappedProperty = property.GetValue(Mapped, null);
modelProperty.ShouldEqual(mappedProperty);
}
}
}
public class when_mapping_AcqRequestLineViewModel_to_AcqRequestLine :
when_mapping_to_another_type_and_back<AcqRequestLineViewModel, AcqRequestLine>
{
Establish context =
() => Model =
new AcqRequestLineViewModel
{
Cost_Centre = "KST",
Cost_Unit = "KTR"
};
It should_equal_the_original_model = VerifyAllProperties;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment