public void PublishInactiveConsumerComponent() { ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData(); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); ActiveCollisionConsumerMock oneConsumer = oneContainer.AddComponent <ActiveCollisionConsumerMock>(); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer); ActiveCollisionConsumerMock twoConsumer = twoContainer.AddComponent <ActiveCollisionConsumerMock>(); twoConsumer.enabled = false; eventData.ActiveCollisions.Add(oneData); eventData.ActiveCollisions.Add(twoData); subject.SetActiveCollisions(eventData); Assert.IsFalse(oneConsumer.received); Assert.IsFalse(twoConsumer.received); subject.Publish(); Assert.IsTrue(oneConsumer.received); Assert.IsFalse(twoConsumer.received); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); }
public void PublishInactiveComponent() { UnityEventListenerMock registeredMock = new UnityEventListenerMock(); UnityEventListenerMock publishedMock = new UnityEventListenerMock(); subject.Registered.AddListener(registeredMock.Listen); subject.Published.AddListener(publishedMock.Listen); ActiveCollisionConsumerMock oneConsumer = containingObject.AddComponent <ActiveCollisionConsumerMock>(); Assert.IsFalse(registeredMock.Received); Assert.AreEqual(0, subject.RegisteredConsumers.Count); subject.Register(oneConsumer, null); Assert.IsTrue(registeredMock.Received); Assert.AreEqual(1, subject.RegisteredConsumers.Count); registeredMock.Reset(); Assert.IsFalse(oneConsumer.received); Assert.IsFalse(publishedMock.Received); subject.enabled = false; subject.Publish(); Assert.IsFalse(publishedMock.Received); Assert.IsFalse(oneConsumer.received); }
public void Publish() { ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData(); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); ActiveCollisionConsumerMock oneConsumer = oneContainer.AddComponent <ActiveCollisionConsumerMock>(); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer); ActiveCollisionConsumerMock twoConsumer = twoContainer.AddComponent <ActiveCollisionConsumerMock>(); eventData.ActiveCollisions.Add(oneData); eventData.ActiveCollisions.Add(twoData); subject.SetActiveCollisions(eventData); Assert.IsFalse(oneConsumer.received); Assert.IsFalse(twoConsumer.received); subject.Publish(); Assert.IsTrue(oneConsumer.received); Assert.IsTrue(twoConsumer.received); Assert.AreEqual("{ SourceContainer = [null] | PublisherContainer = New Game Object (UnityEngine.GameObject) }", subject.Payload.ToString()); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); }
public void RegisterUnregister() { UnityEventListenerMock registeredMock = new UnityEventListenerMock(); UnityEventListenerMock unregisteredMock = new UnityEventListenerMock(); subject.Registered.AddListener(registeredMock.Listen); subject.Unregistered.AddListener(unregisteredMock.Listen); ActiveCollisionConsumerMock oneConsumer = containingObject.AddComponent <ActiveCollisionConsumerMock>(); Assert.IsFalse(registeredMock.Received); Assert.IsFalse(unregisteredMock.Received); Assert.AreEqual(0, subject.RegisteredConsumers.Count); subject.Register(oneConsumer, null); Assert.IsTrue(registeredMock.Received); Assert.IsFalse(unregisteredMock.Received); Assert.AreEqual(1, subject.RegisteredConsumers.Count); registeredMock.Reset(); unregisteredMock.Reset(); ActiveCollisionConsumerMock twoConsumer = containingObject.AddComponent <ActiveCollisionConsumerMock>(); subject.Register(twoConsumer, null); Assert.IsTrue(registeredMock.Received); Assert.IsFalse(unregisteredMock.Received); Assert.AreEqual(2, subject.RegisteredConsumers.Count); registeredMock.Reset(); unregisteredMock.Reset(); subject.Unregister(oneConsumer); Assert.IsFalse(registeredMock.Received); Assert.IsTrue(unregisteredMock.Received); Assert.AreEqual(1, subject.RegisteredConsumers.Count); registeredMock.Reset(); unregisteredMock.Reset(); subject.IgnoredRegisteredConsumers.Add(twoConsumer); Assert.AreEqual(1, subject.IgnoredRegisteredConsumers.Count); subject.Unregister(twoConsumer); Assert.IsFalse(registeredMock.Received); Assert.IsTrue(unregisteredMock.Received); Assert.AreEqual(0, subject.RegisteredConsumers.Count); Assert.AreEqual(0, subject.IgnoredRegisteredConsumers.Count); }
public void RegisterInactiveGameObject() { UnityEventListenerMock registeredMock = new UnityEventListenerMock(); UnityEventListenerMock publishedMock = new UnityEventListenerMock(); subject.Registered.AddListener(registeredMock.Listen); subject.Published.AddListener(publishedMock.Listen); subject.gameObject.SetActive(false); ActiveCollisionConsumerMock oneConsumer = containingObject.AddComponent <ActiveCollisionConsumerMock>(); Assert.IsFalse(registeredMock.Received); Assert.AreEqual(0, subject.RegisteredConsumers.Count); subject.Register(oneConsumer, null); Assert.IsFalse(registeredMock.Received); Assert.AreEqual(0, subject.RegisteredConsumers.Count); }
public void PublishWithRegisteredConsumerContainer() { ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData(); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); ActiveCollisionConsumerMock oneConsumer = oneContainer.AddComponent <ActiveCollisionConsumerMock>(); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer); ActiveCollisionConsumerMock twoConsumer = twoContainer.AddComponent <ActiveCollisionConsumerMock>(); eventData.ActiveCollisions.Add(oneData); eventData.ActiveCollisions.Add(twoData); subject.SetActiveCollisions(eventData); ActiveCollisionRegisteredConsumerContainerMock reigsteredConsumerContainer = containingObject.AddComponent <ActiveCollisionRegisteredConsumerContainerMock>(); subject.RegisteredConsumerContainer = reigsteredConsumerContainer; Assert.AreEqual(0, reigsteredConsumerContainer.ConsumerCount); Assert.AreEqual(0, reigsteredConsumerContainer.IgnoredConsumerCount); subject.Publish(); Assert.AreEqual(2, reigsteredConsumerContainer.ConsumerCount); Assert.AreEqual(2, reigsteredConsumerContainer.IgnoredConsumerCount); subject.UnregisterRegisteredConsumer(twoConsumer); Assert.AreEqual(1, reigsteredConsumerContainer.ConsumerCount); Assert.AreEqual(1, reigsteredConsumerContainer.IgnoredConsumerCount); subject.UnregisterRegisteredConsumer(oneConsumer); Assert.AreEqual(0, reigsteredConsumerContainer.ConsumerCount); Assert.AreEqual(0, reigsteredConsumerContainer.IgnoredConsumerCount); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); }
public void RegisterAndPublish() { UnityEventListenerMock registeredMock = new UnityEventListenerMock(); UnityEventListenerMock publishedMock = new UnityEventListenerMock(); subject.Registered.AddListener(registeredMock.Listen); subject.Published.AddListener(publishedMock.Listen); ActiveCollisionConsumerMock oneConsumer = containingObject.AddComponent <ActiveCollisionConsumerMock>(); Assert.IsFalse(registeredMock.Received); Assert.AreEqual(0, subject.RegisteredConsumers.Count); subject.Register(oneConsumer, null); Assert.IsTrue(registeredMock.Received); Assert.AreEqual(1, subject.RegisteredConsumers.Count); registeredMock.Reset(); ActiveCollisionConsumerMock twoConsumer = containingObject.AddComponent <ActiveCollisionConsumerMock>(); subject.Register(twoConsumer, null); Assert.IsTrue(registeredMock.Received); Assert.AreEqual(2, subject.RegisteredConsumers.Count); registeredMock.Reset(); Assert.IsFalse(oneConsumer.received); Assert.IsFalse(twoConsumer.received); Assert.IsFalse(publishedMock.Received); subject.Publish(); Assert.IsTrue(publishedMock.Received); Assert.IsTrue(oneConsumer.received); Assert.IsTrue(twoConsumer.received); Assert.AreEqual("{ Consumer = New Game Object (Test.Zinnia.Tracking.Collision.Active.ActiveCollisionConsumerMock) | Payload = [null] }", subject.GetEventData().ToString()); }
public void RegisterUnregisterOnConsumerContainer() { UnityEventListenerMock registeredMock = new UnityEventListenerMock(); UnityEventListenerMock unregisteredMock = new UnityEventListenerMock(); subject.Registered.AddListener(registeredMock.Listen); subject.Unregistered.AddListener(unregisteredMock.Listen); GameObject containerOne = new GameObject(); GameObject containerTwo = new GameObject(); ActiveCollisionConsumerMock oneConsumerA = containerOne.AddComponent <ActiveCollisionConsumerMock>(); ActiveCollisionConsumerMock oneConsumerB = containerOne.AddComponent <ActiveCollisionConsumerMock>(); ActiveCollisionConsumerMock twoConsumer = containerTwo.AddComponent <ActiveCollisionConsumerMock>(); oneConsumerA.SetConsumerContainer(containerOne); oneConsumerB.SetConsumerContainer(containerOne); twoConsumer.SetConsumerContainer(containerTwo); subject.Register(oneConsumerA, null); subject.Register(oneConsumerB, null); subject.Register(twoConsumer, null); Assert.IsFalse(unregisteredMock.Received); Assert.AreEqual(3, subject.RegisteredConsumers.Count); registeredMock.Reset(); unregisteredMock.Reset(); subject.UnregisterConsumersOnContainer(containerOne); Assert.IsFalse(registeredMock.Received); Assert.IsTrue(unregisteredMock.Received); Assert.AreEqual(1, subject.RegisteredConsumers.Count); Object.DestroyImmediate(containerOne); Object.DestroyImmediate(containerTwo); }