Ejemplo n.º 1
0
 public void ClassUnitTestRoundtrip()
 {
     // formatted class doesn't match the converted class because of the testMethod modifiers
     CompareLineByLine(ApexSharpParser.IndentApex(ClassUnitTest_Original), ClassUnitTest_Formatted);
     CompareLineByLine(ApexToCSharpHelpers.ConvertToCSharp(ClassUnitTest_Original, Options), ClassUnitTest_CSharp1);
     CompareLineByLine(CSharpToApexHelpers.ConvertToApex(ClassUnitTest_CSharp1)[0], ClassUnitTest_Converted);
 }
Ejemplo n.º 2
0
 private void Check(string apexOriginal, string apexFormatted, string csharp)
 {
     Assert.Multiple(() =>
     {
         CompareLineByLine(ApexSharpParser.IndentApex(apexOriginal), apexFormatted);
         CompareLineByLine(ApexToCSharpHelpers.ConvertToCSharp(apexOriginal, Options), csharp);
         CompareLineByLine(CSharpToApexHelpers.ConvertToApex(csharp)[0], apexFormatted);
     });
 }
Ejemplo n.º 3
0
        public void CSharpHelperConvertsCSharpTextsToApex()
        {
            var csharp      = "class Test1 { public Test1(int x) { } } class Test2 : Test1 { private int x = 10; }";
            var apexClasses = CSharpToApexHelpers.ConvertToApex(csharp);

            Assert.AreEqual(2, apexClasses.Length);

            CompareLineByLine(
                @"class Test1
                {
                    public Test1(Integer x)
                    {
                    }
                }", apexClasses[0]);

            CompareLineByLine(
                @"class Test2 extends Test1
                {
                    private Integer x = 10;
                }", apexClasses[1]);
        }
Ejemplo n.º 4
0
        public void DemoTestIsConverted()
        {
            var csharpCode =
                @"namespace ApexSharpDemo.ApexCode
                {
                    using Apex.ApexSharp;
                    using Apex.System;
                    using SObjects;
                    using NUnit.Framework;

                    [TestFixture]
                    public class DemoTest
                    {
                        [OneTimeSetUp]
                        public void NoApexSetup()
                        {
                            new ApexSharp().Connect(""C:\\DevSharp\\connect.json"");
                        }

                        [SetUp]
                        public static void Setup()
                        {
                            Contact contactNew = new Contact();
                            contactNew.LastName = ""Jay"";
                            contactNew.Email = ""*****@*****.**"";
                            Soql.Insert(contactNew);
                        }

                        [OneTimeSetUp]
                        public void noApexSetupAgain()
                        {
                            new ApexSharp().Connect(""C:\\DevSharp\\connect.json"");
                        }

                        [Test]
                        public static void UpdatePhoneTestValidEmail()
                        {
                            Demo.UpdatePhone(""*****@*****.**"", ""555-1212"");
                            List<Contact> contacts = Soql.Query<Contact>(""SELECT Id, Email, Phone FROM Contact WHERE Email = '*****@*****.**'"");
                            System.AssertEquals(contacts[0].Phone, ""555-1212"");
                        }

                        [Test]
                        public static void UpdatePhoneTestNotValidEmail()
                        {
                            Demo.UpdatePhone(""*****@*****.**"", ""555-1212"");
                            List<Contact> contacts = Soql.Query<Contact>(""SELECT Id, Email, Phone FROM Contact WHERE Email = '*****@*****.**'"");
                            System.AssertEquals(contacts.Size(), 0);
                        }
                    }
                }";

            var apexClasses = CSharpToApexHelpers.ConvertToApex(csharpCode);

            Assert.AreEqual(1, apexClasses.Length);
            CompareLineByLine(apexClasses[0],
                              @"@IsTest
                public class DemoTest
                {
                    //:NoApex [OneTimeSetUp]
                    //:NoApex public void NoApexSetup()
                    //:NoApex {
                    //:NoApex     new ApexSharp().Connect(""C:\\DevSharp\\connect.json"");
                    //:NoApex }
                    @TestSetup
                    public static void Setup()
                    {
                        Contact contactNew = new Contact();
                        contactNew.LastName = 'Jay';
                        contactNew.Email = '*****@*****.**';
                        insert contactNew;
                    }

                    //:NoApex [OneTimeSetUp]
                    //:NoApex public void noApexSetupAgain()
                    //:NoApex {
                    //:NoApex     new ApexSharp().Connect(""C:\\DevSharp\\connect.json"");
                    //:NoApex }
                    @IsTest
                    public static void UpdatePhoneTestValidEmail()
                    {
                        Demo.UpdatePhone('*****@*****.**', '555-1212');
                        List<Contact> contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = '*****@*****.**'];
                        System.AssertEquals(contacts[0].Phone, '555-1212');
                    }

                    @IsTest
                    public static void UpdatePhoneTestNotValidEmail()
                    {
                        Demo.UpdatePhone('*****@*****.**', '555-1212');
                        List<Contact> contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = '*****@*****.**'];
                        System.AssertEquals(contacts.Size(), 0);
                    }
                }");
        }
Ejemplo n.º 5
0
        public void DemoIsConverted()
        {
            var csharpCode =
                @"namespace ApexSharpDemo.ApexCode
                {
                    using Apex.ApexSharp;
                    using Apex.System;
                    using SObjects;

                    public class Demo
                    {
                        public Contact contact { get; set; }

                        public Demo()
                        {
                            contact = new Contact();
                        }

                        public PageReference Save()
                        {
                            try
                            {
                                Soql.Insert(contact);
                            }
                            catch (DmlException e)
                            {
                                ApexPages.AddMessages(e);
                            }

                            return null;
                        }

                        public static string UpdatePhone(string email, string newPhone)
                        {
                            List<Contact> contacts = GetContactByEMail(email);
                            if (contacts.IsEmpty())
                            {
                                return ""Not Found"";
                            }
                            else
                            {
                                contacts[0].Phone = newPhone;
                                UpdateContacts(contacts);
                                return ""Phone Number Updated"";
                            }
                        }

                        public static List<Contact> GetContactByEMail(string email)
                        {
                            List<Contact> contacts = Soql.Query<Contact>(""SELECT Id, Email, Phone FROM Contact WHERE Email = :email"", email);
                            return contacts;
                        }

                        public static List<Contact> GetContacts()
                        {
                            List<Contact> contacts = Soql.Query<Contact>(""SELECT Id, Email, Phone FROM Contact"");
                            return contacts;
                        }

                        public static void UpdateContacts(List<Contact> contacts)
                        {
                            Soql.Update(contacts);
                        }
                    }
                }";

            var apexClasses = CSharpToApexHelpers.ConvertToApex(csharpCode);

            Assert.AreEqual(1, apexClasses.Length);
            CompareLineByLine(apexClasses[0],
                              @"public class Demo
                {
                    public Contact contact { get; set; }

                    public Demo()
                    {
                        contact = new Contact();
                    }

                    public PageReference Save()
                    {
                        try
                        {
                            insert contact;
                        }
                        catch (DmlException e)
                        {
                            ApexPages.AddMessages(e);
                        }

                        return null;
                    }

                    public static String UpdatePhone(String email, String newPhone)
                    {
                        List<Contact> contacts = GetContactByEMail(email);
                        if (contacts.IsEmpty())
                        {
                            return 'Not Found';
                        }
                        else
                        {
                            contacts[0].Phone = newPhone;
                            UpdateContacts(contacts);
                            return 'Phone Number Updated';
                        }
                    }

                    public static List<Contact> GetContactByEMail(String email)
                    {
                        List<Contact> contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = :email];
                        return contacts;
                    }

                    public static List<Contact> GetContacts()
                    {
                        List<Contact> contacts = [SELECT Id, Email, Phone FROM Contact];
                        return contacts;
                    }

                    public static void UpdateContacts(List<Contact> contacts)
                    {
                        update contacts;
                    }
                }");
        }