public void SetMemoryItem() { MemoryItem testItem = new MemoryItem(new MemoryProperty("Prop", TestType)); var o = new DataObject(TestType); testItem.Set(o); Assert.AreEqual(o, testItem.Value, "Value failed to store in memory."); }
public void SetMemoryItemInvalidType() { MemoryItem testItem = new MemoryItem(new MemoryProperty("Prop", TestType)); var o = new DataObject(AnotherTestType); Assert.ThrowsException <MemoryException>(() => testItem.Set(o), "Set operation should not have succeeded with incorrect type."); Assert.AreNotEqual(o, testItem.Value, "Value was incorrectly stored in memory."); }
/// <summary> /// Creates a <see cref="MemoryItem"/> of the given type and key of the <see cref="ScriptInput"/> and attempts to set its <see cref="MemoryItem.Value"/> to the given <see cref="DataObject"/>. /// </summary> /// <param name="dataObject">The desired value of the <see cref="MemoryItem"/>.</param> public MemoryItem CreateMemoryItem(DataObject dataObject) { if (CanCreateMemoryItem(dataObject)) { var item = new MemoryItem( new MemoryProperty( this.Key, this.Type, MemoryProperty.DefaultFlags | PropertyFlags.Scoped)); item.Set(dataObject); return(item); } else { throw new ScriptInputException($"Could not parse input {this.Key}: input was of invalid type."); } }