public void EditingConcurrent() { var entityA = GetItemUpdated(2, "A"); var entityB = GetItemUpdated(2, "B"); using (var db = new WisperoDbContext()) { var dataService = new KnowledgeBaseData(db); Assert.IsTrue(entityA.RowVersion.SequenceEqual(entityB.RowVersion)); //Updating EntityA. dataService.Edit(entityA); dataService.CommitChanges(); var recentlyUpdated = dataService.Get(2); Assert.IsNotNull(recentlyUpdated.Query); Assert.IsTrue(recentlyUpdated.Query == entityA.Query); //Sleep to simulate a delay between updates. System.Threading.Thread.Sleep(10); //Updating EntityB. //It should failed because the version kept memory has changes on the source because of EntityA. try { dataService.Edit(entityB); dataService.CommitChanges(); Assert.Fail(); } catch (DbUpdateConcurrencyException) { } } }
public void Editing() { using (var db = new WisperoDbContext()) { var dataService = new KnowledgeBaseData(db); var currentEntity = dataService.Get(2); //Making updates currentEntity.Answer = "NewAnswer2"; currentEntity.Query = "NewQuery2"; currentEntity.LastUpdateOn = DateTime.Now; currentEntity.Tags = "NewTags"; dataService.Edit(currentEntity); dataService.CommitChanges(); var recentlyUpdated = dataService.Get(2); Assert.IsNotNull(recentlyUpdated); Assert.IsTrue(recentlyUpdated.Query == "NewQuery2"); } }