Exemplo n.º 1
0
        public void SpeedTestInterface()
        {
            dynamic New     = new ClayFactory();
            IRobot  tRobot  = New.Robot().Name("Bender");
            IRobot  tRobotI = Impromptu.ActLike <IRobot>(New.Robot().Name("Bender"));

            var tInteration = 50000;
            var tWatchC     = TimeIt.Go(() =>
            {
                var tOut =
                    Impromptu.ActLike <IRobot>(New.Robot().Name("Bender"));
            }, tInteration);
            var tWatchC2 = TimeIt.Go(() =>
            {
                IRobot tOut = New.Robot().Name("Bender");
            }, tInteration);

            TestContext.WriteLine("*CreateInterface*");
            TestContext.WriteLine("Impromptu: " + tWatchC.Elapsed);
            TestContext.WriteLine("Clay: " + tWatchC2.Elapsed);
            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatchC2.ElapsedTicks / tWatchC.ElapsedTicks);
            Assert.Less(tWatchC.Elapsed, tWatchC2.Elapsed);

            var tWatch = TimeIt.Go(() => { var tOut = tRobotI.Name; }, tInteration);

            var tWatch2 = TimeIt.Go(() => { var tOut = tRobot.Name; }, tInteration);

            TestContext.WriteLine("*Get from Interface*");
            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Clay: " + tWatch2.Elapsed);

            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatch2.ElapsedTicks / tWatch.ElapsedTicks);

            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
Exemplo n.º 2
0
        public static void ComplexTest()
        {
            Console.WriteLine("**** ComplexTest ****");

            dynamic New = new ClayFactory();

            var directory = New.Array(
                New.Person(
                    FirstName: "Louis",
                    LastName: "Dejardin",
                    Aliases: new[] { "Lou" }
                    ),
                New.Person(
                    FirstName: "Bertrand",
                    LastName: "Le Roy"
                    ).Aliases("bleroy", "boudin"),
                New.Person(
                    FirstName: "Renaud",
                    LastName: "Paquay"
                    ).Aliases("Your Scruminess", "Chef")
                ).Name("Some Orchard folks");

            foreach (var person in directory)
            {
                Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
                foreach (var alias in person.Aliases)
                {
                    Console.WriteLine("    {0}", alias);
                }
            }

            Console.WriteLine();
        }
Exemplo n.º 3
0
        public void ClayTest()
        {
            dynamic New = new ClayFactory();

            var somePlugin = New.Person(new AnotherPlugin());

            IPlugin plugin = (IPlugin)somePlugin;

            int count = plugin.SomeMethod("john");
        }
Exemplo n.º 4
0
        public static void ChainableSetters() {
            Console.WriteLine("**** ChainableSetters ****");
            dynamic New = new ClayFactory();

            var person = New.Person()
                .FirstName("Louis")
                .LastName("Dejardin");

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);

            Console.WriteLine();
        }
Exemplo n.º 5
0
        public static void ChainableSetters()
        {
            Console.WriteLine("**** ChainableSetters ****");
            dynamic New = new ClayFactory();

            var person = New.Person()
                         .FirstName("Louis")
                         .LastName("Dejardin");

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);

            Console.WriteLine();
        }
Exemplo n.º 6
0
        public static void IndexedPropertySyntax() {
            Console.WriteLine("**** IndexedPropertySyntax ****");

            dynamic New = new ClayFactory();

            var person = New.Person();
            person["FirstName"] = "Louis";
            person["LastName"] = "Dejardin";

            // Note that you can mix and match
            Console.WriteLine("{0} {1}", person["FirstName"], person.LastName);

            Console.WriteLine();
        }
Exemplo n.º 7
0
        public static void NamedArguments() {
            Console.WriteLine("**** NamedArguments ****");

            dynamic New = new ClayFactory();

            var person = New.Person(
                FirstName: "Louis",
                LastName: "Dejardin"
            );

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);

            Console.WriteLine();
        }
Exemplo n.º 8
0
        public static void AnonymousObject() {
            Console.WriteLine("**** AnonymousObject ****");

            dynamic New = new ClayFactory();

            var person = New.Person(new {
                FirstName = "Louis",
                LastName = "Dejardin"
            });

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);

            Console.WriteLine();
        }
Exemplo n.º 9
0
        public static void AnonymousObject()
        {
            Console.WriteLine("**** AnonymousObject ****");

            dynamic New = new ClayFactory();

            var person = New.Person(new {
                FirstName = "Louis",
                LastName  = "Dejardin"
            });

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);

            Console.WriteLine();
        }
Exemplo n.º 10
0
        public static void NamedArguments()
        {
            Console.WriteLine("**** NamedArguments ****");

            dynamic New = new ClayFactory();

            var person = New.Person(
                FirstName: "Louis",
                LastName: "Dejardin"
                );

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);

            Console.WriteLine();
        }
Exemplo n.º 11
0
        public static void IndexedPropertySyntax()
        {
            Console.WriteLine("**** IndexedPropertySyntax ****");

            dynamic New = new ClayFactory();

            var person = New.Person();

            person["FirstName"] = "Louis";
            person["LastName"]  = "Dejardin";

            // Note that you can mix and match
            Console.WriteLine("{0} {1}", person["FirstName"], person.LastName);

            Console.WriteLine();
        }
Exemplo n.º 12
0
        public static void PropertyAssignment() {
            Console.WriteLine("**** PropertyAssignment ****");

            dynamic New = new ClayFactory();

            var person = New.Person();
            person.FirstName = "Louis";
            person.LastName = "Dejardin";

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);

            // This is equivalent, using method call syntax
            Console.WriteLine("{0} {1}", person.FirstName(), person.LastName());

            Console.WriteLine();
        }
Exemplo n.º 13
0
        public void SpeedTestPrototype()
        {
            dynamic NewI = Builder.New();
            dynamic NewE = Builder.New <ExpandoObject>();
            dynamic NewP = Builder.New <Robot>();
            dynamic NewC = new ClayFactory();

            var   tRobotI = NewI.Robot(Name: "Bender");
            var   tRobotC = NewC.Robot(Name: "Bender");
            var   tRobotE = NewE.Robot(Name: "Bender");
            Robot tRobotP = NewP.Robot(Name: "Bender");

            var tWatchI = TimeIt.Go(() =>
            {
                var tOut = tRobotI.Name;
            });

            var tWatchC = TimeIt.Go(() =>
            {
                var tOut = tRobotC.Name;
            });

            var tWatchE = TimeIt.Go(() =>
            {
                var tOut = tRobotE.Name;
            });

            var tWatchP = TimeIt.Go(() =>
            {
                var tOut = tRobotP.Name;
            });

            TestContext.WriteLine("Impromptu: " + tWatchI.Elapsed);
            TestContext.WriteLine("Clay: " + tWatchC.Elapsed);
            TestContext.WriteLine("Expando: " + tWatchE.Elapsed);
            TestContext.WriteLine("POCO: " + tWatchP.Elapsed);

            Assert.Less(tWatchI.Elapsed, tWatchC.Elapsed);

            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatchC.ElapsedTicks / tWatchI.ElapsedTicks);
            TestContext.WriteLine("Expando  VS Clay:{0:0.0}  x faster", (double)tWatchC.ElapsedTicks / tWatchE.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Clay:{0:0.0}  x faster", (double)tWatchC.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Impromptu:{0:0.0}  x faster", (double)tWatchI.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Expando:{0:0.0}  x faster", (double)tWatchE.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("Expando  VS Impromptu:{0:0.0}  x faster", (double)tWatchI.ElapsedTicks / tWatchE.ElapsedTicks);
        }
Exemplo n.º 14
0
        public static void PropertyAssignment()
        {
            Console.WriteLine("**** PropertyAssignment ****");

            dynamic New = new ClayFactory();

            var person = New.Person();

            person.FirstName = "Louis";
            person.LastName  = "Dejardin";

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);

            // This is equivalent, using method call syntax
            Console.WriteLine("{0} {1}", person.FirstName(), person.LastName());

            Console.WriteLine();
        }
Exemplo n.º 15
0
        public void TestClay()
        {
            dynamic New = new ClayFactory();

            var directory = New.Array(
                New.Person().Name("Louis").Aliases(new[] { "Lou" }),
                New.Person().Name("Bertrand").Aliases("bleroy", "boudin")
                ).Name("Orchard folks");

            Assert.AreEqual(2, directory.Count);
            Assert.AreEqual("Orchard folks", directory.Name);
            Assert.AreEqual("Louis", directory[0].Name);
            Assert.AreEqual(1, directory[0].Aliases.Count);
            Assert.AreEqual("Lou", directory[0].Aliases[0]);
            Assert.AreEqual("Bertrand", directory[1].Name);
            Assert.AreEqual(2, directory[1].Aliases.Count);
            Assert.AreEqual("bleroy", directory[1].Aliases[0]);
            Assert.AreEqual("boudin", directory[1].Aliases[1]);
        }
