Ejemplo n.º 1
0
        public void OnSuspiciousObjectCollides_UpdateTogglesSuspicions_SendsExpectedMessages()
        {
            _vision.IsSuspiciousResult = false;
            var detectedObject = new GameObject();

            _vision.TestCollide(detectedObject);

            _vision.IsSuspiciousResult = true;

            _vision.TestUpdate(_vision.TimeUntilDetection + 0.1f);
            _vision.TestUpdate(_vision.TimeUntilDetection + 0.1f);

            var messageSpy = new UnityTestMessageHandleResponseObject <SuspiciousObjectDetectedMessage>();
            var handle     =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <SuspiciousObjectDetectedMessage>(_detector,
                                                                                                          messageSpy.OnResponse);

            _vision.IsSuspiciousResult = false;

            _vision.TestUpdate(_vision.TimeUntilDetection + 0.1f);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_detector, handle);
        }
Ejemplo n.º 2
0
        public void OnSuspiciousObjectCollides_Updates_SendsDetectionMessageToDetectorForCorrectObject()
        {
            _vision.IsSuspiciousResult = true;
            var detectedObject = new GameObject();
            var laterObject    = new GameObject();

            var messageSpy = new UnityTestMessageHandleResponseObject <SuspiciousObjectDetectedMessage>();
            var handle     =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <SuspiciousObjectDetectedMessage>(_detector,
                                                                                                          messageSpy.OnResponse);

            _vision.TestCollide(detectedObject);

            _vision.TestUpdate(_vision.TimeUntilDetection - 0.1f);

            _vision.TestCollide(laterObject);

            _vision.TestUpdate(0.2f);

            Assert.IsTrue(messageSpy.ActionCalled);
            Assert.AreSame(detectedObject, messageSpy.MessagePayload.SuspiciousGameObject);

            _vision.TestUpdate(_vision.TimeUntilDetection + 0.1f);

            Assert.AreSame(laterObject, messageSpy.MessagePayload.SuspiciousGameObject);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_detector, handle);
        }
Ejemplo n.º 3
0
        public void ReadData_SetsExpectedCompanions()
        {
            var messageSpy      = new UnityTestMessageHandleResponseObject <CompanionSlotsUpdatedMessage>();
            var initialUseCount = _companion.GetCompanionDataResult.PowerUseCount;

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <CompanionSlotsUpdatedMessage>(_set.gameObject,
                                                                                                       messageSpy.OnResponse);

            _set.SetCompanion(_companion, ECompanionSlot.Primary);

            var stream = new MemoryStream();

            _set.WriteData(stream);

            _set.ClearCompanion(ECompanionSlot.Primary);

            var readStream = new MemoryStream(stream.ToArray());

            _companion.GetCompanionDataResult.PowerUseCount++;

            _set.ReadData(readStream);

            _set.TestUpdate();

            Assert.IsTrue(messageSpy.ActionCalled);
            Assert.IsNotNull(messageSpy.MessagePayload.Updates[ECompanionSlot.Primary].PriorCompanion);
            Assert.AreEqual(initialUseCount, messageSpy.MessagePayload.Updates[ECompanionSlot.Primary].PriorCompanion.GetCompanionData().PowerUseCount);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_set.gameObject, handle);
        }
Ejemplo n.º 4
0
        public void CycleActiveGadget_ActiveSlotDoesNotChange_DoesNotSendMessage()
        {
            _set.InitialCapacities.Add(new GadgetSlotCapcity {
                Capacity = 2, Slot = EGadgetSlot.Mine
            });
            _set.InitialCapacities.Add(new GadgetSlotCapcity {
                Capacity = 2, Slot = EGadgetSlot.NoiseMaker
            });

            _gadget.GetGadgetSlotResult      = EGadgetSlot.Mine;
            _otherGadget.GetGadgetSlotResult = EGadgetSlot.NoiseMaker;

            _set.TestAwake();

            _set.AddGadget(_gadget);
            _set.AddGadget(_otherGadget);

            var messageSpy = new UnityTestMessageHandleResponseObject <GadgetUpdatedMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher
                         <GadgetUpdatedMessage>(_set.gameObject, messageSpy.OnResponse);

            _set.CycleActiveGadget(200);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_set.gameObject, handle);
        }
Ejemplo n.º 5
0
        public void ReadData_Collisions_CannotSave()
        {
            _trigger.TestCollide(_character.gameObject);

            var stream = new MemoryStream();

            _trigger.WriteData(stream);

            var readStream = new MemoryStream(stream.ToArray());

            _trigger.ReadData(readStream);

            var messageSpy =
                new UnityTestMessageHandleResponseObject <SaveGameTriggerActivatedMessage>();

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <SaveGameTriggerActivatedMessage>(_character.gameObject,
                                                                                                          messageSpy.OnResponse);

            _trigger.TestCollide(_character.gameObject);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_character.gameObject, handle);
        }
Ejemplo n.º 6
0
        public void CycleActiveGadget_Negative_WrapsAround()
        {
            _set.InitialCapacities.Add(new GadgetSlotCapcity {
                Capacity = 2, Slot = EGadgetSlot.Mine
            });
            _set.InitialCapacities.Add(new GadgetSlotCapcity {
                Capacity = 2, Slot = EGadgetSlot.NoiseMaker
            });

            _gadget.GetGadgetSlotResult      = EGadgetSlot.Mine;
            _otherGadget.GetGadgetSlotResult = EGadgetSlot.NoiseMaker;

            _set.TestAwake();

            _set.AddGadget(_gadget);
            _set.AddGadget(_otherGadget);

            var messageSpy = new UnityTestMessageHandleResponseObject <GadgetUpdatedMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher
                         <GadgetUpdatedMessage>(_set.gameObject, messageSpy.OnResponse);

            _set.CycleActiveGadget(-1);

            Assert.IsTrue(messageSpy.ActionCalled);
            Assert.AreSame(_otherGadget, messageSpy.MessagePayload.NewGadget);
            Assert.AreEqual(1, messageSpy.MessagePayload.SlotCount);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_set.gameObject, handle);
        }
Ejemplo n.º 7
0
        public void UseActiveGadget_GadgetsLeftInSameSlot_SendsMessageWithRemainingGadget()
        {
            _set.InitialCapacities.Add(new GadgetSlotCapcity {
                Capacity = 2, Slot = EGadgetSlot.Mine
            });

            _gadget.GetGadgetSlotResult      = EGadgetSlot.Mine;
            _otherGadget.GetGadgetSlotResult = EGadgetSlot.Mine;

            _set.TestAwake();

            _set.AddGadget(_gadget);
            _set.AddGadget(_otherGadget);

            var messageSpy = new UnityTestMessageHandleResponseObject <GadgetUpdatedMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher
                         <GadgetUpdatedMessage>(_set.gameObject, messageSpy.OnResponse);

            _set.UseActiveGadget();

            Assert.IsTrue(messageSpy.ActionCalled);
            Assert.AreSame(_gadget, messageSpy.MessagePayload.NewGadget);
            Assert.AreEqual(1, messageSpy.MessagePayload.SlotCount);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_set.gameObject, handle);
        }
Ejemplo n.º 8
0
        private void RegisterForTriggerMessages()
        {
            _triggerMessageHandle = UnityMessageEventFunctions.RegisterActionWithDispatcher <TriggerMessage>
                                        (TriggerObject, OnTrigger);

            _cancelTriggerMessageHandle = UnityMessageEventFunctions.RegisterActionWithDispatcher <CancelTriggerMessage>
                                              (TriggerObject, OnCancelTrigger);
        }
Ejemplo n.º 9
0
        public void RegisterMessageEvent_NullDispatcher_ExceptionThrown()
        {
            TestUnityMessageEventDispatcherInterface dispatcherInterface = null;
            var responseObject = new UnityTestMessageHandleResponseObject <UnityTestMessagePayload>();

            Assert.Throws <UnityMessageHandleException>(() =>
                                                        UnityMessageEventFunctions.RegisterActionWithDispatcher <UnityTestMessagePayload>(dispatcherInterface,
                                                                                                                                          responseObject.OnResponse));
        }
Ejemplo n.º 10
0
        private void RegisterForMessages()
        {
            _enterDeadHandle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <EnterDeadActionStateMessage>(DetectingObject,
                                                                                                      OnEnterDeadActionState);

            _leftDeadHandle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <LeftDeadActionStateMessage>(DetectingObject,
                                                                                                     OnLeftDeadActionState);
        }
Ejemplo n.º 11
0
        private void RegisterAnimalMessages()
        {
            _enterLocomotionHandle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <EnterLocomotionStateMessage>(gameObject,
                                                                                                      OnEnterLocomotion);

            _leaveLocomotionHandle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <LeaveLocomotionStateMessage>(gameObject,
                                                                                                      OnLeavingLocomotion);
        }
