Mock <AbstractInput> inputReturningMockTouch() { var touch = touchExpectedAtOrigin(); var mockInput = factory.CreateMock <AbstractInput>(); mockInput.Expects.AtLeastOne.GetProperty(_ => _.touchCount).WillReturn(1); mockInput.Expects.AtLeastOne.MethodWith(_ => _.GetTouch(0)).WillReturn(touch.MockObject); return(mockInput); }
public void SetUp() { factory = new MockFactory(); sensor = factory.CreateMock <AbstractTouchSensor>(); prompt = factory.CreateMock <TextControl>(); prompt.Expects.One.Method(_ => _.show()); prompt.Expects.One.Method(_ => _.hide()); prompt.Expects.One.Method(_ => _.setText("")).With(Is.TypeOf(typeof(String))); sprite = factory.CreateMock <Sprite>(); messageBox = factory.CreateMock <AbstractMessageBox>(); messageBox.Expects.One.Method(_ => _.setMessage("")).With(Is.TypeOf(typeof(String))); messageBox.Expects.One.Method(_ => _.hide()); messageBox.Expects.One.Method(_ => _.show()); gameObject = factory.CreateMock <GameObject>(); gameObject.Expects.Any.Method(_ => _.GetComponent <Sprite>()).WillReturn(sprite.MockObject); }
public void SetUp() { factory = new MockFactory(); camera = factory.CreateMock <Camera>(); inputReturningTouch = inputReturningMockTouch(); }
public void triggersFrontMostObjectWhenObjectsOverlap() { var messagePromptCoordinator = new MessagePromptCoordinator(prompt.MockObject, messageBox.MockObject); var first = factory.CreateMock <GameObject>(); first.Expects.Any.Method(_ => _.GetComponent <Sprite>()).WillReturn(sprite.MockObject); var second = factory.CreateMock <GameObject>(); second.Expects.Any.Method(_ => _.GetComponent <Sprite>()).WillReturn(sprite.MockObject); var back = new Vector3(0, 0, 0); var backTransform = new Transform() { position = back }; var front = new Vector3(0, 0, -1); var frontTransform = new Transform() { position = front }; // if you think this looks weird, it is. we can't mock bareback public fields, and Unity is full of them. first.MockObject.transform = backTransform; second.MockObject.transform = frontTransform; var frontObjectResponse = "front object response"; var frontObjectAction = "action2"; var actionResponses = new Dictionary <GameObject, ActionResponsePair[]> { { first.MockObject, new [] { new ActionResponsePair("action", new[] { "response" }) } }, { second.MockObject, new [] { new ActionResponsePair(frontObjectAction, new[] { frontObjectResponse }) } } }; using (factory.Ordered()) { expectTouchWithinSprite(sprite.MockObject, true); expectTouchWithinSprite(sprite.MockObject, false); expectTouchWithinSprite(sprite.MockObject, true); } messagePromptCoordinator.hintWhenTouched( GameObject => { }, sensor.MockObject, beforeEverything, actionResponses ); messagePromptCoordinator.Update(beforeEverything); GameObject triggeredObject = null; messageBox.Expects.One.Method(_ => _.setMessage("")).With(Is.EqualTo(frontObjectResponse)); messageBox.Expects.One.Method(_ => _.hide()); messageBox.Expects.One.Method(_ => _.show()); prompt.Expects.One.Method(_ => _.setText("")).With(Is.EqualTo(frontObjectAction)); prompt.Expects.One.Method(_ => _.hide()); prompt.Expects.One.Method(_ => _.show()); messagePromptCoordinator.hintWhenTouched( gameObject => { triggeredObject = gameObject; }, sensor.MockObject, afterMessageTime, actionResponses ); messageBox.Expects.One.Method(_ => _.hide()); messagePromptCoordinator.Update(afterMessageTime + MessagePromptCoordinator.promptTime + 0.1f); Assert.That(triggeredObject, Iz.EqualTo(second.MockObject)); }
public void SetUp() { factory = new MockFactory(); loopTracker = factory.CreateMock <AbstractLoopTracker>(); sceneFactory = factory.CreateMock <AbstractSceneFactory>(); }