示例#1
0
        public void Derivation()
        {
            var population = new Default.DynamicPopulation(
                new DynamicMeta(new Pluralizer()),
                v =>
            {
                v.AddUnit <Person, string>("FirstName");
                v.AddUnit <Person, string>("LastName");
                v.AddUnit <Person, string>("FullName");
                v.AddUnit <Person, string>("DerivedAt");
            });

            population.DerivationById["FullName"] = new FullNameDerivation();

            dynamic john = population.New <Person>();

            john.FirstName = "John";
            john.LastName  = "Doe";

            population.Derive();

            Assert.Equal("John Doe", john.FullName);

            population.DerivationById["FullName"] = new GreetingDerivation(population.DerivationById["FullName"]);

            dynamic jane = population.New <Person>();

            jane.FirstName = "Jane";
            jane.LastName  = "Doe";

            population.Derive();

            Assert.Equal("Jane Doe Chained", jane.FullName);
        }
示例#2
0
        public void Derivation()
        {
            var population = new Default.DynamicPopulation(
                new DynamicMeta(new Pluralizer()),
                v =>
            {
                v.AddUnit <Person, string>("FirstName");
                v.AddUnit <Person, string>("LastName");
                v.AddUnit <Person, string>("FullName");
                v.AddUnit <Person, DateTime>("DerivedAt");
                v.AddUnit <Person, string>("Greeting");
            });

            population.DerivationById["FullName"] = new FullNameDerivation();
            population.DerivationById["Greeting"] = new GreetingDerivation();

            dynamic john = population.New <Person>();

            john.FirstName = "John";
            john.LastName  = "Doe";

            population.Derive();

            Assert.Equal("Hello John Doe!", john.Greeting);
        }