public void ShouldReturnComponentOfType() { var state = new TestState(); var fooComp = new FooComponent(); var customFoo = new FooComponent { Test = "NewFoo" }; state.AddComponent(fooComp); state.AddComponent(customFoo); Assert.IsInstanceOf<FooComponent>(state.GetComponent(typeof(FooComponent))); }
public void ShouldReturnComponentMatchingPredicate() { var state = new TestState(); var fooComp = new FooComponent(); var customFoo = new FooComponent { Test = "NewFoo" }; state.AddComponent(fooComp); state.AddComponent(customFoo); // We have to do some null checking, as we have both Foo and Bar components // in the game state. Assert.AreEqual(state.GetComponent(c => { var cf = c as FooComponent; return cf != null && cf.Test == "NewFoo"; }), customFoo); }
var state = new TestState(); var fooComp = new FooComponent(); var customFoo = new FooComponent { Test = "NewFoo" }; var barComp = new BarComponent(); var customBar = new BarComponent { Test = "NewBar" }; state.AddComponent(fooComp); state.AddComponent(customFoo); state.AddComponent(barComp); state.AddComponent(customBar); Assert.AreEqual(state.GetAllComponents().Count(), 4);
var state = new TestState(); var fooComp = new FooComponent(); var customFoo = new FooComponent { Test = "NewFoo" }; state.AddComponent(fooComp); state.AddComponent(customFoo); // We have to do some null checking, as we have both Foo and Bar components // in the game state. Assert.AreEqual(state.GetComponent(c => { var cf = c as FooComponent; return cf != null && cf.Test == "NewFoo"; }), customFoo); } [Test]