示例#1
0
        public IEnumerator KeepUnlockedAtEndPropertyIsUnlockedAfterFinishingStep()
        {
            // Given a transition with a condition referencing a scene object with a lockable property
            // that should not be locked in the end of a step.
            ISceneObject         o1       = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>();

            LockableReferencingConditionMock doNotLockAtEndOfStepCondition = new LockableReferencingConditionMock();

            doNotLockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            doNotLockAtEndOfStepCondition.LockableProperties        = new[] { new LockablePropertyData(property, false) };

            Step step2 = new BasicStepBuilder("step2").Build();

            Step step = new BasicStepBuilder("step").AddCondition(doNotLockAtEndOfStepCondition).Build();

            step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2;

            // When executing the locking routine and completing the step.
            LockHandling.Unlock(step.Data, new List <LockablePropertyData>());
            step.Data.Transitions.Data.Transitions.First().Autocomplete();
            step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true;
            LockHandling.Lock(step.Data, new List <LockablePropertyData>());

            // Then the property is not locked in the end.
            Assert.IsFalse(property.IsLocked);

            yield return(null);
        }
示例#2
0
        public IEnumerator SecondPropertyStaysLocked()
        {
            // Given two steps and two scene objects with each one lockable property
            // where only the first property is referenced in the first step.
            ISceneObject         o1        = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock property1 = o1.GameObject.AddComponent <LockablePropertyMock>();

            ISceneObject         o2        = TestingUtils.CreateSceneObject("o2");
            LockablePropertyMock property2 = o2.GameObject.AddComponent <LockablePropertyMock>();

            LockableReferencingConditionMock doNotLockAtEndOfStepCondition = new LockableReferencingConditionMock();

            doNotLockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            doNotLockAtEndOfStepCondition.LockableProperties        = new[] { new LockablePropertyData(property1, false) };

            Step step2 = new BasicStepBuilder("step2").Build();
            Step step  = new BasicStepBuilder("step")
                         .AddCondition(doNotLockAtEndOfStepCondition)
                         .Build();

            property1.SetLocked(true);
            property2.SetLocked(true);

            step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2;

            // When executing the locking routine in the first step.
            LockHandling.Unlock(step.Data, new List <LockablePropertyData>());

            // Then property 2 is locked during the first step.
            Assert.IsTrue(property2.IsLocked);

            yield return(null);
        }
示例#3
0
        public IEnumerator DependencyGetsLocked()
        {
            // Given a scene object with one lockable property with dependency.
            ISceneObject         o1         = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock dependency = o1.GameObject.AddComponent <LockablePropertyMock>();
            LockablePropertyMockWithDependency propertyWithDependency = o1.GameObject.AddComponent <LockablePropertyMockWithDependency>();

            Step step2 = new BasicStepBuilder("step").Build();
            Step step  = new BasicStepBuilder("step").AddCondition(new EndlessConditionMock()).Build();

            step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2;

            dependency.SetLocked(true);
            propertyWithDependency.SetLocked(true);

            // When we manually unlock the property for one step.
            LockHandling.Unlock(step.Data, new List <LockablePropertyData> {
                new LockablePropertyData(propertyWithDependency)
            });
            step.Data.Transitions.Data.Transitions.First().Autocomplete();
            step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true;
            LockHandling.Lock(step.Data, new List <LockablePropertyData> {
                new LockablePropertyData(propertyWithDependency)
            });

            // Then after the step the dependent property is also locked again.
            Assert.IsTrue(dependency.IsLocked);

            yield return(null);
        }
示例#4
0
        public IEnumerator UnlockedAfterManualUnlockStarted()
        {
            // Given a scene object with a lockable property which is not referenced by any condition.
            ISceneObject         o1       = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>();

            EndlessConditionMock condition = new EndlessConditionMock();

            Step step2 = new BasicStepBuilder("step").AddCondition(new EndlessConditionMock()).Build();
            Step step  = new BasicStepBuilder("step").AddCondition(condition).Build();

            step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2;

            property.SetLocked(true);

            // When we include the property into the manualUnlocked list of the UnlockPropertiesForStepData method.
            LockHandling.Unlock(step.Data, new List <LockablePropertyData> {
                new LockablePropertyData(property)
            });

            // Then the property is not locked.
            Assert.IsFalse(property.IsLocked);

            yield return(null);
        }
示例#5
0
        public IEnumerator OtherPropertyLockedAfterManualUnlockFinished()
        {
            // Given a scene object with two independent lockable properties which are not referenced by any condition.
            ISceneObject         o1        = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock property  = o1.GameObject.AddComponent <LockablePropertyMock>();
            LockablePropertyMock property2 = o1.GameObject.AddComponent <LockablePropertyMock>();

            EndlessConditionMock condition = new EndlessConditionMock();

            Step step2 = new BasicStepBuilder("step").AddCondition(new EndlessConditionMock()).Build();
            Step step  = new BasicStepBuilder("step").AddCondition(condition).Build();

            step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2;

            property.SetLocked(true);
            property2.SetLocked(true);

            // When we manually unlock one property for one step.
            LockHandling.Unlock(step.Data, new List <LockablePropertyData>());
            step.Data.Transitions.Data.Transitions.First().Autocomplete();
            step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true;
            LockHandling.Lock(step.Data, new List <LockablePropertyData> {
                new LockablePropertyData(property)
            });

            // Then the other property stays locked after the step was completed.
            Assert.IsTrue(property2.IsLocked);

            yield return(null);
        }
示例#6
0
        public IEnumerator SamePropertyInSecondStepStaysUnlocked()
        {
            // Given a scene object with a lockable property which is referenced in the transitions of the first and second step
            // and should normally lock at the end of a step.
            ISceneObject         o1       = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>();

            LockableReferencingConditionMock lockAtEndOfStepCondition = new LockableReferencingConditionMock();

            lockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            lockAtEndOfStepCondition.LockableProperties        = new[] { new LockablePropertyData(property, true) };

            Step step2 = new BasicStepBuilder("step2").AddCondition(lockAtEndOfStepCondition).Build();

            Step step = new BasicStepBuilder("step").AddCondition(lockAtEndOfStepCondition).Build();

            step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2;

            // When executing the locking routine in the first step.
            LockHandling.Unlock(step.Data, new List <LockablePropertyData>());
            step.Data.Transitions.Data.Transitions.First().Autocomplete();
            step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true;
            LockHandling.Lock(step.Data, new List <LockablePropertyData>());

            // Then the property is not locked at the end of the first step because it is needed in the second step.
            Assert.IsFalse(property.IsLocked);

            yield return(null);
        }
示例#7
0
        public IEnumerator GetLockablePropertiesObjectInMultipleConditions()
        {
            // Given a scene object with one lockable property and one non-lockable property used by two conditions in a transition.
            ISceneObject         o1       = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>();

            o1.GameObject.AddComponent <PropertyMock>();

            LockableReferencingConditionMock condition1 = new LockableReferencingConditionMock();

            condition1.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            condition1.LockableProperties        = new[] { new LockablePropertyData(property, true) };

            LockableReferencingConditionMock condition2 = new LockableReferencingConditionMock();

            condition2.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            condition2.LockableProperties        = new[] { new LockablePropertyData(property, false) };

            Step step2 = new BasicStepBuilder("step2").Build();
            Step step  = new BasicStepBuilder("step").AddCondition(condition1).AddCondition(condition2).Build();

            Transition transition = (Transition)step.Data.Transitions.Data.Transitions[0];

            transition.Data.TargetStep = step2;

            // When counting the lockable properties in the transition.
            // Then there is exactly one lockable property.
            Assert.IsTrue(transition.GetLockableProperties().Count() == 1);

            yield return(null);
        }
示例#8
0
        public IEnumerator GetLockablePropertiesMultipleObjectsAndConditions()
        {
            // Given three scene objects,
            // one of them with one lockable property and one non-lockable property,
            // one of them with only one non-lockable property,
            // and one of them with only one lockable property,
            // used by three different conditions in a transition.
            ISceneObject         o1       = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>();

            o1.GameObject.AddComponent <PropertyMock>();

            ISceneObject o2 = TestingUtils.CreateSceneObject("o2");

            o2.GameObject.AddComponent <PropertyMock>();

            ISceneObject         o3        = TestingUtils.CreateSceneObject("o3");
            LockablePropertyMock property2 = o2.GameObject.AddComponent <LockablePropertyMock>();

            LockableReferencingConditionMock condition1 = new LockableReferencingConditionMock();

            condition1.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            condition1.LockableProperties        = new[] { new LockablePropertyData(property, true) };

            ReferencingConditionMock condition2 = new ReferencingConditionMock();

            condition2.Data.PropertyMock = new ScenePropertyReference <PropertyMock>(o2.UniqueName);

            LockableReferencingConditionMock condition3 = new LockableReferencingConditionMock();

            condition3.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o3.UniqueName);
            condition3.LockableProperties        = new[] { new LockablePropertyData(property2, true) };

            Step step2 = new BasicStepBuilder("step2").Build();
            Step step  = new BasicStepBuilder("step")
                         .AddCondition(condition1)
                         .AddCondition(condition2)
                         .AddCondition(condition3)
                         .Build();
            Transition transition = (Transition)step.Data.Transitions.Data.Transitions[0];

            transition.Data.TargetStep = step2;

            // When counting the lockable properties in the transition.
            // Then there are exactly two lockable properties.
            Assert.IsTrue(transition.GetLockableProperties().Count() == 2);

            yield return(null);
        }
示例#9
0
        public IEnumerator ObjectInConditionIsInAutoUnlockList()
        {
            // Given a step with a condition with a LockableProperty
            ISceneObject                     o1 = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock             lockableProperty = o1.GameObject.AddComponent <LockablePropertyMock>();
            LockableReferencingConditionMock lockCondition    = new LockableReferencingConditionMock();

            lockCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            Step step = new BasicStepBuilder("step").AddCondition(lockCondition).Build();

            // When we create a collection referencing this step
            LockableObjectsCollection collection = new LockableObjectsCollection(step.Data);

            // Then the lockable property is in the AutoUnlockList of the collection
            Assert.IsTrue(collection.IsInAutoUnlockList(lockableProperty));

            yield return(null);
        }
示例#10
0
        public IEnumerator SecondTransitionIsLocked()
        {
            // Given a step with two different transitions,
            // each of them having an own condition with a lockable property which should not be locked at the end of a step.
            ISceneObject         o1       = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>();

            ISceneObject         o2        = TestingUtils.CreateSceneObject("o2");
            LockablePropertyMock property2 = o2.GameObject.AddComponent <LockablePropertyMock>();

            LockableReferencingConditionMock doNotLockAtEndOfStepCondition1 = new LockableReferencingConditionMock();

            doNotLockAtEndOfStepCondition1.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            doNotLockAtEndOfStepCondition1.LockableProperties        = new[] { new LockablePropertyData(property, false) };

            LockableReferencingConditionMock doNotLockAtEndOfStepCondition2 = new LockableReferencingConditionMock();

            doNotLockAtEndOfStepCondition2.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o2.UniqueName);
            doNotLockAtEndOfStepCondition2.LockableProperties        = new[] { new LockablePropertyData(property2, false) };

            Step step2 = new BasicStepBuilder("step2").AddCondition(doNotLockAtEndOfStepCondition1).Build();

            Step step = new BasicStepBuilder("step").AddCondition(doNotLockAtEndOfStepCondition1).Build();

            step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2;
            step.Data.Transitions.Data.Transitions.Add(new Transition());
            step.Data.Transitions.Data.Transitions[1].Data.Conditions.Add(doNotLockAtEndOfStepCondition2);

            // When completing only the first transition.
            LockHandling.Unlock(step.Data, new List <LockablePropertyData>());
            step.Data.Transitions.Data.Transitions.First().Autocomplete();
            step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true;
            LockHandling.Lock(step.Data, new List <LockablePropertyData>());

            // Then the lockable property of the second transition is locked,
            // even though lock at the end of step is set to false.
            Assert.IsTrue(property2.IsLocked);

            yield return(null);
        }
示例#11
0
        public IEnumerator SecondPropertyGetsLockedAfterNotBeingNeededAnymore()
        {
            // Given two steps and two scene objects with each one lockable property
            // and property 2 (lock at the end of step = true) is referenced only in the first step,
            // whereas property 1 (lock at the end of step = false) is referenced in both steps.
            ISceneObject         o1 = TestingUtils.CreateSceneObject("o1");
            LockablePropertyMock DoNotLockAtEndOfStep = o1.GameObject.AddComponent <LockablePropertyMock>();

            ISceneObject         o2 = TestingUtils.CreateSceneObject("o2");
            LockablePropertyMock lockAtEndOfStep = o2.GameObject.AddComponent <LockablePropertyMock>();

            LockableReferencingConditionMock doNotLockAtEndOfStepCondition = new LockableReferencingConditionMock();

            doNotLockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName);
            doNotLockAtEndOfStepCondition.LockableProperties        = new[] { new LockablePropertyData(DoNotLockAtEndOfStep, false) };

            LockableReferencingConditionMock lockAtEndOfStepCondition = new LockableReferencingConditionMock();

            lockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o2.UniqueName);
            lockAtEndOfStepCondition.LockableProperties        = new[] { new LockablePropertyData(lockAtEndOfStep, true) };

            Step step2 = new BasicStepBuilder("step2").AddCondition(doNotLockAtEndOfStepCondition).Build();
            Step step  = new BasicStepBuilder("step")
                         .AddCondition(doNotLockAtEndOfStepCondition)
                         .AddCondition(lockAtEndOfStepCondition)
                         .Build();

            step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2;

            // When executing the locking routine in the first step.
            LockHandling.Unlock(step.Data, new List <LockablePropertyData>());
            step.Data.Transitions.Data.Transitions.First().Autocomplete();
            step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true;
            LockHandling.Lock(step.Data, new List <LockablePropertyData>());

            // Then property 2 is locked in the end of the first step.
            Assert.IsTrue(lockAtEndOfStep.IsLocked);

            yield return(null);
        }