Created
January 31, 2012 09:02
-
-
Save alexbeletsky/1709552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IMapper<TInput, TOutput> | |
{ | |
TOutput Map(TInput input); | |
} | |
public interface ICompositeMapper<TInput, TOutput> | |
{ | |
TOutput[] Map(TInput input); | |
} | |
// Implementation | |
public class Mapper : IMapper<XModel, Model> | |
{ | |
public Model Map(XModel) | |
{ | |
} | |
} | |
public class CompositeMapper : ICompositeMapper<XModel, Model> | |
{ | |
public Model[] Map(XModel) | |
{ | |
} | |
} | |
// Tests | |
public class MapperTests | |
{ | |
[Test] | |
public void should_map() | |
{ | |
var mapper = new Mapper(); | |
var result = mapper.Map(input); | |
// assert result | |
} | |
} | |
public class CompositeMapperTests | |
{ | |
[Test] | |
public void should_map() | |
{ | |
var mapper = new CompositeMapper(); | |
var result = mapper.Map(input); | |
// assert result | |
} | |
} | |
// Use case | |
public class SomeRepository : IRepository | |
{ | |
public Model GetById (int id) | |
{ | |
var xModel = // ask NHibernate for it.. | |
return new Mapper().Map(xModel); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment