예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #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);
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
0
 private void UnregisterForMessages()
 {
     if (_enterDeadActionStateHandle != null)
     {
         UnityMessageEventFunctions.UnregisterActionWithDispatcher(gameObject, _enterDeadActionStateHandle);
     }
 }
예제 #9
0
 private void UnregisterForTriggerMessages()
 {
     if (TriggerObject != null)
     {
         UnityMessageEventFunctions.UnregisterActionWithDispatcher(TriggerObject, _cancelTriggerMessageHandle);
         UnityMessageEventFunctions.UnregisterActionWithDispatcher(TriggerObject, _triggerMessageHandle);
     }
 }
예제 #10
0
        public void UnregisterMessageEvent_UnregistersEvent()
        {
            var dispatcherInterface = new TestUnityMessageEventDispatcherInterface();
            var responseObject      = new UnityTestMessageHandleResponseObject <UnityTestMessagePayload>();
            var handle = dispatcherInterface.Dispatcher.RegisterForMessageEvent <UnityTestMessagePayload>(responseObject.OnResponse);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(dispatcherInterface, handle);

            Assert.IsFalse(handle.IsRegistered());
        }
예제 #11
0
        public void UnregisterMessageEvent_NullDispatcher_ExceptionThrown()
        {
            TestUnityMessageEventDispatcherInterface dispatcherInterface = null;

            var handle = new UnityMessageEventHandle <UnityTestMessagePayload>();

            Assert.Throws <UnityMessageHandleException>(() =>
                                                        UnityMessageEventFunctions.UnregisterActionWithDispatcher(dispatcherInterface,
                                                                                                                  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);
        }
예제 #13
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);
        }
        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);
        }
        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);
        }
예제 #17
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);
        }
예제 #18
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);
        }
예제 #19
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);
        }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #22
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);
        }
예제 #23
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);
        }
예제 #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);
        }
예제 #25
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 OnNoiseHeard_NotNoiseOfInterest_NoMessageSent()
        {
            var messageSpy = new UnityTestMessageHandleResponseObject <NoiseHeardMessage>();

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <NoiseHeardMessage>(_listener.gameObject,
                                                                                            messageSpy.OnResponse);

            _listener.OnNoiseHeard(new NoiseData {
                NoiseType = ENoiseType.Explosion
            });

            Assert.IsFalse(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_listener.gameObject, handle);
        }
        public void Start_SendsEnterLocomotionStateMessage()
        {
            var locomotion = new LocomotionActionState(new ActionStateInfo(_inputBinder.gameObject));

            var messageSpy = new UnityTestMessageHandleResponseObject <EnterLocomotionStateMessage>();

            var handle =
                UnityMessageEventFunctions.RegisterActionWithDispatcher <EnterLocomotionStateMessage>(
                    _characterComponent.gameObject, messageSpy.OnResponse);

            locomotion.Start();

            Assert.IsTrue(messageSpy.ActionCalled);

            UnityMessageEventFunctions.UnregisterActionWithDispatcher(_characterComponent.gameObject, handle);
        }
예제 #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);
        }
예제 #29
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);
        }
        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);
        }