Ejemplo n.º 12
0
        public void RegisterMessageEvent_RegistersMessageEvent()
        {
            var dispatcherInterface = new TestUnityMessageEventDispatcherInterface();
            var responseObject      = new UnityTestMessageHandleResponseObject <UnityTestMessagePayload>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher <UnityTestMessagePayload>(dispatcherInterface, responseObject.OnResponse);

            Assert.IsTrue(handle.IsRegistered());

            dispatcherInterface.Dispatcher.UnregisterForMessageEvent(handle);
        }
        public void Start_SendsEnterCinematicActionStateMessage()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <EnterCinematicCameraActionStateMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher <EnterCinematicCameraActionStateMessage>(
                _character.gameObject, messageSpy.OnResponse);

            _actionState.Start();

            Assert.IsTrue(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_character.gameObject, handle);
        }
        public void NullCollides_NoTriggerMessage()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <TriggerMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher <TriggerMessage>
                             (_pushTrigger.gameObject, messageSpy.OnResponse);

            _pushTrigger.TestCollide(null);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_pushTrigger.gameObject, handle);
        }
Ejemplo n.º 15
0
        public void Start_FiresSetMaxEventWithMaxStamina()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <MaxStaminaChangedMessage>();

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <MaxStaminaChangedMessage>(_stamina.gameObject, messageSpy.OnResponse);

            _stamina.TestStart();

            Assert.AreEqual(_stamina.InitialStamina, messageSpy.MessagePayload.NewMaxStamina);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_stamina.gameObject, handle);
        }
        public void PushableStopsColliding_NotColliding_NoCancelTriggerMessage()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <CancelTriggerMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher <CancelTriggerMessage>
                             (_pushTrigger.gameObject, messageSpy.OnResponse);

            _pushTrigger.TestStopColliding(_pushable.gameObject);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_pushTrigger.gameObject, handle);
        }
Ejemplo n.º 17
0
        public void AddActiveInteractable_DoesNotSendInteractableUpdatedMessage()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <ActiveInteractableUpdatedMessage>();

            var handler =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <ActiveInteractableUpdatedMessage>(
                    _interaction.gameObject, messageSpy.OnResponse);

            _interaction.AddActiveInteractable(_interactable);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_interaction.gameObject, handler);
        }
        public void PushableCollides_TriggerMessage()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <TriggerMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher <TriggerMessage>
                             (_pushTrigger.gameObject, messageSpy.OnResponse);

            _pushTrigger.TestCollide(_pushable.gameObject);

            Assert.IsTrue(messageSpy.ActionCalled);
            Assert.AreSame(_pushable.gameObject, messageSpy.MessagePayload.TriggeringObject);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_pushTrigger.gameObject, handle);
        }
Ejemplo n.º 19
0
        public void SetCompanion_NoUpdateMessage()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <CompanionSlotsUpdatedMessage>();

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <CompanionSlotsUpdatedMessage>(_set.gameObject,
                                                                                                       messageSpy.OnResponse);

            _set.SetCompanion(_companion, ECompanionSlot.Primary);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_set.gameObject, handle);
        }
Ejemplo n.º 20
0
        private void RegisterForMessages()
        {
            _enterDeadActionStateHandle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <EnterDeadActionStateMessage>(gameObject,
                                                                                                      OnEnterDeadActionState);

            _leftDeadActionStateHandle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <LeftDeadActionStateMessage>(gameObject,
                                                                                                     OnLeftDeadActionState);

            _pauseStatusChangedHandle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <PauseStatusChangedMessage>(gameObject,
                                                                                                    OnPauseStatusChanged);
        }
Ejemplo n.º 21
0
        public void Start_SendsEnterEventToOwner()
        {
            _deadActionState = new DeadActionState(new ActionStateInfo(_playerBinder.gameObject), _params);

            var eventSpy = new UnityTestMessageHandleResponseObject <EnterDeadActionStateMessage>();
            var handle   =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <EnterDeadActionStateMessage>(_playerBinder.gameObject, eventSpy.OnResponse);

            _deadActionState.Start();

            Assert.IsTrue(eventSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_playerBinder.gameObject, handle);
        }
