Exemplo n.º 1
0
        public void triggerFirstCallbackWhenTouchedOnFirstHintCall()
        {
            var messagePromptCoordinator = new MessagePromptCoordinator(prompt.MockObject, messageBox.MockObject);

            var singleActionResponse = new Dictionary <GameObject, ActionResponsePair[]> {
                { gameObject.MockObject, new [] { new ActionResponsePair("action", new[] { "response" }) } }
            };

            using (factory.Ordered()) {
                // touch on first tick
                expectTouchWithinSprite(sprite.MockObject, true);
                sensor.Expects.One.MethodWith(_ => _.hasTaps()).WillReturn(true);
                // no touch on second tick
                expectTouchWithinSprite(sprite.MockObject, false);
            }


            bool hintTriggered       = false;
            bool secondHintTriggered = false;

            Action <GameObject> setHintTriggered = GameObject => {
                hintTriggered = true;
            };
            Action <GameObject> setSecondHintTriggered = GameObject => {
                secondHintTriggered = true;
            };

            messagePromptCoordinator.hintWhenTouched(
                setHintTriggered,
                sensor.MockObject,
                beforeEverything,
                singleActionResponse
                );

            messagePromptCoordinator.Update(beforeEverything);

            messagePromptCoordinator.hintWhenTouched(
                setSecondHintTriggered,
                sensor.MockObject,
                beforeMessageTime,
                singleActionResponse
                );

            messagePromptCoordinator.Update(beforeMessageTime);

            messagePromptCoordinator.hintWhenTouched(
                setSecondHintTriggered,
                sensor.MockObject,
                afterMessageTime,
                singleActionResponse
                );

            messagePromptCoordinator.Update(afterMessageTime);

            Assert.That(hintTriggered, Iz.True);
            Assert.That(secondHintTriggered, Iz.False);
        }
Exemplo n.º 2
0
        public void failToTriggerAnyCallbackWhenTouchedOnSecondHintCall()
        {
            var messagePromptCoordinator = new MessagePromptCoordinator (prompt, messageBox);

            var singleActionResponse = new Dictionary<Sprite, ActionResponsePair[]> {
                {mocks.DynamicMock<Sprite>(), new [] {new ActionResponsePair("action", new[] {"response"})}}
            };

            using (mocks.Ordered()) {
                Expect.Call (sensor.insideSprite (null, null, new[] {TouchInput.TouchPhase.Began}))
                    .Constraints(Rhino.Mocks.Constraints.Is.Anything(), Rhino.Mocks.Constraints.Is.Anything(), Rhino.Mocks.Constraints.Is.Equal(new[] {TouchInput.TouchPhase.Began}))
                    .Return (false);
                // touch on second tick
                Expect.Call (sensor.insideSprite (null, null, new[] {TouchInput.TouchPhase.Began}))
                    .Constraints(Rhino.Mocks.Constraints.Is.Anything(), Rhino.Mocks.Constraints.Is.Anything(), Rhino.Mocks.Constraints.Is.Equal(new[] {TouchInput.TouchPhase.Began}))
                    .Return (true);
                Expect.Call(sensor.hasTaps()).Return(true);
            }

            mocks.ReplayAll ();

            bool hintTriggered = false;
            bool secondHintTriggered = false;

            Action<Sprite> setHintTriggered =  GameObject => { hintTriggered = true; };
            Action<Sprite> setSecondHintTriggered =  GameObject => { secondHintTriggered = true; };

            messagePromptCoordinator.hintWhenTouched (
                setHintTriggered,
                sensor,
                beforeEverything,
                singleActionResponse
                );

            messagePromptCoordinator.Update (beforeEverything);

            messagePromptCoordinator.hintWhenTouched (
                setSecondHintTriggered,
                sensor,
                beforeMessageTime,
                singleActionResponse
                );

            messagePromptCoordinator.Update(beforeMessageTime);

            messagePromptCoordinator.hintWhenTouched (
                setSecondHintTriggered,
                sensor,
                afterMessageTime,
                singleActionResponse
                );

            messagePromptCoordinator.Update(afterMessageTime);

            Assert.That (hintTriggered, Is.False);
            Assert.That (secondHintTriggered, Is.False);

            mocks.VerifyAll ();
        }