Exemplo n.º 16
0
        public void TestClay()
        {
            dynamic New = new ClayFactory();

            var directory = New.Array(
                   New.Person().Name("Louis").Aliases(new[] { "Lou" }),
                   New.Person().Name("Bertrand").Aliases("bleroy", "boudin")
                   ).Name("Orchard folks");

            Assert.AreEqual(2, directory.Count);
            Assert.AreEqual("Orchard folks", directory.Name);
            Assert.AreEqual("Louis",directory[0].Name);
            Assert.AreEqual(1, directory[0].Aliases.Count);
            Assert.AreEqual("Lou",directory[0].Aliases[0]);
            Assert.AreEqual("Bertrand",directory[1].Name);
            Assert.AreEqual(2, directory[1].Aliases.Count);
            Assert.AreEqual("bleroy",directory[1].Aliases[0]);
            Assert.AreEqual("boudin",directory[1].Aliases[1]);
        }
Exemplo n.º 17
0
        public static void CastToCLRInterface()
        {
            Console.WriteLine("**** CastToCLRInterface ****");

            dynamic New = new ClayFactory();

            var person = New.Person();

            person.FirstName = "Louis";
            person.LastName  = "Dejardin";

            // Concrete interface implementation gets magically created!
            IPerson lou = person;

            // You get intellisense and compile time check here
            Console.WriteLine("{0} {1}", lou.FirstName, lou.LastName);

            Console.WriteLine();
        }
        public static void ArrayCreation()
        {
            Console.WriteLine("**** ArrayCreation ****");

            dynamic New = new ClayFactory();

            var people = New.Array(
                New.Person().FirstName("Louis").LastName("Dejardin"),
                New.Person().FirstName("Bertrand").LastName("Le Roy")
            );

            Console.WriteLine("Count = {0}", people.Count);
            Console.WriteLine("people[0].FirstName = {0}", people[0].FirstName);

            foreach (var person in people) {
                Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
            }

            Console.WriteLine();
        }
Exemplo n.º 19
0
        public void AddDefaultRoutes()
        {
            dynamic New = new ClayFactory();

            var document = New.Array(
                New.Person(
                    FirstName: "Louis",
                    LastName: "Dejardin",
                    Aliases: new[] { "Lou" }
                    ),
                New.Person(
                    FirstName: "Bertrand",
                    LastName: "Le Roy"
                    ).Aliases("bleroy", "boudin"),
                New.Person(
                    FirstName: "Renaud",
                    LastName: "Paquay"
                    ).Aliases("Your Scruminess", "Chef")
                ).Name("Some Orchard folks").Id(Guid.NewGuid());


            //var document = new Document {Id = Guid.NewGuid()};

            var serializedDocument = JsonConvert.SerializeObject(document, Formatting.Indented, new ClayJsonConverter());

            var x = serializedDocument;

            //using (var documentSession = DependencyResolver.Current.GetService<IDocumentSession>())
            //{
            //    documentSession.Store(document);
            //    documentSession.SaveChanges();
            //}

            //dynamic loadedDocument;
            //using (var documentSession = DependencyResolver.Current.GetService<IDocumentSession>())
            //{
            //    loadedDocument = documentSession.Load<Document>(document.Id);
            //}

            //Assert.IsTrue(Extensions.PublicInstancePropertiesEqual<Document>(loadedDocument, document));
        }
Exemplo n.º 20
0
        public static void ArrayCreation()
        {
            Console.WriteLine("**** ArrayCreation ****");

            dynamic New = new ClayFactory();

            var people = New.Array(
                New.Person().FirstName("Louis").LastName("Dejardin"),
                New.Person().FirstName("Bertrand").LastName("Le Roy")
                );

            Console.WriteLine("Count = {0}", people.Count);
            Console.WriteLine("people[0].FirstName = {0}", people[0].FirstName);

            foreach (var person in people)
            {
                Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
            }

            Console.WriteLine();
        }
        public static void ArrayCreationOnExistingObject()
        {
            Console.WriteLine("**** ArrayCreationOnExistingObject ****");

            dynamic New = new ClayFactory();

            var person = New.Person(
                FirstName: "Bertrand",
                LastName: "Le Roy"
            );

            person.Aliases("bleroy", "BoudinFatal");

            // Array size is dynamic
            person.Aliases.Add("One more alias");

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
            foreach (var alias in person.Aliases) {
                Console.WriteLine("    {0}", alias);
            }

            Console.WriteLine();
        }
