public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"class Class1\r\n" +
				"    def initialize()\r\n" +
				"        @name = String.Empty\r\n" +
				"        @lastName = String.Empty\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def Name\r\n" +
				"        return @name\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def Name=(value)\r\n" +
				"        @name = value\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def LastName\r\n" +
				"        return @lastName\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def LastName=(value)\r\n" +
				"        @lastName = value\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def Clone()\r\n" +
				"        return Class1.new(Name = \"First\", LastName = \"Last\")\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"# <summary>\r\n" +
				"# Class Foo\r\n" +
				"# </summary>\r\n" +
				"class Foo\r\n" +
				"    # <summary>\r\n" +
				"    # Run\r\n" +
				"    # </summary>\r\n" +
				"    def Run()\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    # <summary> Stop </summary>\r\n" +
				"    def Stop()\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    # <summary> Initialize.</summary>\r\n" +
				"    def initialize()\r\n" +
				"        # Initialize j.\r\n" +
				"        j = 0 # Set to zero\r\n" +
				"        # test\r\n" +
				"        if j == 0 then\r\n" +
				"            j = 2\r\n" +
				"        end\r\n" +
				"    end\r\n" +
				"end";

			Assert.AreEqual(expectedRuby, Ruby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        @count = 0\r\n" +
				"        @i = 0\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def Count\r\n" +
				"        if @i == 0 then\r\n" +
				"            return 10\r\n" +
				"        else\r\n" +
				"            return @count\r\n" +
				"        end\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def Count=(value)\r\n" +
				"        if @i == 1 then\r\n" +
				"            @count = value\r\n" +
				"        else\r\n" +
				"            @count = value + 5\r\n" +
				"        end\r\n" +
				"    end\r\n" +				
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        @count = 0\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def Count\r\n" +
				"        return @count\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def Increment()\r\n" +
				"        self.Count += 1\r\n" +
				"    end\r\n" +
				"\r\n" +
				"    def SetCount(Count)\r\n" +
				"        self.Count = Count\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby, Ruby);
		}
		public void GeneratedMainMethodCallWithNoParametersCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "  ";
			converter.Convert(mainMethodWithNoParametersCode);
			string code = converter.GenerateMainMethodCall(converter.EntryPointMethods[0]);	
			Assert.AreEqual("Foo.Main()", code);
		}
		public void MultiplyOperator()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(GetCode(csharp, "*="));
			string expectedRuby = GetCode(RubyCodeTemplate, "*=");
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			string Ruby = converter.Convert(csharp);
			string expectedRuby = "class Foo\r\n" +
									"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}		
		public void ConvertedRubyCode()
		{
			string expectedCode =
				"class Foo < Bar, IMyInterface\r\n" +
				"end";
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string code = converter.Convert(csharp);
			
			Assert.AreEqual(expectedCode, code);
		}
		public void GeneratedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			string Ruby = converter.Convert(csharp);
			string expectedRuby = "require \"mscorlib\"\r\n" +
									"require \"System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\r\n" +
									"\r\n" +
									"class Foo\r\n" +
									"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
