Exemplo n.º 1
0
        public void NonGenericLemmingUniqueNameShouldBeEqualToName()
        {
            var lemming = Lemming.From(typeof(Service));

            Assert.AreEqual("NailsFramework.Tests.IoC.Lemmings.Service", lemming.Name);
            Assert.AreEqual("NailsFramework.Tests.IoC.Lemmings.Service", lemming.UniqueName);
        }
Exemplo n.º 2
0
 public MoveToCliffState(Lemming lemming, HexagonMap.MapPosition targetPosition)
 {
     this.lemming        = lemming;
     this.targetPosition = GameController.Instance.map.GetRandomPositionInCliffPosition(targetPosition);
     lemming.randomPositionOfCurrentTargetPosition = this.targetPosition;
     SetRandomSpeed(lemming);
 }
Exemplo n.º 3
0
        public void GenericLemmings()
        {
            objectFactory.Configure(new[] { Lemming.From(typeof(GenericService <>)) }, new Injection[0]);
            var service = objectFactory.GetObject <GenericService <string> >();

            Assert.IsNotNull(service);
        }
Exemplo n.º 4
0
    private bool ProcessSpawners(LevelMoment mom)
    {
        bool result = false;

        List <Spawner> spawners = new List <Spawner>();

        spawners.AddRange(mom.spawners);

        foreach (Spawner spawn in spawners)
        {
            spawn.age--;

            if (spawn.age == 0)
            {
                mom.spawners.Remove(spawn);
            }
            if (spawn.age % 2 != 0)
            {
                continue;
            }

            Lemming lem = spawn.MakeLemming();
            if (mom.IsFree(lem.position))
            {
                mom.lemmings.Add(lem);
            }
        }

        return(result);
    }
Exemplo n.º 5
0
        public void ShouldBeAbleToAddGenericLemmingsOfDifferentTypes()
        {
            var serviceLemming = Lemming.From <ServiceWithGenericDependency>();

            serviceLemming.Injections.OfType <ReferenceInjection>().Single().ReferencedLemming = "Test1";

            var anotherServiceLemming = Lemming.From <AnotherServiceWithGenericDependency>();

            anotherServiceLemming.Injections.OfType <ReferenceInjection>().Single().ReferencedLemming = "Test2";

            var test1 = Lemming.From(typeof(GenericService <>));

            test1.Name = "Test1";

            var test2 = Lemming.From(typeof(GenericService <>));

            test2.Name = "Test2";

            var lemmings = new[] { serviceLemming, anotherServiceLemming, test1, test2 };

            objectFactory.Configure(lemmings, new Injection[0]);

            var service = objectFactory.GetObject <ServiceWithGenericDependency>();

            Assert.IsNotNull(service);
            Assert.IsNotNull(service.GenericDependency);

            var service2 = objectFactory.GetObject <ServiceWithGenericDependency>();

            Assert.IsNotNull(service2);
            Assert.IsNotNull(service2.GenericDependency);
        }
Exemplo n.º 6
0
    private void PlaceLemming(char key, Lemming lem)
    {
        GameObject newObject = GetObject(key);

        if (newObject == null)
        {
            return;
        }

        Vector3Int pos = lem.position;

        newObject.SetActive(true);

        newObject.transform.localPosition = new Vector3(pos.x, pos.y, pos.z);

        Vector3 angles = new Vector3(0f, 90f, 0f);
        float   turn   = 0f;

        if (lem.direction.z == -1)
        {
            turn = 1;
        }
        else if (lem.direction.x == -1)
        {
            turn = 2;
        }
        else if (lem.direction.z == 1)
        {
            turn = 3;
        }

        newObject.transform.localEulerAngles = angles * turn;
    }
Exemplo n.º 7
0
        public void ShouldAddInjectionsDueAttributes()
        {
            var lemming = Lemming.From(typeof(Service));

            Assert.AreEqual(1, lemming.Injections.Count());
            Assert.AreEqual("Dependency", lemming.Injections.Single().Property.Name);
        }
 /// <summary>
 /// Inflicts the block's effects on a lemming.
 /// </summary>
 /// <param name="lemming">The lemming who triggered the block.</param>
 /// <param name="hit">Collision information.</param>
 public override void AffectLemming(Lemming lemming, RaycastHit hit = new RaycastHit())
 {
     if (lemming.CanJump())
     {
         lemming.body.AddForce((transform.forward + Vector3.up) * force);
     }
 }