Exemplo n.º 22
0
        public static void ArrayCreationOnExistingObject()
        {
            Console.WriteLine("**** ArrayCreationOnExistingObject ****");

            dynamic New = new ClayFactory();

            var person = New.Person(
                FirstName: "Bertrand",
                LastName: "Le Roy"
                );

            person.Aliases("bleroy", "BoudinFatal");

            // Array size is dynamic
            person.Aliases.Add("One more alias");

            Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
            foreach (var alias in person.Aliases)
            {
                Console.WriteLine("    {0}", alias);
            }

            Console.WriteLine();
        }
        public static void CastToCLRInterface()
        {
            Console.WriteLine("**** CastToCLRInterface ****");

            dynamic New = new ClayFactory();

            var person = New.Person();
            person.FirstName = "Louis";
            person.LastName = "Dejardin";

            // Concrete interface implementation gets magically created!
            IPerson lou = person;

            // You get intellisense and compile time check here
            Console.WriteLine("{0} {1}", lou.FirstName, lou.LastName);

            Console.WriteLine();
        }
        public static void ComplexTest()
        {
            Console.WriteLine("**** ComplexTest ****");

            dynamic New = new ClayFactory();

            var directory = New.Array(
                New.Person(
                    FirstName: "Louis",
                    LastName: "Dejardin",
                    Aliases: new[] { "Lou" }
                ),
                New.Person(
                    FirstName: "Bertrand",
                    LastName: "Le Roy"
                ).Aliases("bleroy", "boudin"),
                New.Person(
                    FirstName: "Renaud",
                    LastName: "Paquay"
                ).Aliases("Your Scruminess", "Chef")
            ).Name("Some Orchard folks");

            foreach (var person in directory) {
                Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
                foreach (var alias in person.Aliases) {
                    Console.WriteLine("    {0}", alias);
                }
            }

            Console.WriteLine();
        }
Exemplo n.º 25
0
        public void SpeedTestInterface()
        {   
            dynamic New = new ClayFactory();
            IRobot tRobot = New.Robot().Name("Bender");
            IRobot tRobotI = Impromptu.ActLike<IRobot>(New.Robot().Name("Bender"));
         
             var tInteration = 50000;
             var tWatchC = TimeIt.Go(() =>
                                         {
                                             var tOut =
                                                 Impromptu.ActLike<IRobot>(New.Robot().Name("Bender"));
                                         }, tInteration);
            var tWatchC2 = TimeIt.Go(() =>
                                         {
                                             IRobot tOut = New.Robot().Name("Bender");
                                         },tInteration );
           
            TestContext.WriteLine("*CreateInterface*");
            TestContext.WriteLine("Impromptu: " + tWatchC.Elapsed);
            TestContext.WriteLine("Clay: " + tWatchC2.Elapsed);
            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatchC2.ElapsedTicks / tWatchC.ElapsedTicks);
            Assert.Less(tWatchC.Elapsed, tWatchC2.Elapsed);

            var tWatch = TimeIt.Go(() => { var tOut = tRobotI.Name; }, tInteration);

            var tWatch2 = TimeIt.Go(() => { var tOut = tRobot.Name; }, tInteration);
            
            TestContext.WriteLine("*Get from Interface*");
            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Clay: " + tWatch2.Elapsed);

            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatch2.ElapsedTicks / tWatch.ElapsedTicks);

             Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }
Exemplo n.º 26
0
        public void SpeedTestPrototype()
        {
            dynamic NewI = Builder.New();
            dynamic NewE = Builder.New<ExpandoObject>();
            dynamic NewP = Builder.New<Robot>();
            dynamic NewC = new ClayFactory();

            var tRobotI = NewI.Robot(Name: "Bender");
            var tRobotC = NewC.Robot(Name: "Bender");
            var tRobotE = NewE.Robot(Name: "Bender");
            Robot tRobotP = NewP.Robot(Name: "Bender");

            var tWatchI = TimeIt.Go(() =>
            {
                var tOut = tRobotI.Name;
            });
   
            var tWatchC = TimeIt.Go(() =>
             {
                 var tOut =tRobotC.Name;
             } );

            var tWatchE = TimeIt.Go(() =>
            {
                var tOut = tRobotE.Name;
            });

            var tWatchP = TimeIt.Go(() =>
            {
                var tOut = tRobotP.Name;
            });
            TestContext.WriteLine("Impromptu: " + tWatchI.Elapsed);
            TestContext.WriteLine("Clay: " + tWatchC.Elapsed);
            TestContext.WriteLine("Expando: " + tWatchE.Elapsed);
            TestContext.WriteLine("POCO: " + tWatchP.Elapsed);

            Assert.Less(tWatchI.Elapsed, tWatchC.Elapsed);

            TestContext.WriteLine("Impromptu VS Clay: {0:0.0} x faster", (double)tWatchC.ElapsedTicks / tWatchI.ElapsedTicks);
            TestContext.WriteLine("Expando  VS Clay:{0:0.0}  x faster", (double)tWatchC.ElapsedTicks / tWatchE.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Clay:{0:0.0}  x faster", (double)tWatchC.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Impromptu:{0:0.0}  x faster", (double)tWatchI.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("POCO  VS Expando:{0:0.0}  x faster", (double)tWatchE.ElapsedTicks / tWatchP.ElapsedTicks);
            TestContext.WriteLine("Expando  VS Impromptu:{0:0.0}  x faster", (double)tWatchI.ElapsedTicks / tWatchE.ElapsedTicks);
        }