title: Mocking DbEntityEntry.CurrentValues.SetValues() in EF4 CTP5 Code First
body: <p>I am trying to use the DbEntityEntry.CurrentValues.SetValues() method to facilitate updating an existing entity with values from a non-entity DTO (see: <a href="http://blogs.msdn.com/b/adonet/archive/2011/01/30/using-dbcontext-in-ef-feature-ctp5-part-5-working-with-property-values.aspx" rel="nofollow">http://blogs.msdn.com/b/adonet/archive/2011/01/30/using-dbcontext-in-ef-feature-ctp5-part-5-working-with-property-values.aspx</a>)</p>
  
  <p>I'm having trouble removing the dependency on DbEntityEntry though (for mocking, testing).  Here is an example of what I would like to do:</p>
  
  <pre><code>var entity = dbSet.Find(dto.Id);
  var entry = context.Entry(entity);
  entry.CurrentValues.SetValues(dto);
  context.SaveChanges();
  </code></pre>
  
  <p>I've also considered:</p>
  
  <pre><code>EntityType entity = new EntityType() { Id = dto.Id };
  context.Attach(entity);
  var entry = context.Entry(entity);
  entry.CurrentValues.SetValues(entity);
  context.SaveChanges();
  </code></pre>
  
  <p>From what I've been able to find both seem reasonable when working with an actual DbContext, but when I abstract the context to an IMyContext I lose the capability to get a DbEntityEntry for an entity, thus losing the SetValues option.</p>
  
  <p>Is there any way to work around this issue, or do I need to bite the bullet and manually set modified properties on the entity from the DTO (potentially a lot of boilerplate for entities with many properties)?</p>
  
  <p>(I'm fairly new to EF and this is my first StackOverflow question, so please be gentle)</p>