Exemplo n.º 9
0
        public void SingletonsShouldBeSingletonsWhenGettedFromDifferentTypes()
        {
            objectFactory.Configure(new[] { Lemming.From <ServiceDependency>() }, new Injection[0]);
            var o1 = objectFactory.GetObject <ServiceDependency>();
            var o2 = objectFactory.GetObject <IServiceDependency>();

            Assert.AreEqual(o1, o2);
        }
Exemplo n.º 10
0
    private void SetRandomSpeed(Lemming lemming)
    {
        const float RANDOM_PERCENTAGE_LIMIT = 20;
        var         maximumSpeed            = lemming.defaultSpeed * (1 + RANDOM_PERCENTAGE_LIMIT / 100);
        var         minimumSpeed            = lemming.defaultSpeed * (1 - RANDOM_PERCENTAGE_LIMIT / 100);

        lemming.speed = Random.Range(minimumSpeed, maximumSpeed);
    }
Exemplo n.º 11
0
        public void InstanceInjection()
        {
            objectFactory.Configure(new[] { Lemming.From <ServiceDependency>() }, new Injection[0]);

            var instance = new NonLemmingWithInjections();

            objectFactory.Inject(instance);
            Assert.IsNotNull(instance.Dependency);
            Assert.AreEqual("test123", instance.Value);
        }
Exemplo n.º 12
0
    public override void Move(LevelMoment next, LevelMoment prev, Lemming lemming, GameBlock block)
    {
        lemming.position = block.pos;

        LevelData.Instance.WormHole(next);
        next.timeTraveler = lemming;
        next.lemmings.Remove(lemming);
        next.phasedLemmings.Remove(lemming);
        next.fail--;
    }
Exemplo n.º 13
0
        public void NonSingletonsShouldNotBeSingletons()
        {
            var lemming = Lemming.From <ServiceDependency>();

            lemming.Singleton = false;
            objectFactory.Configure(new[] { lemming }, new Injection[0]);
            var o1 = objectFactory.GetObject <ServiceDependency>();
            var o2 = objectFactory.GetObject <ServiceDependency>();

            Assert.AreNotEqual(o1, o2);
        }
Exemplo n.º 14
0
        public void ShouldSetInjectionNamesWithAttributes()
        {
            var lemming = Lemming.From(typeof(NamedLemming));

            Assert.AreEqual(lemming.Injections.Count(), 1);

            var reference = (ReferenceInjection)lemming.Injections.Single();

            Assert.AreEqual("Dependency", reference.Property.Name);
            Assert.AreEqual("lalala", reference.ReferencedLemming);
        }
Exemplo n.º 15
0
        public void ConfigurationInjectionsShouldHaveValueAsAppSetingsWithLemmingPropertyAsKeyByDefault()
        {
            var lemming = Lemming.From(typeof(LemmingWithValuesFromConfiguration));

            Assert.AreEqual(lemming.Injections.Count(), 1);

            var reference = (ConfigurationInjection)lemming.Injections.Single();

            Assert.AreEqual("ConfigurationValue", reference.Property.Name);
            Assert.AreEqual("testConfigurationValueForDefaultKey", reference.Value);
        }
Exemplo n.º 16
0
    public Lemming MakeLemming()
    {
        Lemming result = new Lemming();

        result.age       = 25;
        result.direction = direction;
        result.position  = position + Vector3Int.down;
        result.phase     = phase;

        return(result);
    }
Exemplo n.º 17
0
        public void ConfigurationInjectionsOverridenKey()
        {
            var lemming = Lemming.From(typeof(LemmingWithValuesFromConfigurationWithOverridenKey));

            Assert.AreEqual(lemming.Injections.Count(), 1);

            var value = (ConfigurationInjection)lemming.Injections.Single();

            Assert.AreEqual("ConfigurationValue", value.Property.Name);
            Assert.AreEqual("test123", value.Value);
        }
Exemplo n.º 18
0
        public void GetFromInterface()
        {
            objectFactory.Configure(new[]
            {
                Lemming.From(typeof(Service)),
                Lemming.From(typeof(ServiceDependency))
            }, new Injection[0]);

            var service = objectFactory.GetObject <IService>();

            Assert.IsNotNull(service);
        }
Exemplo n.º 19
0
        public void GetFromTypeGeneric()
        {
            objectFactory.Configure(new[]
            {
                Lemming.From(typeof(ServiceWithGenericDependency)),
                Lemming.From(typeof(GenericService <>))
            }, new Injection[0]);

            var service = objectFactory.GetObject <GenericService <string> >();

            Assert.IsNotNull(service);
        }
