Skip to content

Instantly share code, notes, and snippets.

@ahmad2x4
Created September 28, 2014 11:55
Show Gist options
  • Save ahmad2x4/ae925ff32eeec9685cf1 to your computer and use it in GitHub Desktop.
Save ahmad2x4/ae925ff32eeec9685cf1 to your computer and use it in GitHub Desktop.
blog Automapper extension
[Fact]
[UseDatabase]
public void ShouldConvertPredicates()
{
var connStr = ConfigurationManager.ConnectionStrings["SQLExpressConnection"].ConnectionString;
var myContext = new MyContext(connStr);
using (var repository = new SourceRepositorySql(myContext))
{
AddRecords(repository);
myContext.SaveChanges();
const string name = "Ahmadreza";
var query = repository.Find(s => s.FullName == name && s.NumberOfYears > 10);
var result = query.Project().To<Source>().ToList();
Assert.Equal(1, result.Count);
Assert.Equal(name, result.First().FullName);
}
}
private static void AddRecords(IRepository<Source, Destination> repository)
{
repository.Add(new Source { FullName = "Ahmadreza", NumberOfYears = 35 });
repository.Add(new Source { FullName = "Ahmadreza", NumberOfYears = 9 });
repository.Add(new Source { FullName = "Jon", NumberOfYears = 20 });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment