Пример #1
0
        public IEnumerator ResetLifetimeTestPass()
        {
            DateTime modificationTime = DateTime.UtcNow;
            TimeSpan elapsedTime      = new TimeSpan(0);
            float    lifetime         = 2;

            IModifiable                 modifiable     = Substitute.For <IModifiable>();
            Modifier <IModifiable>      simpleModifier = Substitute.For <Modifier <IModifiable> >();
            AliveModifier <IModifiable> aliveModifier  = new AliveModifier <IModifiable>(simpleModifier, lifetime);

            //Setup When...Do for modifier
            simpleModifier.
            When(modifier => modifier.Modify(modifiable)).
            Do(modifier => modifiable.OnModificationApplied(simpleModifier));

            simpleModifier.
            When(modifier => modifier.Revert(modifiable)).
            Do(modifier => modifiable.OnModificationReverted(simpleModifier));

            //Setup When...Do for modifiable
            modifiable.
            When(spyModifiable => spyModifiable.OnModificationApplied(simpleModifier)).
            Do(spyModifiable => modificationTime = DateTime.UtcNow);

            modifiable.
            When(spyModifiable => spyModifiable.OnModificationReverted(simpleModifier)).
            Do(spyModifiable => elapsedTime = DateTime.UtcNow.Subtract(modificationTime));

            aliveModifier.Modify(modifiable);

            yield return(new WaitForSeconds(lifetime - 1));

            aliveModifier.Reset();
            modificationTime = DateTime.UtcNow;

            yield return(new WaitForSeconds(lifetime - 1));

            Assert.Zero(elapsedTime.Seconds);

            yield return(new WaitForSeconds(lifetime));

            Assert.NotZero(elapsedTime.Seconds);

            Assert.Greater(elapsedTime.TotalSeconds, lifetime);
        }
Пример #2
0
        public IEnumerator SimpleLifetimeTestPass()
        {
            DateTime modificationTime = DateTime.UtcNow;
            TimeSpan elapsedTime      = new TimeSpan(0);
            float    lifetime         = 2;

            IModifiable                 modifiable     = Substitute.For <IModifiable>();
            Modifier <IModifiable>      simpleModifier = Substitute.For <Modifier <IModifiable> >();
            AliveModifier <IModifiable> aliveModifier  = new AliveModifier <IModifiable>(simpleModifier, lifetime);

            //Setup When...Do for modifier
            simpleModifier.
            When(modifier => modifier.Modify(modifiable)).
            Do(modifier => modifiable.OnModificationApplied(simpleModifier));

            simpleModifier.
            When(modifier => modifier.Revert(modifiable)).
            Do(modifier => modifiable.OnModificationReverted(simpleModifier));

            //Setup When...Do for modifiable
            modifiable.
            When(spyModifiable => spyModifiable.OnModificationApplied(simpleModifier)).
            Do(spyModifiable => modificationTime = DateTime.UtcNow);

            modifiable.
            When(spyModifiable => spyModifiable.OnModificationReverted(simpleModifier)).
            Do(spyModifiable => elapsedTime = DateTime.UtcNow.Subtract(modificationTime));

            aliveModifier.Modify(modifiable);

            yield return(new WaitForSeconds(lifetime + 1));

            float timeDiff = Mathf.Abs(lifetime - (float)elapsedTime.TotalSeconds);

            Assert.IsTrue(timeDiff < 0.1f);
        }