Exemplo n.º 20
0
        public void ConfigurationInjectionForNamedLemmingDefaultKey()
        {
            var lemming = Lemming.From(typeof(LemmingWithValuesFromConfiguration));

            lemming.Name = "Bar";
            Assert.AreEqual(lemming.Injections.Count(), 1);

            var reference = (ConfigurationInjection)lemming.Injections.Single();

            Assert.AreEqual("ConfigurationValue", reference.Property.Name);
            Assert.AreEqual("bar-value", reference.Value);
        }
Exemplo n.º 21
0
        public void ConfigurationInjectionForGenericNamedLemmingDefaultNonGenericKey()
        {
            var lemming = Lemming.From(typeof(GenericLemmingWithValuesFromConfiguration <string>));

            lemming.Name = "GenericLemming2";
            Assert.AreEqual(lemming.Injections.Count(), 1);

            var reference = (ConfigurationInjection)lemming.Injections.Single();

            Assert.AreEqual("ConfigurationValue", reference.Property.Name);
            Assert.AreEqual("generic2-value", reference.Value);
        }
Exemplo n.º 22
0
        public void GetFromTypeNonGeneric()
        {
            objectFactory.Configure(new[]
            {
                Lemming.From(typeof(Service)),
                Lemming.From(typeof(ServiceDependency))
            }, new Injection[0]);

            var service = objectFactory.GetObject(typeof(Service));

            Assert.IsNotNull(service);
        }
Exemplo n.º 23
0
        public void GetGenericByNameAndTypeParameters()
        {
            objectFactory.Configure(new[]
            {
                Lemming.From(typeof(GenericService <>))
            }, new Injection[0]);

            var service = objectFactory.GetGenericObject <string>("NailsFramework.Tests.IoC.Lemmings.GenericService");

            Assert.IsNotNull(service);
            Assert.IsInstanceOf <IGenericService <string> >(service);
        }
Exemplo n.º 24
0
        public void ReferenceInjections()
        {
            objectFactory.Configure(new[]
            {
                Lemming.From(typeof(Service)),
                Lemming.From(typeof(ServiceDependency))
            }, new Injection[0]);

            var service = objectFactory.GetObject <Service>();

            Assert.IsInstanceOf <ServiceDependency>(service.Dependency);
        }
Exemplo n.º 25
0
        public void SingletonsShouldBeSingletonsWhenGettedFromTypeAndName()
        {
            var lemming = Lemming.From <ServiceDependency>();

            lemming.Name = "Test";
            objectFactory.Configure(new[] { lemming }, new Injection[0]);

            var o1 = objectFactory.GetObject <ServiceDependency>();
            var o2 = objectFactory.GetObject("Test");

            Assert.AreEqual(o1, o2);
        }
Exemplo n.º 26
0
        public void GenericReferenceInjections()
        {
            objectFactory.Configure(new[]
            {
                Lemming.From(typeof(GenericService <>)),
                Lemming.From(typeof(ServiceWithGenericDependency))
            }, new Injection[0]);

            var service = objectFactory.GetObject <ServiceWithGenericDependency>();

            Assert.IsInstanceOf <GenericService <string> >(service.GenericDependency);
        }
Exemplo n.º 27
0
    public Lemming DeepCopy()
    {
        Lemming result = new Lemming
        {
            age       = this.age,
            phase     = this.phase,
            direction = this.direction,
            position  = this.position
        };

        return(result);
    }
Exemplo n.º 28
0
        private void InjectTestProperties()
        {
            var lemming = Lemming.From(GetType());

            foreach (var injection in lemming.Injections)
            {
                if (!configured || !lemming.Singleton)
                {
                    injection.Accept(this);
                }
            }
        }
Exemplo n.º 29
0
    public override void Move(LevelMoment next, LevelMoment prev, Lemming lemming, GameBlock block)
    {
        Vector3Int i = block.pos;

        if (fade > '0')
        {
            next.level[i.x, i.y, i.z] = fade;
        }
        else
        {
            next.level[i.x, i.y, i.z] = GameBoardCubeDictionary.OPEN_CUBE;
        }
    }
        /// <summary>
        /// Inflicts the block's effects on a lemming.
        /// </summary>
        /// <param name="lemming">The lemming who triggered the block.</param>
        /// <param name="hit">Collision information.</param>
        public override void AffectLemming(Lemming lemming, RaycastHit hit = new RaycastHit())
        {
            Vector3 xz = VectorUtil.SetY(transform.forward, 0);

            xz.Normalize();

            // Turns the lemming around if it would be walking into the block.
            if (VectorUtil.ApproximatelyEqual(lemming.transform.forward, xz))
            {
                xz = -xz;
            }

            lemming.transform.forward = xz;
        }