コード例 #1
0
        void calling_set_members()
        {
            context["setting a single member"] = () =>
            {
                act = () =>
                {
                    gemini = new ParameterlessGemini();
                    gemini.SetMember("FirstName", "Amir");
                };

                it["sets member"] = () => (gemini.FirstName as string).should_be("Amir");
            };

            context["setting multiple members"] = () =>
            {
                act = () =>
                {
                    gemini = new ParameterlessGemini();
                    gemini.SetMembers(new { FirstName = "Amir", LastName = "Rajan" });
                };

                it["sets multiple members"] = () =>
                {
                    (gemini.FirstName as string).should_be("Amir");
                    (gemini.LastName as string).should_be("Rajan");
                };
            };
        }
コード例 #2
0
ファイル: accessing_property.cs プロジェクト: bpugh/Oak
        void properites_defined_on_underlying_prototype()
        {
            before = () => gemini = new ParameterlessGemini();

            it["properties are accessible"] = () => (gemini.FirstName as string).should_be("");

            context["tacking on properties after the fact is allowed"] = () =>
            {
                act = () => gemini.Prototype.NewProp = "new prop";

                it["new prop is accessible"] = () => (gemini.NewProp as string).should_be("new prop");
            };

            context["tacking on methods after the fact is allowed"] = () =>
            {
                act = () => gemini.Prototype.NewProp = new Func <string, string>((s) => s.ToUpper());

                it["new method is accessible"] = () => (gemini.NewProp("hello") as string).should_be("HELLO");
            };
        }
コード例 #3
0
ファイル: gemini_methods.cs プロジェクト: bpugh/Oak
        void calling_dynamically_defined_methods()
        {
            context["method is defined as a dynamic function that takes in one dynamic parameter"] = () =>
            {
                act = () =>
                {
                    gemini = new ParameterlessGemini();
                    gemini.CreateNewGemini = new DynamicFunctionWithParam(d => new Gemini(d));
                };

                it["calls method with parameter specified"] = () =>
                {
                    dynamic newGemini = gemini.CreateNewGemini(new { FirstName = "Amir" });

                    (newGemini.FirstName as string).should_be("Amir");
                };

                it["calls method with even if parameter is not specified"] = () =>
                {
                    dynamic newGemini = gemini.CreateNewGemini();

                    (newGemini as object).should_not_be_null();
                };

                it["calls method with parameters specified as named parameters"] = () =>
                {
                    dynamic newGemini = gemini.CreateNewGemini(FirstName: "Amir");

                    (newGemini.FirstName as string).should_be("Amir");
                };

                it["ignores unnamed parameters if name parameters have been specified"] = () =>
                {
                    dynamic newGemini = gemini.CreateNewGemini("Unnamed", FirstName: "Amir", LastName: "Rajan");

                    (newGemini.FirstName as string).should_be("Amir");

                    (newGemini.LastName as string).should_be("Rajan");
                };
            };

            context["method is defined as a dynamic method that takes in one dynamic parameter"] = () =>
            {
                act = () =>
                {
                    gemini             = new ParameterlessGemini();
                    gemini.AlterGemini = new DynamicMethodWithParam(d => gemini.Property = d ?? "Default");
                };

                it["calls method with parameter specified"] = () =>
                {
                    gemini.AlterGemini("Other");

                    (gemini.Property as string).should_be("Other");
                };

                it["calls method with even if parameter is not specified"] = () =>
                {
                    gemini.AlterGemini();

                    (gemini.Property as string).should_be("Default");
                };
            };
        }