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 StoreThumbnail_EntityWithoutThumbnailAttribute() { var entity = new FileEntity("test") .SetAttribute(new Attribute("attr", new IntValue(1), AttributeSource.Custom)) .SetAttribute(new Attribute("thumbnail", new ImageValue(new byte[] { 0x21 }), AttributeSource.Metadata)); _storage.Store(entity); _storage.ApplyChanges(); var result = _storage.Load("test"); Assert.IsNotNull(result); Assert.AreEqual(1, result.GetValue <IntValue>("attr").Value); Assert.AreEqual(1, result.GetValue <ImageValue>("thumbnail").Value.Length); Assert.AreEqual(0x21, result.GetValue <ImageValue>("thumbnail").Value[0]); entity = entity.RemoveAttribute("thumbnail"); _storage.StoreThumbnail(entity); _storage.ApplyChanges(); result = _storage.Load("test"); Assert.IsNotNull(result); Assert.AreEqual(1, result.GetValue <IntValue>("attr").Value); Assert.AreEqual(1, result.GetValue <ImageValue>("thumbnail").Value.Length); Assert.AreEqual(0x21, result.GetValue <ImageValue>("thumbnail").Value[0]); }
public void Remove_NonExitentKey() { IEntity attrs = new FileEntity("test"); var newAttrs = attrs.RemoveAttribute("test"); Assert.AreEqual(newAttrs, attrs); }
public void Remove_OneKey() { IEntity attrs = new FileEntity("test"); attrs = attrs.SetAttribute(new Attribute("test", new IntValue(42), AttributeSource.Custom)); Assert.IsNotNull(attrs.GetAttribute("test")); attrs = attrs.RemoveAttribute("test"); Assert.IsNull(attrs.GetAttribute("test")); }
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); }