public void TestGetItemAttributeExpression() { var item = new Item("test", 14, 1, 2, 3, 4); const int ATTRIBUTE_ID = 1; const double ATTRIBUTE_VALUE = 15.0; var attribute = new Attribute(item, ATTRIBUTE_ID, "testAttribute", true , true, ATTRIBUTE_VALUE); item.AddAttributeRange(new[] {attribute}); var e = new GetItemAttributeExpression(new ConstantExpression(item), new ConstantExpression(ATTRIBUTE_ID)); e.Execute(_context, _stack); Assert.IsTrue(attribute == ((IEnumerable<IAttribute>)_stack.Pop()).Single()); Assert.IsFalse(_stack.Any()); }
public void TestGetItemAttributeValueExpression() { var item = new Item("test", 14, 1, 2,3, 4); const int ATTRIBUTE_ID = 1; const double ATTRIBUTE_VALUE = 15.0; item.AddAttributeRange(new[] {new Attribute(item, ATTRIBUTE_ID, "testAttribute", true, true, ATTRIBUTE_VALUE)}); var e = new GetItemAttributeValueExpression(new ConstantExpression(item), new ConstantExpression(ATTRIBUTE_ID)); e.Execute(_context, _stack); Assert.AreEqual(ATTRIBUTE_VALUE, _stack.Pop()); Assert.IsFalse(_stack.Any()); }
private void TestLocationAndSkillRequirementInternal(int attributeId) { int skillType = 3000 + attributeId; var item = new Item(); item.AddAttributeRange(new[] { new Attribute(item, attributeId, "requiredSkill", true , true, skillType), }); var item2 = new Item(); item2.AddAttributeRange(new[] { new Attribute(item2, 0, "invalid", true, true, skillType), }); var item3 = new Item(); item3.AddAttributeRange(new[] { new Attribute(item3, attributeId, "requiredSkill", true, true, skillType), }); _ship.InstalledItems.Add(item); _ship.InstalledItems.Add(item2); _ship.InstalledItems.Add(item3); var e = new LocationAndSkillRequirementSelectorExpression(new ConstantExpression(_ship), new ConstantExpression(skillType)); e.Execute(_context, _stack); var items = ((IEnumerable<Item>) _stack.Pop()).ToArray(); Assert.IsFalse(_stack.Any()); Assert.AreEqual(2, items.Count()); Assert.AreSame(item, items.First()); Assert.AreSame(item3, items.Skip(1).First()); }