public void GetModified_ReventRemovesEntityFromTheSavingList() { var entity = new FileEntity("test") .SetAttribute(new Attribute("a", new IntValue(1), AttributeSource.Custom)); // add entity to the modified list _entityManager.SetEntity(entity, true); // move it to the saving list var snapshot = _entityManager.GetModified(); Assert.AreEqual(1, snapshot.Count); Assert.AreEqual(entity.Path, snapshot[0].Path); var loaded = _entityManager.GetEntity("test"); Assert.AreEqual(entity, loaded); // remove attribute "a" entity.RemoveAttribute("a"); Assert.IsFalse(entity.Any()); // revert the entity to its initial state snapshot[0].Revert(); Assert.IsTrue(entity.Any()); Assert.AreEqual(1, entity.GetValue <IntValue>("a").Value); loaded = _entityManager.GetEntity("test"); Assert.IsNull(loaded); }
public void GetModified_ReturnRemovesEntityFromTheSavingList() { var entity = new FileEntity("test") .SetAttribute(new Attribute("a", new IntValue(1), AttributeSource.Custom)); // add entity to the modified list _entityManager.SetEntity(entity, true); // move it to the saving list var snapshot = _entityManager.GetModified(); Assert.AreEqual(1, snapshot.Count); Assert.AreEqual(entity.Path, snapshot[0].Path); var loaded = _entityManager.GetEntity("test"); Assert.AreEqual(entity, loaded); // remove attribute "a" entity.RemoveAttribute("a"); Assert.IsFalse(entity.Any()); // return the entity to the modified list snapshot[0].Return(); Assert.IsFalse(entity.Any()); // It returns the modified entity. This is ok, Return should not change the entity state loaded = _entityManager.GetEntity("test"); Assert.AreEqual(entity, loaded); // move it to the saving list again snapshot = _entityManager.GetModified(); Assert.AreEqual(1, snapshot.Count); Assert.AreEqual(entity.Path, snapshot[0].Path); Assert.AreEqual(1, snapshot[0].GetValue <IntValue>("a").Value); loaded = _entityManager.GetEntity("test"); Assert.AreEqual(entity, loaded); }