public void CurrentMemberShouldBeClearedBetweenTypes()
        {
            ICodeGenerator codeGenerator = new MockCodeGenerator();
            var            o             = new StringWriter()
            {
                NewLine = "\n",
            };

            var t = new CodeTypeDeclaration()
            {
                Name    = "Foo",
                Members =
                {
                    new CodeMemberField()
                    {
                        Name = "f",
                    },
                    new CodeMemberMethod()
                    {
                        Name            = "M",
                        StartDirectives =
                        {
                            new CodeRegionDirective(CodeRegionMode.Start, "foo..."),
                        },
                        EndDirectives =
                        {
                            new CodeRegionDirective(CodeRegionMode.End, null),
                        },
                    }
                }
            };

            var opts = new CodeGeneratorOptions()
            {
                IndentString = "\t",
            };

            codeGenerator.GenerateCodeFromType(t, o, opts);
            t.Name = "Bar";
            codeGenerator.GenerateCodeFromType(t, o, opts);

            var expected =
                "(type Foo\n" +
                "\t\n" +
                "\t(field f (TypeRef System.Void))\n" +
                "\t\n" +
                "\t(region foo...\n" +
                "\t\t(method M)))\n" +
                "(type Bar\n" +
                "\t\n" +
                "\t(field f (TypeRef System.Void))\n" +
                "\t\n" +
                "\t(region foo...\n" +
                "\t\t(method M)))\n";

            Assert.AreEqual(expected, o.ToString());
        }
Пример #2
0
        public void IsCurrentTest()
        {
            MockCodeGenerator codeGenerator = new MockCodeGenerator();

            Assert.AreEqual(false, codeGenerator.IsCurrentClass, "#A1");
            Assert.AreEqual(false, codeGenerator.IsCurrentDelegate, "#A2");
            Assert.AreEqual(false, codeGenerator.IsCurrentEnum, "#A3");
            Assert.AreEqual(false, codeGenerator.IsCurrentInterface, "#A4");
            Assert.AreEqual(false, codeGenerator.IsCurrentStruct, "#A5");

            ((ICodeGenerator)codeGenerator).GenerateCodeFromType(GetClassType(),
                                                                 new StringWriter(), new CodeGeneratorOptions());
            Assert.AreEqual(true, codeGenerator.IsCurrentClass, "#B1");
            Assert.AreEqual(false, codeGenerator.IsCurrentDelegate, "#B2");
            Assert.AreEqual(false, codeGenerator.IsCurrentEnum, "#B3");
            Assert.AreEqual(false, codeGenerator.IsCurrentInterface, "#B4");
            Assert.AreEqual(false, codeGenerator.IsCurrentStruct, "#B5");

            ((ICodeGenerator)codeGenerator).GenerateCodeFromType(GetDelegateType(),
                                                                 new StringWriter(), new CodeGeneratorOptions());
            Assert.AreEqual(false, codeGenerator.IsCurrentClass, "#C1");
            Assert.AreEqual(true, codeGenerator.IsCurrentDelegate, "#C2");
            Assert.AreEqual(false, codeGenerator.IsCurrentEnum, "#C3");
            Assert.AreEqual(false, codeGenerator.IsCurrentInterface, "#C4");
            Assert.AreEqual(false, codeGenerator.IsCurrentStruct, "#C5");

            ((ICodeGenerator)codeGenerator).GenerateCodeFromType(GetEnumType(),
                                                                 new StringWriter(), new CodeGeneratorOptions());
            Assert.AreEqual(false, codeGenerator.IsCurrentClass, "#D1");
            Assert.AreEqual(false, codeGenerator.IsCurrentDelegate, "#D2");
            Assert.AreEqual(true, codeGenerator.IsCurrentEnum, "#D3");
            Assert.AreEqual(false, codeGenerator.IsCurrentInterface, "#D4");
            Assert.AreEqual(false, codeGenerator.IsCurrentStruct, "#D5");

            ((ICodeGenerator)codeGenerator).GenerateCodeFromType(GetInterfaceType(),
                                                                 new StringWriter(), new CodeGeneratorOptions());
            Assert.AreEqual(false, codeGenerator.IsCurrentClass, "#E1");
            Assert.AreEqual(false, codeGenerator.IsCurrentDelegate, "#E2");
            Assert.AreEqual(false, codeGenerator.IsCurrentEnum, "#E3");
            Assert.AreEqual(true, codeGenerator.IsCurrentInterface, "#E4");
            Assert.AreEqual(false, codeGenerator.IsCurrentStruct, "#E5");

            ((ICodeGenerator)codeGenerator).GenerateCodeFromType(GetStructType(),
                                                                 new StringWriter(), new CodeGeneratorOptions());
            Assert.AreEqual(false, codeGenerator.IsCurrentClass, "#F1");
            Assert.AreEqual(false, codeGenerator.IsCurrentDelegate, "#F2");
            Assert.AreEqual(false, codeGenerator.IsCurrentEnum, "#F3");
            Assert.AreEqual(false, codeGenerator.IsCurrentInterface, "#F4");
            Assert.AreEqual(true, codeGenerator.IsCurrentStruct, "#F5");
        }
		public void IsCurrentTest ()
		{
			MockCodeGenerator codeGenerator = new MockCodeGenerator ();
			Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#A1");
			Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#A2");
			Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#A3");
			Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#A4");
			Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#A5");

			((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetClassType (),
				new StringWriter (), new CodeGeneratorOptions ());
			Assert.AreEqual (true, codeGenerator.IsCurrentClass, "#B1");
			Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#B2");
			Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#B3");
			Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#B4");
			Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#B5");

			((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetDelegateType (),
				new StringWriter (), new CodeGeneratorOptions ());
			Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#C1");
			Assert.AreEqual (true, codeGenerator.IsCurrentDelegate, "#C2");
			Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#C3");
			Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#C4");
			Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#C5");

			((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetEnumType (),
				new StringWriter (), new CodeGeneratorOptions ());
			Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#D1");
			Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#D2");
			Assert.AreEqual (true, codeGenerator.IsCurrentEnum, "#D3");
			Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#D4");
			Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#D5");

			((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetInterfaceType (),
				new StringWriter (), new CodeGeneratorOptions ());
			Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#E1");
			Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#E2");
			Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#E3");
			Assert.AreEqual (true, codeGenerator.IsCurrentInterface, "#E4");
			Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#E5");

			((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetStructType (),
				new StringWriter (), new CodeGeneratorOptions ());
			Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#F1");
			Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#F2");
			Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#F3");
			Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#F4");
			Assert.AreEqual (true, codeGenerator.IsCurrentStruct, "#F5");
		}