我想激发DbUpdateConcurrencyException以对其进行负面单元测试。
最简单的方法是什么?
我试过这样,但它没有错误地通过:
ClientRepository clientRepo = new ClientRepository(this._context, MockingHelper.GetIDataAccessLayerInformation());
try
{
var client = clientRepo.DBSet.Single(x => x.ClientCode == 1);
var clientSecondTime = clientRepo.DBSet.Single(x => x.ClientCode == 1);
client.ClientDisplayName = "NewName";
this._context.SaveChanges();
clientSecondTime.ClientDisplayName = "NewNameForException";
this._context.SaveChanges();
}
catch (DbUpdateConcurrencyException cex)
{
Assert.Pass();
}
Assert.Fail();