コード例 #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(ApexSharpParser.ConvertApexToCSharp(ClassUnitTest_Original), ClassUnitTest_CSharp1);
     CompareLineByLine(ApexSharpParser.ToApex(ClassUnitTest_CSharp1)[0], ClassUnitTest_Converted);
 }
コード例 #2
0
 private void Check(string apexOriginal, string apexFormatted, string csharp)
 {
     Assert.Multiple(() =>
     {
         CompareLineByLine(ApexSharpParser.IndentApex(apexOriginal), apexFormatted);
         CompareLineByLine(ApexSharpParser.ConvertApexToCSharp(apexOriginal), csharp);
         CompareLineByLine(ApexSharpParser.ToApex(csharp)[0], apexFormatted);
     });
 }
コード例 #3
0
        public void CSharpHelperConvertsCSharpTextsToApex()
        {
            var csharp      = "class Test1 { public Test1(int x) { } } class Test2 : Test1 { private int x = 10; }";
            var apexClasses = ApexSharpParser.ToApex(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]);
        }
コード例 #4
0
 private string ToApex(string s) => ApexSharpParser.ToApex(s).FirstOrDefault();
コード例 #5
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);
                        }

                        [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 = ApexSharpParser.ToApex(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;
                    }

                    @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);
                    }
                }");
        }
コード例 #6
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 = ApexSharpParser.ToApex(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;
                    }
                }");
        }