public void globally_set_behaviors_should_be_overridable()
    {
        var instance = MagicFactory.For <ClassA>()
                       .WithBehavior(new DoNotFillBehavior())
                       .Build();

        instance.DateTimeProperty.Should().Be(default);
Exemplo n.º 2
0
 // 工厂系列
 // 简单工厂
 // 静态工厂
 // 工厂方法
 ///产品围度扩展
 // 抽象工厂
 ///产品一族进行扩展
 static void Main(string[] args)
 {
     Factory.AbstractFactory.AbstractFactory af = new MagicFactory();
     af.CreateFood();
     af.CreateVihicle();
     af.CreateWeapon();
 }
Exemplo n.º 3
0
    public void ReadAll(string path)
    {
        Debug.Log(path);
        TextReader tr = new StreamReader(path);
        string     line;

        while ((line = tr.ReadLine()) != null)            //read till end
        {
            string[] columns = line.Split(' ');

            string label = columns[0];
            //int cooldown = Convert.ToInt32(columns[1]);
            int cooldown = 1;
            MagicFactory.AddMagic(label, cooldown);

            List <PointData> points = new List <PointData> ();

            for (int i = 1; i < columns.Length; i += 2)
            {
                float x = float.Parse(columns[i]);
                float z = float.Parse(columns[i + 1]);

                points.Add(new PointData(new UnityEngine.Vector3(x, z, 0), new UnityEngine.Quaternion(), 0.1f, 0.1f, null));
            }

            AddOrUpdate(points, label);
        }
    }
 public void Awake()
 {
     hand = GameObject.FindGameObjectWithTag("hand");
     neck = GameObject.FindGameObjectWithTag("neck");
     head = GameObject.FindGameObjectWithTag("head");
     MagicFactory.AddMagic("throw", 0);
     magic = MagicFactory.GetMagic("throw");
     scale = CalculateDistance();
 }
Exemplo n.º 5
0
        public static IEnumerable <object[]> FactoriesWithDefaultBehavior()
        {
            var customizedBehavior = new FillWithEmptyValuesBehavior();

            return(new List <object[]>
            {
                new object[] { new CustomerFactory(customizedBehavior) },
                new object[] { MagicFactory.For <Customer>().WithBehavior(customizedBehavior) }
            });
        }
Exemplo n.º 6
0
        public static IEnumerable <object[]> FactoriesWithNullableFillingDisabled()
        {
            var customizedBehavior = new FillWithEmptyValuesBehavior(options => options.FillNullables = false);

            return(new List <object[]>
            {
                new object[] { new CustomerFactory(customizedBehavior) },
                new object[] { MagicFactory.For <Customer>().WithBehavior(customizedBehavior) }
            });
        }
Exemplo n.º 7
0
        public void Should_create_instance_with_default_values()
        {
            var factory = MagicFactory.For <Person>();

            var person = factory.Build();

            person.FirstName.Should().BeNull();
            person.LastName.Should().BeNull();
            person.Age.Should().Be(0);
        }
            public static IEnumerable <object[]> FactoriesWithDefaultBehavior()
            {
                var behavior = new FillWithSequentialValuesBehavior();

                return(new List <object[]>
                {
                    new object[] { new CustomerFactory(behavior) },
                    new object[] { MagicFactory.For <Customer>().WithBehavior(behavior) }
                });
            }
Exemplo n.º 9
0
        public void Should_produce_an_instance_using_custom_constructor()
        {
            var product = MagicFactory.For <Product>()
                          .UsingConstructor(() => new Product("MAG-7", "Shotgun"))
                          .With(x => x.Description = "South Africa, 1995")
                          .Build();

            product.Name.Should().Be("MAG-7");
            product.Category.Should().Be("Shotgun");
            product.Description.Should().Be("South Africa, 1995");
        }
 public void Awake()
 {
     skeletonController = FindObjectOfType(typeof(RUISSkeletonController)) as RUISSkeletonController;
     skeletonManager    = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;
     hand = GameObject.FindGameObjectWithTag("hand");
     neck = GameObject.FindGameObjectWithTag("neck");
     head = GameObject.FindGameObjectWithTag("head");
     MagicFactory.AddMagic("throw", 0);
     magic = MagicFactory.GetMagic("throw");
     scale = CalculateDistance();
 }
    public void globally_set_behaviors_should_be_used_in_new_factories()
    {
        var instances = MagicFactory.For <ClassA>().Many(2).Build().ToArray();

        instances[0].DateTimeProperty.Should().Be(2.September(2020));
        instances[0].NullableDateTimeProperty.Should().BeNull("FillNullables option is set to false");
        instances[0].B.Should().BeNull("Recursive option is set to false");
        instances[1].DateTimeProperty.Should().Be(2.September(2020).At(1.Hours()));
        instances[1].NullableDateTimeProperty.Should().BeNull("FillNullables option is set to false");
        instances[1].B.Should().BeNull("Recursive option is set to false");
    }
    public void Update()
    {
        UpdatePoints();

        if (!gestureEnabled)
        {
            return;
        }

        if (!gestureStarted)
        {
            ClearPoints();
            cnt = 0;

            float dist = CalculateDistance();

            if (dist < distanceTreshold)
            {
                gestureStarted = true;
            }
        }
        else
        {
            cnt++;

            if (cnt >= 60)
            {
                gestureStarted = false;
            }

            float distance = CalculateDistance();
            //Debug.Log (distance + " distnace now!");
            //Debug.Log (scale + " Scale now");
            if (distance >= scale - requiredConfidence && distance <= scale + requiredConfidence)
            {
                startCnt       = true;
                gestureStarted = false;
            }
        }

        if (startCnt)
        {
            cnt2++;
            if (cnt2 == 5)
            {
                cnt2     = 0;
                startCnt = false;
                Magic magic = MagicFactory.GetMagic("throw");
                magic.TryActivate();
            }
        }
    }
Exemplo n.º 13
0
    public void should_execute_callbacks_in_order()
    {
        string shipNameBefore = null;
        string shipNameAfter  = null;

        MagicFactory.For <Ship>()
        .Do(x => shipNameBefore = x.Name)
        .With(x => x.Name       = "Mary")
        .Do(x => shipNameAfter  = x.Name)
        .Build();

        shipNameBefore.Should().BeNull();
        shipNameAfter.Should().Be("Mary");
    }
Exemplo n.º 14
0
    public void should_execute_callback_through_ICustomizeOneBuildOne()
    {
        string shipName = null;

        Action <Ship> saveShipName           = ship => shipName = ship.Name;
        ICustomizeOneBuildOne <Ship> factory = MagicFactory.For <Ship>()
                                               .With(x => x.Name = "Mary");

        factory
        .Do(saveShipName)
        .Build();

        shipName.Should().Be("Mary");
    }
Exemplo n.º 15
0
        public BaseMagic GetInstantiate(Vector3 position)
        {
            var newMagic = MagicFactory.GetInstantiate(MagicName);

            if (newMagic == null)
            {
                return(newMagic);
            }

            newMagic.transform.position = position;
            newMagic.tag = MagicTag;
            newMagic.SetMagicData(this);
            return(newMagic);
        }
Exemplo n.º 16
0
        public void Should_allow_customization()
        {
            var factory = MagicFactory.For <Person>();

            var person = factory
                         .With(x => x.FirstName = "Martha")
                         .With(x => x.LastName  = "Kent")
                         .With(x => x.Age       = 60)
                         .Build();

            person.FirstName.Should().Be("Martha");
            person.LastName.Should().Be("Kent");
            person.Age.Should().Be(60);
        }
Exemplo n.º 17
0
        public void Should_produce_multiple_instances_using_custom_constructor()
        {
            var products = MagicFactory.For <Product>()
                           .UsingConstructor(() => new Product("MAG-7", "Shotgun"))
                           .Many(2)
                           .Plus(2)
                           .Build()
                           .ToArray();

            products.Should().HaveCount(4);
            foreach (var product in products)
            {
                product.Name.Should().Be("MAG-7");
                product.Category.Should().Be("Shotgun");
            }
        }
            public static IEnumerable <object[]> FactoriesWithRecursionDisabled()
            {
                var customizedBehavior = new FillWithSequentialValuesBehavior(options =>
                {
                    options.Recursive = false;
                });

                return(new List <object[]>
                {
                    new object[] { new CustomerFactory(customizedBehavior) },
                    new object[] { MagicFactory.For <Customer>()
                                   .WithBehavior(new FillWithSequentialValuesBehavior(options =>
                                                                                      options.Recursive = false)
                                                 ) }
                });
            }
            public static IEnumerable <object[]> FactoriesWithDefaultBehavior()
            {
                var customizedBehavior = new FillWithSequentialValuesBehavior(options =>
                {
                    options.DateTimeOptions = new DateTimeSequenceOptions
                    {
                        StartDate          = 25.December(2020).At(22.Hours()),
                        DateTimeIncrements = DateTimeIncrements.Hours
                    };
                });

                return(new List <object[]>
                {
                    new object[] { new CustomerFactory(customizedBehavior) },
                    new object[] { MagicFactory.For <Customer>().WithBehavior(customizedBehavior) }
                });
            }
Exemplo n.º 20
0
    void Update()
    {
        //Debug.Log (System.Threading.Thread.CurrentThread.ManagedThreadId);
        //Debug.Log (ruisInput.points [ruisInput.points.Count - 1].position);
        gestureState = false;

        if (ruisInput.points.Count > 10 && Mathf.Abs(ruisInput.AverageCord(3) - head.transform.position.z) > distanceTreshold)
        {
            //NOT SURE IF WE NEED TO check in each iteration. maybe once in some number
            string recognized = dtwGestures.Recognize(ruisInput.points, colliders);
            if (!recognized.Contains("UNKNOWN"))
            {
                Magic magic = MagicFactory.GetMagic(recognized);
                magic.TryActivate();
                gestureState = true;
            }
        }
    }
Exemplo n.º 21
0
    public void should_execute_callback_through_ICustomizeManyBuildMany()
    {
        string shipName = null;
        var    counter  = 0;

        Action <Ship> saveShipName = ship =>
        {
            shipName = ship.Name;
            counter++;
        };
        ICustomizeManyBuildMany <Ship> factory = MagicFactory.For <Ship>()
                                                 .Many(2)
                                                 .With(x => x.Name = "Mary");

        factory
        .Do(saveShipName)
        .Build()
        .ToArray();

        shipName.Should().Be("Mary");
        counter.Should().Be(2);
    }
Exemplo n.º 22
0
    public void should_execute_callback_through_ICustomizeOneBuildManyWithNavigation()
    {
        string shipName = null;
        var    counter  = 0;

        Action <Ship> saveShipName = ship =>
        {
            shipName = ship.Name;
            counter++;
        };
        ICustomizeOneBuildManyWithNavigation <Ship> factory = MagicFactory.For <Ship>()
                                                              .One()
                                                              .PlusOne()
                                                              .With(x => x.Name = "Mary");

        factory
        .Do(saveShipName)
        .Build()
        .ToArray();

        shipName.Should().Be("Mary");
        counter.Should().Be(1, "the first generator node does not configure a configure");
    }