Beispiel #10
0
        public static bool Convert(SupportedLanguage inputLanguage, string ProvidedSource, out string ConvertedSource, out string ErrorMessage)
        {
            NRefactoryToRubyConverter converter = new
                    NRefactoryToRubyConverter(inputLanguage);

            string convertedCode = converter.Convert(ProvidedSource);

            ConvertedSource = convertedCode;
            ErrorMessage = "";

            return true;
        }
		public void GeneratedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby = "class Foo\r\n" +
									"    def Init()\r\n" +
									"    end\r\n" +
									"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			string expectedCode = "class Foo\r\n" +
									"    def Run()\r\n" +
									"        raise XmlException.new()\r\n" +
									"    end\r\n" +
									"end";
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string code = converter.Convert(csharp);
			
			Assert.AreEqual(expectedCode, code);
		}	
		public void GeneratedRubySourceCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(vb);
			string expectedRuby = 
				"module DefaultNamespace\r\n" +
				"    class Class1\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"class Foo\r\n" +
				"    def IsEqual(o)\r\n" +
				"        return System::Object.ReferenceEquals(o, nil)\r\n" +
				"    end\r\n" +
				"end";

			Assert.AreEqual(expectedRuby, Ruby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby = "class Foo\r\n" +
									"    def TestMe(test)\r\n" +
									"        a = test ? \"Ape\" : \"Monkey\"\r\n" +
									"        return a\r\n" +
									"    end\r\n" +
									"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertCSharpClassWithFieldsWhereFirstFieldDoesNotHaveInitialValue()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string ruby = converter.Convert(csharpClassWithTwoFieldsWhereFirstDoesNotHaveInitialValue);
			string expectedRuby =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        @j = 1\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        System.Console.WriteLine(\"Test\")\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			string expectedRuby =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        b = Bar.new(0, 0, 1, 10)\r\n" +
				"    end\r\n" +
				"end";
			
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertVBNetClassWithTwoArrayVariablesOnSameLine()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet);
			converter.IndentString = "    ";
			string ruby = converter.Convert(vnetClassWithTwoArrayLocalVariablesOnSameLine);
			string expectedRuby =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        i = Array.CreateInstance(System::Int32, 10)\r\n" +
				"        j = Array.CreateInstance(System::Int32, 20)\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"class Foo\r\n" +
				"    def Convert()\r\n" +
				"        a = (b >> 16) & 0xffff\r\n" +
				"        return a\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void SwitchStatement()
		{
			string csharp =
				"class Foo\r\n" +
				"{\r\n" +
				"    public int Run(int i)\r\n" +
				"    {\r\n" +
				"        switch (i) {\r\n" +
				"            case 7:\r\n" +
				"                i = 4;\r\n" +
				"                break;\r\n" +
				"            case 10:\r\n" +
				"                return 0;\r\n" +
				"            case 9:\r\n" +
				"                return 2;\r\n" +
				"            case 8:\r\n" +
				"                break;\r\n" +
				"            default:\r\n" +
				"                return -1;\r\n" +
				"        }\r\n" +
				"        return i;\r\n" +
				"    }\r\n" +
				"}";

			string expectedRuby =
				"class Foo\r\n" +
				"  def Run(i)\r\n" +
				"    case i\r\n" +
				"      when 7\r\n" +
				"        i = 4\r\n" +
				"      when 10\r\n" +
				"        return 0\r\n" +
				"      when 9\r\n" +
				"        return 2\r\n" +
				"      when 8\r\n" +
				"      else\r\n" +
				"        return -1\r\n" +
				"    end\r\n" +
				"    return i\r\n" +
				"  end\r\n" +
				"end";
	
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "  ";
			string code = converter.Convert(csharp);
			
			Assert.AreEqual(expectedRuby, code, code);
		}	
		public void Equals()
		{
			string code = GetCode(@"==");
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string RubyCode = converter.Convert(code);
			string expectedRubyCode = "class Foo\r\n" +
						"    def Run(i)\r\n" +
						"        if i == 0 then\r\n" +
						"            return 10\r\n" +
						"        end\r\n" +
						"        return 0\r\n" +
						"    end\r\n" +
						"end";
			Assert.AreEqual(expectedRubyCode, RubyCode);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet);
			converter.IndentString = "    ";
			string ruby = converter.Convert(vb);
			string expectedRuby =
				"class Class1\r\n" +
				"    def Test()\r\n" +
				"        while true\r\n" +
				"            break\r\n" +
				"        end\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, ruby);
		}
		public void ConvertedTypeOfIntegerCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(typeofIntCode);
			string expectedRuby =
				"require \"mscorlib\"\r\n" +
				"\r\n" +
				"class Foo\r\n" +
				"    def ToString()\r\n" +
				"        System::Int32.to_clr_type.FullName\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void GeneratedRubySourceCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"class Foo\r\n" +
				"    def Assign()\r\n" +
				"        elements = Array.CreateInstance(System::Int32, 10)\r\n" +
				"        list = List[Array[System::Int32]].new()\r\n" +
				"        list.Add(elements.Clone())\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby = "class Foo\r\n" +
									"    def Run(a)\r\n" +
									"        if a == nil then\r\n" +
									"            return 4\r\n" +
									"        end\r\n" +
									"        return 2\r\n" +
									"    end\r\n" +
									"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void GeneratedRubySourceCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"require \"mscorlib\"\r\n" +
				"require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\r\n" +
				"\r\n" +
				"module MyNamespace\r\n" +
				"    class Foo\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			string expectedRuby =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        doc = XmlDocument.new()\r\n" +
				"        doc.LoadXml(\"<root/>\")\r\n" +
				"    end\r\n" +
				"end";
			
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			
			Assert.AreEqual(expectedRuby, Ruby);
		}
		public void ConvertedRubyCode()
		{
			string expectedCode =
				"class Foo\r\n" +
				"    def initialize()\r\n" +
				"        button = Button.new()\r\n" +
				"        button.Click { self.ButtonClick() }\r\n" +
				"        button.MouseDown { self.OnMouseDown() }\r\n" +
				"    end\r\n" +
				"end";
			
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp, parseInfo);
			converter.IndentString = "    ";
			string code = converter.Convert(csharp);
			
			Assert.AreEqual(expectedCode, code, code);
		}
		public void ConvertedRubyCode()
		{
			NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
			converter.IndentString = "    ";
			string Ruby = converter.Convert(csharp);
			string expectedRuby =
				"class Foo\r\n" +
				"    def CountDown()\r\n" +
				"        i = 10\r\n" +
				"        while i > 0\r\n" +
				"            i -= 1\r\n" +
				"        end\r\n" +
				"    end\r\n" +
				"end";
			
			Assert.AreEqual(expectedRuby, Ruby);
		}