Exemplo n.º 3
0
        public void failToTriggerAnyCallbackWhenTouchedOnSecondHintCall()
        {
            var messagePromptCoordinator = new MessagePromptCoordinator(prompt.MockObject, messageBox.MockObject);

            var singleActionResponse = new Dictionary<GameObject, ActionResponsePair[]> {
                { gameObject.MockObject, new [] { new ActionResponsePair("action", new[] { "response" }) } }
            };

            using (factory.Ordered()) {
                expectTouchWithinSprite(sprite.MockObject, false);
                // touch on second tick
                expectTouchWithinSprite(sprite.MockObject, true);
                sensor.Expects.One.MethodWith(_ => _.hasTaps()).WillReturn(true);
            }

            bool hintTriggered = false;
            bool secondHintTriggered = false;

            Action<GameObject> setHintTriggered = GameObject => {
                hintTriggered = true;
            };
            Action<GameObject> setSecondHintTriggered = GameObject => {
                secondHintTriggered = true;
            };

            messagePromptCoordinator.hintWhenTouched(
                setHintTriggered,
                sensor.MockObject,
                beforeEverything,
                singleActionResponse
            );

            messagePromptCoordinator.Update(beforeEverything);

            messagePromptCoordinator.hintWhenTouched(
                setSecondHintTriggered,
                sensor.MockObject,
                beforeMessageTime,
                singleActionResponse
            );

            messagePromptCoordinator.Update(beforeMessageTime);

            messagePromptCoordinator.hintWhenTouched(
                setSecondHintTriggered,
                sensor.MockObject,
                afterMessageTime,
                singleActionResponse
            );

            messagePromptCoordinator.Update(afterMessageTime);

            Assert.That(hintTriggered, Iz.False);
            Assert.That(secondHintTriggered, Iz.False);
        }
Exemplo n.º 4
0
        public void triggerWhenTouchedAndTimeElapsed()
        {
            var messagePromptCoordinator = new MessagePromptCoordinator(prompt.MockObject, messageBox.MockObject);

            var singleActionResponse = new Dictionary <GameObject, ActionResponsePair[]> {
                { gameObject.MockObject, new [] { new ActionResponsePair("action", new[] { "response" }) } }
            };

            using (factory.Ordered()) {
                expectTouchWithinSprite(sprite.MockObject, true);
                expectTouchWithinSprite(sprite.MockObject, false);
            }

            bool hintTriggered = false;

            messagePromptCoordinator.hintWhenTouched(
                GameObject => {
                hintTriggered = true;
            },
                sensor.MockObject,
                beforeEverything,
                singleActionResponse
                );

            messagePromptCoordinator.Update(beforeEverything);

            Assert.That(hintTriggered, Iz.False);

            messagePromptCoordinator.hintWhenTouched(
                GameObject => {
                hintTriggered = true;
            },
                sensor.MockObject,
                afterMessageTime,
                singleActionResponse
                );

            messagePromptCoordinator.Update(afterMessageTime);

            Assert.That(hintTriggered, Iz.True);
        }
Exemplo n.º 5
0
        public void doesNotTriggerWhenNotTouched()
        {
            var messagePromptCoordinator = new MessagePromptCoordinator(prompt.MockObject, messageBox.MockObject);

            messagePromptCoordinator.hintWhenTouched(
                GameObject => Assert.Fail(),
                sensor.MockObject,
                beforeEverything,
                new Dictionary<GameObject, ActionResponsePair[]> { }
            );
            messagePromptCoordinator.Update(beforeEverything);
        }
Exemplo n.º 6
0
        public void doesNotTriggerWhenNotTouched()
        {
            var messagePromptCoordinator = new MessagePromptCoordinator(prompt.MockObject, messageBox.MockObject);

            messagePromptCoordinator.hintWhenTouched(
                GameObject => Assert.Fail(),
                sensor.MockObject,
                beforeEverything,
                new Dictionary <GameObject, ActionResponsePair[]> {
            }
                );
            messagePromptCoordinator.Update(beforeEverything);
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        public void triggerWhenTouchedAndTimeElapsed()
        {
            var messagePromptCoordinator = new MessagePromptCoordinator(prompt.MockObject, messageBox.MockObject);

            var singleActionResponse = new Dictionary<GameObject, ActionResponsePair[]> {
                { gameObject.MockObject, new [] { new ActionResponsePair("action", new[] { "response" }) } }
            };

            using (factory.Ordered()) {
                expectTouchWithinSprite(sprite.MockObject, true);
                expectTouchWithinSprite(sprite.MockObject, false);
            }

            bool hintTriggered = false;

            messagePromptCoordinator.hintWhenTouched(
                GameObject => {
                    hintTriggered = true;
                },
                sensor.MockObject,
                beforeEverything,
                singleActionResponse
            );

            messagePromptCoordinator.Update(beforeEverything);

            Assert.That(hintTriggered, Iz.False);

            messagePromptCoordinator.hintWhenTouched(
                GameObject => {
                    hintTriggered = true;
                },
                sensor.MockObject,
                afterMessageTime,
                singleActionResponse
            );

            messagePromptCoordinator.Update(afterMessageTime);

            Assert.That(hintTriggered, Iz.True);
        }
Exemplo n.º 9
0
        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));
        }