public void TestWriteDefinition_CustomInstantiateWorks()
        {
            var tpl = mocks.StrictMock <ITemplate>();

            mocks.ReplayAll();
            string expected = "private Namespace.TestType TestId {" + Environment.NewLine
                              + "	get { return (Namespace.TestType)controls[\"TestId\"]; }"+ Environment.NewLine
                              + "	set {"+ Environment.NewLine
                              + "		controls[\"TestId\"] = value;"+ Environment.NewLine
                              + "		if (!string.IsNullOrEmpty(id))"+ Environment.NewLine
                              + "			((IControl)controls[\"TestId\"]).Id = id + \"_TestId\";"+ Environment.NewLine
                              + "	}"+ Environment.NewLine
                              + "}" + Environment.NewLine + Environment.NewLine;

            var member = new InstantiatedControlMember("TestId", "Namespace.TestType", true, new Dictionary <string, TypedMarkupData>(), new IMember[0]);

            CodeBuilder cb = new CodeBuilder();

            member.WriteCode(tpl, MemberCodePoint.ServerDefinition, cb);
            Assert.AreEqual(expected, cb.ToString());
            Assert.AreEqual(0, cb.IndentLevel);

            cb = new CodeBuilder();
            member.WriteCode(tpl, MemberCodePoint.ClientDefinition, cb);
            Assert.AreEqual(expected, cb.ToString());
            Assert.AreEqual(0, cb.IndentLevel);
            mocks.VerifyAll();
        }
        private void TestWriteConstructorCode_NonCustomInstantiateWorks(bool server)
        {
            var tpl = mocks.StrictMock <ITemplate>();

            mocks.ReplayAll();
            var cb = new CodeBuilder();

            string expected = "{" + Environment.NewLine
                              + "Namespace.Type c = (Namespace.Type)Container.CreateObject(typeof(Namespace.Type));" + Environment.NewLine
                              + "c.Prop1 = value1;" + Environment.NewLine
                              + "c.Prop2 = value2;" + Environment.NewLine
                              + "this.controls[\"CtlName\"] = c;" + Environment.NewLine
                              + "}" + Environment.NewLine;

            var member = new InstantiatedControlMember("CtlName", "Namespace.Type", false, new Dictionary <string, TypedMarkupData>()
            {
                { "Prop1", new TypedMarkupData("value1") }, { "Prop2", new TypedMarkupData("value2") }
            }, new IMember[0]);

            if (server)
            {
                member.WriteCode(tpl, MemberCodePoint.ServerConstructor, cb);
            }
            else
            {
                member.WriteCode(tpl, MemberCodePoint.ClientConstructor, cb);
            }
            Assert.AreEqual(expected, cb.ToString());
            Assert.AreEqual(0, cb.IndentLevel);
            mocks.VerifyAll();
        }
        public void TestWriteIdChangedCode_NothingWritten()
        {
            var tpl = mocks.StrictMock <ITemplate>();

            mocks.ReplayAll();
            var member = new InstantiatedControlMember("TestId", "Namespace.TestType", false, new Dictionary <string, TypedMarkupData>(), new IMember[0]);

            CodeBuilder cb = new CodeBuilder();

            member.WriteCode(tpl, MemberCodePoint.ServerIdChanging, cb);
            Assert.AreEqual("", cb.ToString());
            Assert.AreEqual(0, cb.IndentLevel);

            cb = new CodeBuilder();
            member.WriteCode(tpl, MemberCodePoint.ClientIdChanging, cb);
            Assert.AreEqual("", cb.ToString());
            Assert.AreEqual(0, cb.IndentLevel);
            mocks.VerifyAll();
        }