public void TestTryGetValue_NoSuchProperty_ReturnsFalse() { var instance = new { }; PropertyDictionary dictionary = new PropertyDictionary(instance); object value; bool result = dictionary.TryGetValue("Name", out value); Assert.IsFalse(result, "The property should not have been found."); Assert.IsNull(value, "The value should have been null."); }
public void TestTryGetValue_PropertyExists_ReturnsTrue() { var instance = new { Name = "Test" }; PropertyDictionary dictionary = new PropertyDictionary(instance); object value; bool result = dictionary.TryGetValue("Name", out value); Assert.IsTrue(result, "The property should have been found."); Assert.AreEqual(instance.Name, value, "The value should have equaled the wrapped property value."); }
public void SetReference(string property, object value) { if (Mute) { return; } //drop old references object currentValue = null; properties.TryGetValue(property, out currentValue); if (currentValue is PersistentId) { PersistentId id = (PersistentId)currentValue; if (Context.IsLoaded(id.Id)) { IPersistentObject oldRef = Context.Get(id.Id); ObjectReference reference = new ObjectReference(); reference.Property = property; reference.ObjectId = target.Id; ((IPersistentObject)oldRef).RemoveReference(reference); } } //create new reference if (value is IPersistentObject) { ObjectReference reference = new ObjectReference(); reference.Property = property; reference.ObjectId = target.Id; ((IPersistentObject)value).AddReference(reference); PersistentId id = new PersistentId(); id.Id = ((IPersistentObject)value).Id; value = id; } properties[property] = value; }