Ejemplo n.º 22
0
        public void SetEmoteState_NotChanged_DoesNotSendMessageWithNewState()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <EmoteStatusChangedMessage>();

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <EmoteStatusChangedMessage>(_emote.gameObject,
                                                                                                    messageSpy.OnResponse);

            _emote.SetEmoteState(_emote.GetEmoteState());

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_emote.gameObject, handle);
        }
Ejemplo n.º 23
0
        public void Start_SendsInteractionUpdatedMessage()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <InteractionStatusUpdatedMessage>();

            var handler =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <InteractionStatusUpdatedMessage>(
                    _interaction.gameObject, messageSpy.OnResponse);

            _interaction.TestStart();

            Assert.IsTrue(messageSpy.ActionCalled);
            Assert.IsFalse(messageSpy.MessagePayload.Interactable);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_interaction.gameObject, handler);
        }
Ejemplo n.º 24
0
        public void AlterStamina_DoesNotSendUIEventIfUnaltered()
        {
            _stamina.TestStart();

            var messageSpy = new UnityTestMessageHandleResponseObject <StaminaChangedMessage>();

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <StaminaChangedMessage>(_stamina.gameObject, messageSpy.OnResponse);

            _stamina.AlterStamina(0);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_stamina.gameObject, handle);
        }
Ejemplo n.º 25
0
        public void Update_ConditionsNotComplete_DoesNotFireRequestRespawnEventToGameMode()
        {
            _deadActionState = new DeadActionState(new ActionStateInfo(_playerBinder.gameObject), _params);

            var eventSpy = new UnityTestMessageHandleResponseObject <RequestRespawnMessage>();
            var handle   =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <RequestRespawnMessage>(GameModeComponent.RegisteredGameMode.gameObject, eventSpy.OnResponse);

            _deadActionState.Start();
            _deadActionState.Update(1.0f);

            Assert.IsFalse(eventSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(GameModeComponent.RegisteredGameMode.gameObject, handle);
        }
Ejemplo n.º 26
0
        public void UseActiveGadget_NoGadgets_NoEffect()
        {
            _set.TestAwake();

            var messageSpy = new UnityTestMessageHandleResponseObject <GadgetUpdatedMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher
                         <GadgetUpdatedMessage>(_set.gameObject, messageSpy.OnResponse);

            _set.UseActiveGadget();

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_set.gameObject, handle);
        }
Ejemplo n.º 27
0
        public void Start_EnterSpawningActionStateMessageSent()
        {
            var spawning = new SpawningActionState(new ActionStateInfo(_inputBinder.gameObject), new SpawningActionStateParams());

            var messageSpy = new UnityTestMessageHandleResponseObject <EnterSpawningActionStateMessage>();

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <EnterSpawningActionStateMessage>(
                    _inputBinder.gameObject, messageSpy.OnResponse);

            spawning.Start();

            Assert.IsTrue(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_inputBinder.gameObject, handle);
        }
Ejemplo n.º 28
0
        public void OnCollides_CharacterComponent_MessageSent()
        {
            var messageSpy =
                new UnityTestMessageHandleResponseObject <SaveGameTriggerActivatedMessage>();


            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <SaveGameTriggerActivatedMessage>(_character.gameObject,
                                                                                                          messageSpy.OnResponse);

            _trigger.TestCollide(_character.gameObject);

            Assert.IsTrue(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_character.gameObject, handle);
        }
Ejemplo n.º 29
0
        public void OnNonSuspiciousObjectCollides_DoesNotSendSightingMessageToDetector()
        {
            _vision.IsSuspiciousResult = false;
            var detectedObject = new GameObject();

            var messageSpy = new UnityTestMessageHandleResponseObject <SuspiciousObjectSightedMessage>();
            var handle     =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <SuspiciousObjectSightedMessage>(_detector,
                                                                                                         messageSpy.OnResponse);

            _vision.TestCollide(detectedObject);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_detector, handle);
        }
        public void IncorrectSpeciesCollides_NoTriggerMessage()
        {
            _pushTrigger.TriggeringSpeciesTypes.Add(ESpeciesType.Human);
            _species.GetCurrentSpeciesTypeResult = ESpeciesType.Rat;

            var messageSpy = new UnityTestMessageHandleResponseObject <TriggerMessage>();

            var handle = UnityMessageEventFunctions.RegisterActionWithDispatcher <TriggerMessage>
                             (_pushTrigger.gameObject, messageSpy.OnResponse);

            _pushTrigger.TestCollide(_species.gameObject);

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_pushTrigger.gameObject, handle);
        }