public void Remove() { UnityEventListenerMock firstStartedMock = new UnityEventListenerMock(); UnityEventListenerMock countChangedMock = new UnityEventListenerMock(); UnityEventListenerMock contentsChangedMock = new UnityEventListenerMock(); UnityEventListenerMock allStoppedMock = new UnityEventListenerMock(); subject.FirstStarted.AddListener(firstStartedMock.Listen); subject.CountChanged.AddListener(countChangedMock.Listen); subject.ContentsChanged.AddListener(contentsChangedMock.Listen); subject.AllStopped.AddListener(allStoppedMock.Listen); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); subject.Add(oneData); subject.Add(twoData); firstStartedMock.Reset(); countChangedMock.Reset(); contentsChangedMock.Reset(); allStoppedMock.Reset(); Assert.AreEqual(2, subject.Elements.Count); subject.Remove(oneData); Assert.AreEqual(1, subject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsTrue(countChangedMock.Received); Assert.IsTrue(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); firstStartedMock.Reset(); countChangedMock.Reset(); contentsChangedMock.Reset(); allStoppedMock.Reset(); subject.Remove(twoData); Assert.AreEqual(0, subject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsTrue(countChangedMock.Received); Assert.IsTrue(contentsChangedMock.Received); Assert.IsTrue(allStoppedMock.Received); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); }
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 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 IEnumerator AddInvalidCollisionDueToRule() { UnityEventListenerMock firstStartedMock = new UnityEventListenerMock(); UnityEventListenerMock countChangedMock = new UnityEventListenerMock(); UnityEventListenerMock contentsChangedMock = new UnityEventListenerMock(); UnityEventListenerMock allStoppedMock = new UnityEventListenerMock(); subject.FirstStarted.AddListener(firstStartedMock.Listen); subject.CountChanged.AddListener(countChangedMock.Listen); subject.ContentsChanged.AddListener(contentsChangedMock.Listen); subject.AllStopped.AddListener(allStoppedMock.Listen); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); oneContainer.AddComponent <RuleStub>(); NegationRule negationRule = oneContainer.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = oneContainer.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.CollisionValidity = new RuleContainer { Interface = negationRule }; Assert.AreEqual(0, subject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); subject.Add(oneData); Assert.AreEqual(0, subject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); Object.DestroyImmediate(oneContainer); }
public void SliceInactiveComponent() { UnityEventListenerMock slicedMock = new UnityEventListenerMock(); subject.Sliced.AddListener(slicedMock.Listen); UnityEventListenerMock remainedMock = new UnityEventListenerMock(); subject.Remained.AddListener(remainedMock.Listen); List <CollisionNotifier.EventData> collisionList = new List <CollisionNotifier.EventData>(); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); oneContainer.name = "one"; collisionList.Add(oneData); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer); twoContainer.name = "two"; collisionList.Add(twoData); GameObject threeContainer; CollisionNotifier.EventData threeData = CollisionNotifierHelper.GetEventData(out threeContainer); threeContainer.name = "three"; collisionList.Add(threeData); ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData().Set(collisionList); subject.StartIndex = 0; subject.Length = 1; subject.enabled = false; Assert.AreEqual("one,two,three", ActiveCollisionsHelper.GetNamesOfActiveCollisions(eventData)); Assert.IsFalse(slicedMock.Received); Assert.IsFalse(remainedMock.Received); ActiveCollisionsContainer.EventData remainedList; ActiveCollisionsContainer.EventData slicedList = subject.Slice(eventData, out remainedList); Assert.IsFalse(slicedMock.Received); Assert.IsFalse(remainedMock.Received); Assert.AreEqual("", ActiveCollisionsHelper.GetNamesOfActiveCollisions(slicedList)); Assert.AreEqual("one,two,three", ActiveCollisionsHelper.GetNamesOfActiveCollisions(remainedList)); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); Object.DestroyImmediate(threeContainer); }
public void CreateAndClear() { UnityEventListenerMock createdMock = new UnityEventListenerMock(); UnityEventListenerMock clearedMock = new UnityEventListenerMock(); subject.Created.AddListener(createdMock.Listen); subject.Destroyed.AddListener(clearedMock.Listen); GameObject publisherObject = new GameObject(); ActiveCollisionPublisher publisher = publisherObject.AddComponent <ActiveCollisionPublisher>(); publisher.sourceContainer = publisherObject; publisherObject.transform.position = Vector3.one; GameObject collisionNotifierContainer; CollisionNotifier.EventData collisionNotifierEventData = CollisionNotifierHelper.GetEventData(out collisionNotifierContainer); collisionNotifierContainer.transform.position = Vector3.one * 2f; collisionNotifierContainer.transform.rotation = Quaternion.Euler(Vector3.forward * 90f); ActiveCollisionConsumer.EventData eventData = new ActiveCollisionConsumer.EventData(); eventData.Set(publisher, collisionNotifierEventData); Assert.IsFalse(createdMock.Received); Assert.IsFalse(clearedMock.Received); Assert.IsNull(subject.Container); subject.Create(eventData); Assert.IsTrue(createdMock.Received); Assert.IsFalse(clearedMock.Received); Assert.IsNotNull(subject.Container); Assert.AreEqual(publisherObject.transform.position.ToString(), subject.Container.transform.position.ToString()); Assert.AreEqual(publisherObject.transform.rotation.ToString(), subject.Container.transform.rotation.ToString()); Assert.AreEqual(Vector3.one, subject.Container.transform.localScale); createdMock.Reset(); clearedMock.Reset(); subject.Destroy(); Assert.IsFalse(createdMock.Received); Assert.IsTrue(clearedMock.Received); Assert.IsNull(subject.Container); Object.DestroyImmediate(publisherObject); Object.DestroyImmediate(collisionNotifierContainer); }
public void RemoveInactiveComponent() { ActiveCollisionsContainerNoDisableClearMock altSubject = containingObject.AddComponent <ActiveCollisionsContainerNoDisableClearMock>(); UnityEventListenerMock firstStartedMock = new UnityEventListenerMock(); UnityEventListenerMock countChangedMock = new UnityEventListenerMock(); UnityEventListenerMock contentsChangedMock = new UnityEventListenerMock(); UnityEventListenerMock allStoppedMock = new UnityEventListenerMock(); altSubject.FirstStarted.AddListener(firstStartedMock.Listen); altSubject.CountChanged.AddListener(countChangedMock.Listen); altSubject.ContentsChanged.AddListener(contentsChangedMock.Listen); altSubject.AllStopped.AddListener(allStoppedMock.Listen); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); altSubject.Add(oneData); firstStartedMock.Reset(); countChangedMock.Reset(); contentsChangedMock.Reset(); allStoppedMock.Reset(); altSubject.enabled = false; Assert.AreEqual(1, altSubject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); altSubject.Remove(oneData); Assert.AreEqual(1, altSubject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); Object.DestroyImmediate(oneContainer); }
public void SetActiveCollisions() { ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData(); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer); eventData.ActiveCollisions.Add(oneData); eventData.ActiveCollisions.Add(twoData); Assert.AreEqual(0, subject.Payload.ActiveCollisions.Count); subject.SetActiveCollisions(eventData); Assert.AreEqual(2, subject.Payload.ActiveCollisions.Count); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); }
public void SortInactiveGameObject() { UnityEventListenerMock sortedMock = new UnityEventListenerMock(); subject.Sorted.AddListener(sortedMock.Listen); List <CollisionNotifier.EventData> collisionList = new List <CollisionNotifier.EventData>(); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer, Vector3.one * 5f); oneContainer.name = "one"; collisionList.Add(oneData); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer, Vector3.one * 2f); twoContainer.name = "two"; collisionList.Add(twoData); GameObject threeContainer; CollisionNotifier.EventData threeData = CollisionNotifierHelper.GetEventData(out threeContainer, Vector3.one * 3f); threeContainer.name = "three"; collisionList.Add(threeData); ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData().Set(collisionList); subject.Source = containingObject; subject.gameObject.SetActive(false); Assert.AreEqual("one,two,three", ActiveCollisionsHelper.GetNamesOfActiveCollisions(eventData)); Assert.IsFalse(sortedMock.Received); ActiveCollisionsContainer.EventData sortedList = subject.Sort(eventData); Assert.IsFalse(sortedMock.Received); Assert.AreEqual("one,two,three", ActiveCollisionsHelper.GetNamesOfActiveCollisions(sortedList)); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); Object.DestroyImmediate(threeContainer); }
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 Reverse() { UnityEventListenerMock reversedMock = new UnityEventListenerMock(); subject.Reversed.AddListener(reversedMock.Listen); List <CollisionNotifier.EventData> collisionList = new List <CollisionNotifier.EventData>(); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); oneContainer.name = "one"; collisionList.Add(oneData); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer); twoContainer.name = "two"; collisionList.Add(twoData); GameObject threeContainer; CollisionNotifier.EventData threeData = CollisionNotifierHelper.GetEventData(out threeContainer); threeContainer.name = "three"; collisionList.Add(threeData); ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData().Set(collisionList); Assert.AreEqual("one,two,three", ActiveCollisionsHelper.GetNamesOfActiveCollisions(eventData)); Assert.IsFalse(reversedMock.Received); ActiveCollisionsContainer.EventData reversedList = subject.Reverse(eventData); Assert.IsTrue(reversedMock.Received); Assert.AreEqual("three,two,one", ActiveCollisionsHelper.GetNamesOfActiveCollisions(reversedList)); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); Object.DestroyImmediate(threeContainer); }
public void LengthIsZero() { UnityEventListenerMock slicedMock = new UnityEventListenerMock(); subject.Sliced.AddListener(slicedMock.Listen); UnityEventListenerMock remainedMock = new UnityEventListenerMock(); subject.Remained.AddListener(remainedMock.Listen); List <CollisionNotifier.EventData> collisionList = new List <CollisionNotifier.EventData>(); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); oneContainer.name = "one"; collisionList.Add(oneData); GameObject twoContainer; CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer); twoContainer.name = "two"; collisionList.Add(twoData); GameObject threeContainer; CollisionNotifier.EventData threeData = CollisionNotifierHelper.GetEventData(out threeContainer); threeContainer.name = "three"; collisionList.Add(threeData); GameObject fourContainer; CollisionNotifier.EventData fourData = CollisionNotifierHelper.GetEventData(out fourContainer); fourContainer.name = "four"; collisionList.Add(fourData); GameObject fiveContainer; CollisionNotifier.EventData fiveData = CollisionNotifierHelper.GetEventData(out fiveContainer); fiveContainer.name = "five"; collisionList.Add(fiveData); GameObject sixContainer; CollisionNotifier.EventData sixData = CollisionNotifierHelper.GetEventData(out sixContainer); sixContainer.name = "six"; collisionList.Add(sixData); ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData().Set(collisionList); subject.StartIndex = 0; subject.Length = 0; ActiveCollisionsContainer.EventData remainedList; ActiveCollisionsContainer.EventData slicedList = subject.Slice(eventData, out remainedList); Assert.IsTrue(slicedMock.Received); Assert.IsTrue(remainedMock.Received); Assert.AreEqual("", ActiveCollisionsHelper.GetNamesOfActiveCollisions(slicedList)); Assert.AreEqual("one,two,three,four,five,six", ActiveCollisionsHelper.GetNamesOfActiveCollisions(remainedList)); Object.DestroyImmediate(oneContainer); Object.DestroyImmediate(twoContainer); Object.DestroyImmediate(threeContainer); Object.DestroyImmediate(fourContainer); Object.DestroyImmediate(fiveContainer); Object.DestroyImmediate(sixContainer); }