diff --git a/ApexParser.Example/ApexCodeFormat/CustomApexCodeGeneratorTests.cs b/ApexParser.Example/ApexCodeFormat/CustomApexCodeGeneratorTests.cs index af67d29..8574909 100644 --- a/ApexParser.Example/ApexCodeFormat/CustomApexCodeGeneratorTests.cs +++ b/ApexParser.Example/ApexCodeFormat/CustomApexCodeGeneratorTests.cs @@ -19,21 +19,21 @@ protected void CompareLineByLine(string actual, string expected) for (int i = 0; i < Min(expectedList.Length, actualList.Length); i++) { - Assert.AreEqual(expectedList[i].Trim(), actualList[i].Trim()); + Assert.That(actualList[i].Trim(), Is.EqualTo(expectedList[i].Trim())); } if (Abs(expectedList.Length - actualList.Length) > 1) { - Assert.Fail("Too many difference in lines: expected {0}, actual {1}", expectedList.Length, actualList.Length); + Assert.Fail($"Too many difference in lines: expected {expectedList.Length}, actual {actualList.Length}"); } } [Test] public void TestUsingInvalidInput() { - Assert.AreEqual(string.Empty, CustomApexCodeGenerator.FormatApex(null)); - Assert.AreEqual(string.Empty, CustomApexCodeGenerator.FormatApex(" ")); - Assert.AreEqual(string.Empty, CustomApexCodeGenerator.GenerateApex(null)); + Assert.That(CustomApexCodeGenerator.FormatApex(null), Is.EqualTo(string.Empty)); + Assert.That(CustomApexCodeGenerator.FormatApex(" "), Is.EqualTo(string.Empty)); + Assert.That(CustomApexCodeGenerator.GenerateApex(null), Is.EqualTo(string.Empty)); } [Test] diff --git a/ApexParser.Example/ApexParser.Example.csproj b/ApexParser.Example/ApexParser.Example.csproj index 4c156fb..0f582dc 100644 --- a/ApexParser.Example/ApexParser.Example.csproj +++ b/ApexParser.Example/ApexParser.Example.csproj @@ -1,8 +1,8 @@ - + Exe - net5.0 + net10.0 false @@ -23,12 +23,12 @@ - - - - - - + + + + + + diff --git a/ApexParser.Example/ApexTestFind/ApexTestFinderTest.cs b/ApexParser.Example/ApexTestFind/ApexTestFinderTest.cs index b114dd8..1eb5ba9 100644 --- a/ApexParser.Example/ApexTestFind/ApexTestFinderTest.cs +++ b/ApexParser.Example/ApexTestFind/ApexTestFinderTest.cs @@ -14,174 +14,174 @@ public class ApexTestFinderTest public void GetApexClassesReferencingAGivenClassReturnsEmptyArrayForEmptyList() { var result = ApexTestFinder.GetApexClassesReferencingAGivenClass((string[])null, "Something"); - Assert.NotNull(result); - Assert.IsEmpty(result); + Assert.That(result, Is.Not.Null); + Assert.That(result, Is.Empty); result = ApexTestFinder.GetApexClassesReferencingAGivenClass(Array.Empty(), "Something"); - Assert.NotNull(result); - Assert.IsEmpty(result); + Assert.That(result, Is.Not.Null); + Assert.That(result, Is.Empty); } [Test] public void GetCSharpClassesReferencingAGivenClassReturnsEmptyArrayForEmptyList() { var result = ApexTestFinder.GetApexClassesReferencingAGivenClass((MemberDeclarationSyntax[])null, "Something"); - Assert.NotNull(result); - Assert.IsEmpty(result); + Assert.That(result, Is.Not.Null); + Assert.That(result, Is.Empty); result = ApexTestFinder.GetApexClassesReferencingAGivenClass(Array.Empty(), "Something"); - Assert.NotNull(result); - Assert.IsEmpty(result); + Assert.That(result, Is.Not.Null); + Assert.That(result, Is.Empty); } private static ClassDeclarationSyntax ParseClass(string apexClass) { var result = ApexSharpParser.GetApexAst(apexClass) as ClassDeclarationSyntax; - Assert.NotNull(result); + Assert.That(result, Is.Not.Null); return result; } [Test] public void IsTestClassReturnsFalseForNullOrEmptyClass() { - Assert.IsFalse(ApexTestFinder.IsTestClass(null)); + Assert.That(ApexTestFinder.IsTestClass(null), Is.False); var emptyClass = new ClassDeclarationSyntax { Identifier = "EmptyClass" }; - Assert.IsFalse(ApexTestFinder.IsTestClass(emptyClass)); + Assert.That(ApexTestFinder.IsTestClass(emptyClass), Is.False); var sampleClass = ParseClass("class SampleClass {}"); - Assert.IsFalse(ApexTestFinder.IsTestClass(sampleClass)); + Assert.That(ApexTestFinder.IsTestClass(sampleClass), Is.False); } [Test] public void IsTestClassReturnsTrueForClassDecoratedWithTestAttribute() { var testFixture = ParseClass("@TestFixture class NUnitSample {}"); - Assert.NotNull(testFixture); - Assert.IsTrue(ApexTestFinder.IsTestClass(testFixture)); + Assert.That(testFixture, Is.Not.Null); + Assert.That(ApexTestFinder.IsTestClass(testFixture), Is.True); testFixture = ParseClass("@Test class MSTestSample {}"); - Assert.NotNull(testFixture); - Assert.IsTrue(ApexTestFinder.IsTestClass(testFixture)); + Assert.That(testFixture, Is.Not.Null); + Assert.That(ApexTestFinder.IsTestClass(testFixture), Is.True); testFixture = ParseClass("@isTest class ApexSample {}"); - Assert.NotNull(testFixture); - Assert.IsTrue(ApexTestFinder.IsTestClass(testFixture)); + Assert.That(testFixture, Is.Not.Null); + Assert.That(ApexTestFinder.IsTestClass(testFixture), Is.True); testFixture = ParseClass("@Dummy class NotATestSample {}"); - Assert.NotNull(testFixture); - Assert.IsFalse(ApexTestFinder.IsTestClass(testFixture)); + Assert.That(testFixture, Is.Not.Null); + Assert.That(ApexTestFinder.IsTestClass(testFixture), Is.False); } [Test] public void TextReferencesAClass() { - Assert.IsFalse(ApexTestFinder.TextReferencesAClass(null, "Foo")); - Assert.IsFalse(ApexTestFinder.TextReferencesAClass(" ", "Foo")); - Assert.IsFalse(ApexTestFinder.TextReferencesAClass("Foo", null)); - Assert.IsFalse(ApexTestFinder.TextReferencesAClass("Foo", " ")); - Assert.IsTrue(ApexTestFinder.TextReferencesAClass("Foo.Bar()", "Foo")); - Assert.IsFalse(ApexTestFinder.TextReferencesAClass("NonFoo.Bar()", "Foo")); + Assert.That(ApexTestFinder.TextReferencesAClass(null, "Foo"), Is.False); + Assert.That(ApexTestFinder.TextReferencesAClass(" ", "Foo"), Is.False); + Assert.That(ApexTestFinder.TextReferencesAClass("Foo", null), Is.False); + Assert.That(ApexTestFinder.TextReferencesAClass("Foo", " "), Is.False); + Assert.That(ApexTestFinder.TextReferencesAClass("Foo.Bar()", "Foo"), Is.True); + Assert.That(ApexTestFinder.TextReferencesAClass("NonFoo.Bar()", "Foo"), Is.False); } [Test] public void HasReferencesToReturnsFalseForNullOrEmptyClass() { - Assert.IsFalse(ApexTestFinder.HasReferencesTo(null, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(null, "Foo"), Is.False); var emptyClass = new ClassDeclarationSyntax { Identifier = "EmptyClass" }; - Assert.IsFalse(ApexTestFinder.HasReferencesTo(emptyClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(emptyClass, "Foo"), Is.False); var sampleClass = ParseClass("class SampleClass {}"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] public void HasReferencesToReturnsTrueForStaticMethodCallReferences() { var sampleClass = ParseClass("class SampleClass { void Test() { Foo.Bar(); } }"); - Assert.IsTrue(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.True); // commented out sampleClass = ParseClass("class SampleClass { void Test() { /* Foo.Bar(); */ } }"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] public void HasReferencesToReturnsTrueForTheVariableDeclarations() { var sampleClass = ParseClass("class SampleClass { void Test() { Foo x; } }"); - Assert.IsTrue(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.True); // commented out sampleClass = ParseClass("class SampleClass { void Test() { /* Foo x; */ } }"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] public void HasReferencesToReturnsTrueForTheVariableInitializationExpressions() { var sampleClass = ParseClass("class SampleClass { void Test() { object x = new Foo(); } }"); - Assert.IsTrue(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.True); // commented out sampleClass = ParseClass("class SampleClass { void Test() { /* object x = new Foo(); */ } }"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] public void HasReferencesToReturnsTrueForTheConstructorExpressions() { var sampleClass = ParseClass("class SampleClass { void Test() { new Foo(); } }"); - Assert.IsTrue(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.True); // commented out sampleClass = ParseClass("class SampleClass { void Test() { /* new Foo(); */ } }"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] public void HasReferencesToReturnsTrueForTheFieldDeclarations() { var sampleClass = ParseClass("class SampleClass { Foo f; }"); - Assert.IsTrue(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.True); // commented out sampleClass = ParseClass("class SampleClass { /* Foo f; */ }"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] public void HasReferencesToReturnsTrueForTheFieldInitializationExpressions() { var sampleClass = ParseClass("class SampleClass { object x = new Foo(); }"); - Assert.IsTrue(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.True); // commented out sampleClass = ParseClass("class SampleClass { /* object x = new Foo(); */ }"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] public void HasReferencesToReturnsTrueForThePropertyDeclarations() { var sampleClass = ParseClass("class SampleClass { Foo f { get; } }"); - Assert.IsTrue(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.True); // commented out sampleClass = ParseClass("class SampleClass { /* Foo f { get; } */ }"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] public void HasReferencesToReturnsTrueForTheMethodDeclarations() { var sampleClass = ParseClass("class SampleClass { Foo getSomething() { } }"); - Assert.IsTrue(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.True); // commented out sampleClass = ParseClass("class SampleClass { /* Foo getSomething() { } */ }"); - Assert.IsFalse(ApexTestFinder.HasReferencesTo(sampleClass, "Foo")); + Assert.That(ApexTestFinder.HasReferencesTo(sampleClass, "Foo"), Is.False); } [Test] @@ -195,8 +195,8 @@ public void GetApexClassesReferencingAGivenClassReturnsClassNames() "@isTest class NotMyClass { void Test() { FooBar x = new FooBar(); } }", }, "Foo"); - Assert.AreEqual(1, classes.Length); - Assert.AreEqual("MyClass", classes[0]); + Assert.That(classes.Length, Is.EqualTo(1)); + Assert.That(classes[0], Is.EqualTo("MyClass")); } [Test] @@ -206,8 +206,8 @@ public void GetAllTextClassesReturnsAllTextClassesAsExpected() var subfolder = Path.Combine(location, "..", "..", "..", "ApexClasses"); var classes = ApexTestFinder.GetAllTestClasses(subfolder, "Dx"); - Assert.AreEqual(1, classes.Count); - Assert.IsTrue(classes.Contains("DxTestTwo")); + Assert.That(classes.Count, Is.EqualTo(1)); + Assert.That(classes.Contains("DxTestTwo"), Is.True); } private static bool IsTestClass(MemberDeclarationSyntax ast) @@ -220,21 +220,21 @@ private static bool IsTestClass(MemberDeclarationSyntax ast) public void DetectTestClassExample1() { var ast = ApexSharpParser.GetApexAst("class Example1 {}"); - Assert.IsFalse(IsTestClass(ast)); + Assert.That(IsTestClass(ast), Is.False); } [Test] public void DetectTestClassExample2() { var ast = ApexSharpParser.GetApexAst("@isTest class Example2 {}"); - Assert.IsTrue(IsTestClass(ast)); + Assert.That(IsTestClass(ast), Is.True); } [Test] public void DetectTestClassExample3() { var ast = ApexSharpParser.GetApexAst("@isTest enum Example2 { A, B, C }"); - Assert.IsFalse(IsTestClass(ast)); + Assert.That(IsTestClass(ast), Is.False); } } } diff --git a/ApexParser.Example/CaseClean/ApexCleanCodeGenTests.cs b/ApexParser.Example/CaseClean/ApexCleanCodeGenTests.cs index f87b94a..858dff8 100644 --- a/ApexParser.Example/CaseClean/ApexCleanCodeGenTests.cs +++ b/ApexParser.Example/CaseClean/ApexCleanCodeGenTests.cs @@ -14,12 +14,12 @@ public class ApexCleanCodeGenTests [Test] public void NormalizeWorksAsExpected() { - Assert.AreEqual(null, Normalize(null)); - Assert.AreEqual(string.Empty, Normalize(string.Empty)); - Assert.AreEqual(" ", Normalize(" ")); - Assert.AreEqual("FooBar+123", Normalize("FooBar+123")); - Assert.AreEqual("AbstractRecordField", Normalize("abstractrecordfield")); - Assert.AreEqual("getContext or fooBar + setRecord", Normalize("GetContext or fooBar + setrecord")); + Assert.That(Normalize(null), Is.EqualTo(null)); + Assert.That(Normalize(string.Empty), Is.EqualTo(string.Empty)); + Assert.That(Normalize(" "), Is.EqualTo(" ")); + Assert.That(Normalize("FooBar+123"), Is.EqualTo("FooBar+123")); + Assert.That(Normalize("abstractrecordfield"), Is.EqualTo("AbstractRecordField")); + Assert.That(Normalize("GetContext or fooBar + setrecord"), Is.EqualTo("getContext or fooBar + setRecord")); } [Test] @@ -43,8 +43,8 @@ public static void testPluckDecimals() var parsed = ApexSharpParser.GetApexAst(apex); var generated = ApexCleanCodeGen.GenerateApex(parsed); - Assert.NotNull(generated); - Assert.AreEqual(@"class Something + Assert.That(generated, Is.Not.Null); + Assert.That(generated, Is.EqualTo(@"class Something { @IsTest public static void testPluckDecimals() @@ -58,7 +58,7 @@ public static void testPluckDecimals() System.debug(150.0, revenues[3]); } } -", generated); +")); } } } diff --git a/ApexParser.Example/FindRelatedClasses/RelatedClassHelperTests.cs b/ApexParser.Example/FindRelatedClasses/RelatedClassHelperTests.cs index 5f5809c..6c6f10c 100644 --- a/ApexParser.Example/FindRelatedClasses/RelatedClassHelperTests.cs +++ b/ApexParser.Example/FindRelatedClasses/RelatedClassHelperTests.cs @@ -11,16 +11,16 @@ public class RelatedClassHelperTests [Test] public void InvalidRelatedClasses() { - Assert.DoesNotThrow(() => + Assert.That(() => { - Assert.IsFalse(RelatedClassHelper.IsRelated(null, null)); - Assert.IsFalse(RelatedClassHelper.IsRelated(null, string.Empty)); - Assert.IsFalse(RelatedClassHelper.IsRelated(string.Empty, null)); - Assert.IsFalse(RelatedClassHelper.IsRelated(string.Empty, string.Empty)); - Assert.IsFalse(RelatedClassHelper.IsRelated(null, " ")); - Assert.IsFalse(RelatedClassHelper.IsRelated(" ", null)); - Assert.IsFalse(RelatedClassHelper.IsRelated(" ", " ")); - }); + Assert.That(RelatedClassHelper.IsRelated(null, null), Is.False); + Assert.That(RelatedClassHelper.IsRelated(null, string.Empty), Is.False); + Assert.That(RelatedClassHelper.IsRelated(string.Empty, null), Is.False); + Assert.That(RelatedClassHelper.IsRelated(string.Empty, string.Empty), Is.False); + Assert.That(RelatedClassHelper.IsRelated(null, " "), Is.False); + Assert.That(RelatedClassHelper.IsRelated(" ", null), Is.False); + Assert.That(RelatedClassHelper.IsRelated(" ", " "), Is.False); + }, Throws.Nothing); } private string SampleClass { get; } = @" @@ -42,28 +42,28 @@ public SomethingGreat(WhatElse x) { public void RelatedClassUseCases() { // positives - Assert.IsTrue(RelatedClassHelper.IsRelated(SampleClass, "GreatUtility")); // variable - Assert.IsTrue(RelatedClassHelper.IsRelated(SampleClass, "CoolStuff")); // expression - Assert.IsTrue(RelatedClassHelper.IsRelated(SampleClass, "Object")); // variable - Assert.IsTrue(RelatedClassHelper.IsRelated(SampleClass, "Something")); // property - Assert.IsTrue(RelatedClassHelper.IsRelated(SampleClass, "AwesomeStuff")); // expression - Assert.IsTrue(RelatedClassHelper.IsRelated(SampleClass, "ThatsPerfect")); // annotation - Assert.IsTrue(RelatedClassHelper.IsRelated(SampleClass, "WhatElse")); // parameter + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "GreatUtility"), Is.True); // variable + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "CoolStuff"), Is.True); // expression + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "Object"), Is.True); // variable + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "Something"), Is.True); // property + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "AwesomeStuff"), Is.True); // expression + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "ThatsPerfect"), Is.True); // annotation + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "WhatElse"), Is.True); // parameter // incomplete matches - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "Great")); // partial name - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "Utility")); // partial name - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "Awesome")); // partial name - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "Perfect")); // partial name + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "Great"), Is.False); // partial name + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "Utility"), Is.False); // partial name + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "Awesome"), Is.False); // partial name + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "Perfect"), Is.False); // partial name // negatives - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "IsTest")); // string constant - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "global")); // keyword - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "Hello")); // string constant - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "BadStuff")); // commented out - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "main")); // method name - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "SomethingGreat")); // itself - Assert.IsFalse(RelatedClassHelper.IsRelated(SampleClass, "Else")); // property name + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "IsTest"), Is.False); // string constant + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "global"), Is.False); // keyword + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "Hello"), Is.False); // string constant + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "BadStuff"), Is.False); // commented out + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "main"), Is.False); // method name + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "SomethingGreat"), Is.False); // itself + Assert.That(RelatedClassHelper.IsRelated(SampleClass, "Else"), Is.False); // property name } } -} +} \ No newline at end of file diff --git a/ApexSharp.ApexParser.Tests/ApexSharp.ApexParser.Tests.csproj b/ApexSharp.ApexParser.Tests/ApexSharp.ApexParser.Tests.csproj index 19abd2d..453fb19 100644 --- a/ApexSharp.ApexParser.Tests/ApexSharp.ApexParser.Tests.csproj +++ b/ApexSharp.ApexParser.Tests/ApexSharp.ApexParser.Tests.csproj @@ -11,7 +11,7 @@ Apex, Parser, Roslyn https://github.com/ApexSharp/ApexParser Apex, Parser, Roslyn - net5.0 + net10.0 @@ -33,10 +33,10 @@ - - - - + + + + diff --git a/ApexSharp.ApexParser.Tests/CSharpParserTests.cs b/ApexSharp.ApexParser.Tests/CSharpParserTests.cs index b2eafec..647b853 100644 --- a/ApexSharp.ApexParser.Tests/CSharpParserTests.cs +++ b/ApexSharp.ApexParser.Tests/CSharpParserTests.cs @@ -36,10 +36,10 @@ static void Main(string[] args) } }"); - Assert.NotNull(unit); + Assert.That(unit, Is.Not.Null); var txt = CSharpToApexHelpers.ConvertToCSharp(unit); - Assert.NotNull(txt); + Assert.That(txt, Is.Not.Null); } [Test] @@ -67,7 +67,7 @@ static void Main(string[] args) unit.Accept(walker); var tree = walker.ToString(); - Assert.False(string.IsNullOrWhiteSpace(tree)); + Assert.That(string.IsNullOrWhiteSpace(tree), Is.False); } [Test] @@ -75,7 +75,7 @@ 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); + Assert.That(apexClasses.Length, Is.EqualTo(2)); CompareLineByLine( @"class Test1 @@ -101,7 +101,7 @@ class Test2 : Test1 { private int x = 10; } enum SomeEnum { None, Unknown, Default }"; var apexClasses = CSharpToApexHelpers.ConvertToApexCode(csharp); - Assert.AreEqual(3, apexClasses.Count); + Assert.That(apexClasses.Count, Is.EqualTo(3)); CompareLineByLine( @"class Test1 diff --git a/ApexSharp.ApexParser.Tests/GitHubHelper.cs b/ApexSharp.ApexParser.Tests/GitHubHelper.cs index 3b8fac2..e6312e8 100644 --- a/ApexSharp.ApexParser.Tests/GitHubHelper.cs +++ b/ApexSharp.ApexParser.Tests/GitHubHelper.cs @@ -21,24 +21,29 @@ public static Dictionary GetCodeFromGitFolder(string gitResource { Dictionary codeFromGit = new Dictionary(); - var client = new RestClient("https://api.github.com/"); - var request = new RestRequest(gitResource, Method.GET); - var response = client.Execute>(request); + var options = new RestClientOptions("https://api.github.com/"); + var client = new RestClient(options); + var request = new RestRequest(gitResource, Method.Get); + var response = client.ExecuteAsync>(request).GetAwaiter().GetResult(); if (response.StatusCode != System.Net.HttpStatusCode.OK) { Assert.Warn($"Cannot download the code from url: {gitResource}. Error code: {response.StatusCode}"); + return codeFromGit; } - List newFilteredList = response.Data.Where(x => x?.Name?.EndsWith(extension) ?? false).ToList(); + List newFilteredList = response.Data?.Where(x => x?.Name?.EndsWith(extension) ?? false).ToList() ?? new List(); foreach (var gitHubFile in newFilteredList) { - client = new RestClient(gitHubFile.download_url); - request = new RestRequest(Method.GET); - var code = client.Execute(request).Content; + var fileRequest = new RestRequest(gitHubFile.download_url, Method.Get); + var fileResponse = client.ExecuteAsync(fileRequest).GetAwaiter().GetResult(); - codeFromGit.Add(gitHubFile.download_url, code); + + if (fileResponse.IsSuccessful) + { + codeFromGit.Add(gitHubFile.download_url, fileResponse.Content); + } } return codeFromGit; diff --git a/ApexSharp.ApexParser.Tests/Parser/ApexGrammarTests.cs b/ApexSharp.ApexParser.Tests/Parser/ApexGrammarTests.cs index 31a7e6d..fe3a5ef 100644 --- a/ApexSharp.ApexParser.Tests/Parser/ApexGrammarTests.cs +++ b/ApexSharp.ApexParser.Tests/Parser/ApexGrammarTests.cs @@ -19,43 +19,43 @@ public class ApexGrammarTests [Test] public void KindPropertyCorrespondsToTheNodeType() { - Assert.AreEqual(SyntaxType.Accessor, new AccessorDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.Annotation, new AnnotationSyntax().Kind); - Assert.AreEqual(SyntaxType.Block, new BlockSyntax().Kind); - Assert.AreEqual(SyntaxType.BreakStatement, new BreakStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.Catch, new CatchClauseSyntax().Kind); - Assert.AreEqual(SyntaxType.Class, new ClassDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.ClassInitializer, new ClassInitializerSyntax().Kind); - Assert.AreEqual(SyntaxType.ClassMember, new MemberDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.Constructor, new ConstructorDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.DeleteStatement, new DeleteStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.DoStatement, new DoStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.Enum, new EnumDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.EnumMember, new EnumMemberDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.Expression, new ExpressionSyntax().Kind); - Assert.AreEqual(SyntaxType.Field, new FieldDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.FieldDeclarator, new FieldDeclaratorSyntax().Kind); - Assert.AreEqual(SyntaxType.Finally, new FinallyClauseSyntax().Kind); - Assert.AreEqual(SyntaxType.ForEachStatement, new ForEachStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.ForStatement, new ForStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.IfStatement, new IfStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.InsertStatement, new InsertStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.Interface, new InterfaceDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.Method, new MethodDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.Parameter, new ParameterSyntax("i", "i").Kind); - Assert.AreEqual(SyntaxType.Property, new PropertyDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.RunAsStatement, new RunAsStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.Statement, new StatementSyntax().Kind); - Assert.AreEqual(SyntaxType.SwitchStatement, new SwitchStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.TryStatement, new TryStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.Type, new TypeSyntax().Kind); - Assert.AreEqual(SyntaxType.UpdateStatement, new UpdateStatementSyntax().Kind); - Assert.AreEqual(SyntaxType.VariableDeclaration, new VariableDeclarationSyntax().Kind); - Assert.AreEqual(SyntaxType.VariableDeclarator, new VariableDeclaratorSyntax().Kind); - Assert.AreEqual(SyntaxType.WhenElseClause, new WhenElseClauseSyntax().Kind); - Assert.AreEqual(SyntaxType.WhenExpressionsClause, new WhenExpressionsClauseSyntax().Kind); - Assert.AreEqual(SyntaxType.WhenTypeClause, new WhenTypeClauseSyntax().Kind); - Assert.AreEqual(SyntaxType.WhileStatement, new WhileStatementSyntax().Kind); + Assert.That(new AccessorDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.Accessor)); + Assert.That(new AnnotationSyntax().Kind, Is.EqualTo(SyntaxType.Annotation)); + Assert.That(new BlockSyntax().Kind, Is.EqualTo(SyntaxType.Block)); + Assert.That(new BreakStatementSyntax().Kind, Is.EqualTo(SyntaxType.BreakStatement)); + Assert.That(new CatchClauseSyntax().Kind, Is.EqualTo(SyntaxType.Catch)); + Assert.That(new ClassDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.Class)); + Assert.That(new ClassInitializerSyntax().Kind, Is.EqualTo(SyntaxType.ClassInitializer)); + Assert.That(new MemberDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.ClassMember)); + Assert.That(new ConstructorDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.Constructor)); + Assert.That(new DeleteStatementSyntax().Kind, Is.EqualTo(SyntaxType.DeleteStatement)); + Assert.That(new DoStatementSyntax().Kind, Is.EqualTo(SyntaxType.DoStatement)); + Assert.That(new EnumDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.Enum)); + Assert.That(new EnumMemberDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.EnumMember)); + Assert.That(new ExpressionSyntax().Kind, Is.EqualTo(SyntaxType.Expression)); + Assert.That(new FieldDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.Field)); + Assert.That(new FieldDeclaratorSyntax().Kind, Is.EqualTo(SyntaxType.FieldDeclarator)); + Assert.That(new FinallyClauseSyntax().Kind, Is.EqualTo(SyntaxType.Finally)); + Assert.That(new ForEachStatementSyntax().Kind, Is.EqualTo(SyntaxType.ForEachStatement)); + Assert.That(new ForStatementSyntax().Kind, Is.EqualTo(SyntaxType.ForStatement)); + Assert.That(new IfStatementSyntax().Kind, Is.EqualTo(SyntaxType.IfStatement)); + Assert.That(new InsertStatementSyntax().Kind, Is.EqualTo(SyntaxType.InsertStatement)); + Assert.That(new InterfaceDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.Interface)); + Assert.That(new MethodDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.Method)); + Assert.That(new ParameterSyntax("i", "i").Kind, Is.EqualTo(SyntaxType.Parameter)); + Assert.That(new PropertyDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.Property)); + Assert.That(new RunAsStatementSyntax().Kind, Is.EqualTo(SyntaxType.RunAsStatement)); + Assert.That(new StatementSyntax().Kind, Is.EqualTo(SyntaxType.Statement)); + Assert.That(new SwitchStatementSyntax().Kind, Is.EqualTo(SyntaxType.SwitchStatement)); + Assert.That(new TryStatementSyntax().Kind, Is.EqualTo(SyntaxType.TryStatement)); + Assert.That(new TypeSyntax().Kind, Is.EqualTo(SyntaxType.Type)); + Assert.That(new UpdateStatementSyntax().Kind, Is.EqualTo(SyntaxType.UpdateStatement)); + Assert.That(new VariableDeclarationSyntax().Kind, Is.EqualTo(SyntaxType.VariableDeclaration)); + Assert.That(new VariableDeclaratorSyntax().Kind, Is.EqualTo(SyntaxType.VariableDeclarator)); + Assert.That(new WhenElseClauseSyntax().Kind, Is.EqualTo(SyntaxType.WhenElseClause)); + Assert.That(new WhenExpressionsClauseSyntax().Kind, Is.EqualTo(SyntaxType.WhenExpressionsClause)); + Assert.That(new WhenTypeClauseSyntax().Kind, Is.EqualTo(SyntaxType.WhenTypeClause)); + Assert.That(new WhileStatementSyntax().Kind, Is.EqualTo(SyntaxType.WhileStatement)); } [Test] @@ -63,356 +63,356 @@ public void DebuggerProxyClassReturnsToString() { var node = new ParameterSyntax("i", "i"); var proxy = new BaseSyntaxDebuggerProxy(node); - Assert.NotNull(proxy.NodeType); - Assert.NotNull(proxy.ApexCode); - Assert.NotNull(proxy.ToString()); - Assert.NotNull(node.ToString()); + Assert.That(proxy.NodeType, Is.Not.Null); + Assert.That(proxy.ApexCode, Is.Not.Null); + Assert.That(proxy.ToString(), Is.Not.Null); + Assert.That(node.ToString(), Is.Not.Null); } [Test] public void IdentifierIsALetterFollowedByALetterOrDigitOrUnderscore() { // every test case should include positive examples - Assert.AreEqual("c", Apex.Identifier.Parse("c")); - Assert.AreEqual("abc", Apex.Identifier.Parse(" abc ")); - Assert.AreEqual("Test123", Apex.Identifier.Parse("Test123")); - Assert.AreEqual("Hello_cruel_world", Apex.Identifier.Parse("Hello_cruel_world")); + Assert.That(Apex.Identifier.Parse("c"), Is.EqualTo("c")); + Assert.That(Apex.Identifier.Parse(" abc "), Is.EqualTo("abc")); + Assert.That(Apex.Identifier.Parse("Test123"), Is.EqualTo("Test123")); + Assert.That(Apex.Identifier.Parse("Hello_cruel_world"), Is.EqualTo("Hello_cruel_world")); // and negative ones - Assert.Throws(() => Apex.Identifier.Parse("1")); + Assert.That(() => Apex.Identifier.Parse("1"), Throws.TypeOf()); } [Test] public void QualifiedIdentifierIsAnStreamOfIdentifiersDelimitedByDots() { var qi = Apex.QualifiedIdentifier.Parse(" System.debug ").ToList(); - Assert.AreEqual(2, qi.Count); - Assert.AreEqual("System", qi[0]); - Assert.AreEqual("debug", qi[1]); + Assert.That(qi.Count, Is.EqualTo(2)); + Assert.That(qi[0], Is.EqualTo("System")); + Assert.That(qi[1], Is.EqualTo("debug")); qi = Apex.QualifiedIdentifier.Parse(" System.Exception ").ToList(); - Assert.AreEqual(2, qi.Count); - Assert.AreEqual("System", qi[0]); - Assert.AreEqual("Exception", qi[1]); + Assert.That(qi.Count, Is.EqualTo(2)); + Assert.That(qi[0], Is.EqualTo("System")); + Assert.That(qi[1], Is.EqualTo("Exception")); qi = Apex.QualifiedIdentifier.Parse(@" System . Collections . Generic ").ToList(); - Assert.AreEqual(3, qi.Count); - Assert.AreEqual("System", qi[0]); - Assert.AreEqual("Collections", qi[1]); - Assert.AreEqual("Generic", qi[2]); + Assert.That(qi.Count, Is.EqualTo(3)); + Assert.That(qi[0], Is.EqualTo("System")); + Assert.That(qi[1], Is.EqualTo("Collections")); + Assert.That(qi[2], Is.EqualTo("Generic")); } [Test] public void KeywordIsNotAnIdentifier() { - Assert.Throws(() => Apex.Identifier.Parse("class")); - Assert.Throws(() => Apex.Identifier.Parse("public")); - Assert.Throws(() => Apex.Identifier.Parse("private")); - Assert.Throws(() => Apex.Identifier.Parse("static")); + Assert.That(() => Apex.Identifier.Parse("class"), Throws.TypeOf()); + Assert.That(() => Apex.Identifier.Parse("public"), Throws.TypeOf()); + Assert.That(() => Apex.Identifier.Parse("private"), Throws.TypeOf()); + Assert.That(() => Apex.Identifier.Parse("static"), Throws.TypeOf()); } [Test] public void KeywordIsReturnedInItsNormalizedRepresentation() { - Assert.AreEqual(ApexKeywords.Void, Apex.Keyword(ApexKeywords.Void).Parse("voiD")); - Assert.AreEqual(ApexKeywords.TestMethod, Apex.Keyword(ApexKeywords.TestMethod).Parse("TeStMeThOD")); - Assert.AreEqual(ApexKeywords.Last90Days, Apex.Keyword(ApexKeywords.Last90Days).Parse("LAST_90_days")); + Assert.That(Apex.Keyword(ApexKeywords.Void).Parse("voiD"), Is.EqualTo(ApexKeywords.Void)); + Assert.That(Apex.Keyword(ApexKeywords.TestMethod).Parse("TeStMeThOD"), Is.EqualTo(ApexKeywords.TestMethod)); + Assert.That(Apex.Keyword(ApexKeywords.Last90Days).Parse("LAST_90_days"), Is.EqualTo(ApexKeywords.Last90Days)); } [Test] public void AnnotationBeginsWithAtSign() { var ann = Apex.Annotation.Parse(" @isTest "); - Assert.AreEqual("IsTest", ann.Identifier); - Assert.IsNull(ann.Parameters); + Assert.That(ann.Identifier, Is.EqualTo("IsTest")); + Assert.That(ann.Parameters, Is.Null); - Assert.Throws(() => Apex.Annotation.Parse(" isTest ")); + Assert.That(() => Apex.Annotation.Parse(" isTest "), Throws.TypeOf()); } [Test] public void AnnotationsCanHaveParameters() { var ann = Apex.Annotation.Parse(" @isTest(SeeAllData = true) "); - Assert.AreEqual("IsTest", ann.Identifier); - Assert.AreEqual("SeeAllData = true", ann.Parameters); + Assert.That(ann.Identifier, Is.EqualTo("IsTest")); + Assert.That(ann.Parameters, Is.EqualTo("SeeAllData = true")); - Assert.Throws(() => Apex.Annotation.Parse(" @class ")); + Assert.That(() => Apex.Annotation.Parse(" @class "), Throws.TypeOf()); } [Test] public void KnownAnnotationsHaveTheirCanonicalForm() { var ann = Apex.Annotation.Parse(" @future "); - Assert.AreEqual("Future", ann.Identifier); - Assert.IsNull(ann.Parameters); + Assert.That(ann.Identifier, Is.EqualTo("Future")); + Assert.That(ann.Parameters, Is.Null); ann = Apex.Annotation.Parse(" @unknownAnnotation "); - Assert.AreEqual("unknownAnnotation", ann.Identifier); - Assert.IsNull(ann.Parameters); + Assert.That(ann.Identifier, Is.EqualTo("unknownAnnotation")); + Assert.That(ann.Parameters, Is.Null); - Assert.Throws(() => Apex.Annotation.Parse(" @public ")); + Assert.That(() => Apex.Annotation.Parse(" @public "), Throws.TypeOf()); } [Test] public void SystemTypeIsOneOfSpecificKeywords() { - Assert.AreEqual(ApexKeywords.Void, Apex.SystemType.Parse(" void ").Identifier); - Assert.AreEqual(ApexKeywords.Int, Apex.SystemType.Parse(" int ").Identifier); - Assert.AreEqual(ApexKeywords.Boolean, Apex.SystemType.Parse(" boolean ").Identifier); + Assert.That(Apex.SystemType.Parse(" void ").Identifier, Is.EqualTo(ApexKeywords.Void)); + Assert.That(Apex.SystemType.Parse(" int ").Identifier, Is.EqualTo(ApexKeywords.Int)); + Assert.That(Apex.SystemType.Parse(" boolean ").Identifier, Is.EqualTo(ApexKeywords.Boolean)); // these keywords aren't types - Assert.Throws(() => Apex.SystemType.Parse("class")); - Assert.Throws(() => Apex.SystemType.Parse("sharing")); + Assert.That(() => Apex.SystemType.Parse("class"), Throws.TypeOf()); + Assert.That(() => Apex.SystemType.Parse("sharing"), Throws.TypeOf()); } [Test] public void SystemTypesAreCaseInsensitive() { - Assert.AreEqual(ApexKeywords.Void, Apex.SystemType.Parse(" Void ").Identifier); - Assert.AreEqual(ApexKeywords.Int, Apex.SystemType.Parse(" INT ").Identifier); - Assert.AreEqual(ApexKeywords.Boolean, Apex.SystemType.Parse(" BooLeAn ").Identifier); + Assert.That(Apex.SystemType.Parse(" Void ").Identifier, Is.EqualTo(ApexKeywords.Void)); + Assert.That(Apex.SystemType.Parse(" INT ").Identifier, Is.EqualTo(ApexKeywords.Int)); + Assert.That(Apex.SystemType.Parse(" BooLeAn ").Identifier, Is.EqualTo(ApexKeywords.Boolean)); // these keywords aren't types - Assert.Throws(() => Apex.SystemType.Parse("class")); - Assert.Throws(() => Apex.SystemType.Parse("sharing")); + Assert.That(() => Apex.SystemType.Parse("class"), Throws.TypeOf()); + Assert.That(() => Apex.SystemType.Parse("sharing"), Throws.TypeOf()); } [Test] public void NonGenericTypeIsAPrimitiveTypeOrAnIdentifier() { - Assert.AreEqual(ApexKeywords.Void, Apex.NonGenericType.Parse(" void ").Identifier); - Assert.AreEqual(ApexKeywords.String, Apex.NonGenericType.Parse(" String ").Identifier); - Assert.AreEqual(ApexKeywords.Boolean, Apex.NonGenericType.Parse(" Boolean ").Identifier); - Assert.AreEqual(ApexKeywords.Integer, Apex.NonGenericType.Parse(" Integer ").Identifier); - Assert.AreEqual(ApexKeywords.ID, Apex.NonGenericType.Parse(" Id ").Identifier); - Assert.AreEqual(ApexKeywords.Int, Apex.NonGenericType.Parse(" int ").Identifier); + Assert.That(Apex.NonGenericType.Parse(" void ").Identifier, Is.EqualTo(ApexKeywords.Void)); + Assert.That(Apex.NonGenericType.Parse(" String ").Identifier, Is.EqualTo(ApexKeywords.String)); + Assert.That(Apex.NonGenericType.Parse(" Boolean ").Identifier, Is.EqualTo(ApexKeywords.Boolean)); + Assert.That(Apex.NonGenericType.Parse(" Integer ").Identifier, Is.EqualTo(ApexKeywords.Integer)); + Assert.That(Apex.NonGenericType.Parse(" Id ").Identifier, Is.EqualTo(ApexKeywords.ID)); + Assert.That(Apex.NonGenericType.Parse(" int ").Identifier, Is.EqualTo(ApexKeywords.Int)); // not types or non-generic types - Assert.Throws(() => Apex.SystemType.Parse("class")); - Assert.Throws(() => Apex.SystemType.End().Parse("Map")); + Assert.That(() => Apex.SystemType.Parse("class"), Throws.TypeOf()); + Assert.That(() => Apex.SystemType.End().Parse("Map"), Throws.TypeOf()); } [Test] public void TypeParametersIsACommaSeparatedListOfTypeReferencesEnclosedInAngularBraces() { var tp = Apex.TypeParameters.Parse("").ToList(); - Assert.AreEqual(1, tp.Count); - Assert.AreEqual("String", tp[0].Identifier); + Assert.That(tp.Count, Is.EqualTo(1)); + Assert.That(tp[0].Identifier, Is.EqualTo("String")); tp = Apex.TypeParameters.Parse(" < Sys.Collections.Hashtable, string, int, void, Sys.Character > ").ToList(); - Assert.AreEqual(5, tp.Count); + Assert.That(tp.Count, Is.EqualTo(5)); var type = tp[0]; - Assert.AreEqual(2, type.Namespaces.Count); - Assert.AreEqual("Sys", type.Namespaces[0]); - Assert.AreEqual("Collections", type.Namespaces[1]); - Assert.AreEqual("Hashtable", type.Identifier); + Assert.That(type.Namespaces.Count, Is.EqualTo(2)); + Assert.That(type.Namespaces[0], Is.EqualTo("Sys")); + Assert.That(type.Namespaces[1], Is.EqualTo("Collections")); + Assert.That(type.Identifier, Is.EqualTo("Hashtable")); - Assert.AreEqual("String", tp[1].Identifier); - Assert.AreEqual("int", tp[2].Identifier); - Assert.AreEqual("void", tp[3].Identifier); + Assert.That(tp[1].Identifier, Is.EqualTo("String")); + Assert.That(tp[2].Identifier, Is.EqualTo("int")); + Assert.That(tp[3].Identifier, Is.EqualTo("void")); type = tp[4]; - Assert.AreEqual(1, type.Namespaces.Count); - Assert.AreEqual("Sys", type.Namespaces.Single()); - Assert.AreEqual("Character", type.Identifier); + Assert.That(type.Namespaces.Count, Is.EqualTo(1)); + Assert.That(type.Namespaces.Single(), Is.EqualTo("Sys")); + Assert.That(type.Identifier, Is.EqualTo("Character")); // not types or non-generic types - Assert.Throws(() => Apex.TypeParameters.Parse("string")); - Assert.Throws(() => Apex.TypeParameters.Parse("Map")); + Assert.That(() => Apex.TypeParameters.Parse("string"), Throws.TypeOf()); + Assert.That(() => Apex.TypeParameters.Parse("Map"), Throws.TypeOf()); } [Test] public void TypeReferenceIsAGenericOrNonGenericType() { var tr = Apex.TypeReference.Parse(" String "); - Assert.AreEqual("String", tr.Identifier); - Assert.False(tr.Namespaces.Any()); - Assert.False(tr.TypeParameters.Any()); - Assert.False(tr.IsArray); + Assert.That(tr.Identifier, Is.EqualTo("String")); + Assert.That(tr.Namespaces.Any(), Is.False); + Assert.That(tr.TypeParameters.Any(), Is.False); + Assert.That(tr.IsArray, Is.False); tr = Apex.TypeReference.Parse("List"); - Assert.AreEqual("List", tr.Identifier); - Assert.False(tr.Namespaces.Any()); - Assert.False(tr.IsArray); + Assert.That(tr.Identifier, Is.EqualTo("List")); + Assert.That(tr.Namespaces.Any(), Is.False); + Assert.That(tr.IsArray, Is.False); - Assert.AreEqual(1, tr.TypeParameters.Count); - Assert.AreEqual("String", tr.TypeParameters[0].Identifier); - Assert.False(tr.TypeParameters[0].Namespaces.Any()); - Assert.False(tr.IsArray); + Assert.That(tr.TypeParameters.Count, Is.EqualTo(1)); + Assert.That(tr.TypeParameters[0].Identifier, Is.EqualTo("String")); + Assert.That(tr.TypeParameters[0].Namespaces.Any(), Is.False); + Assert.That(tr.IsArray, Is.False); tr = Apex.TypeReference.Parse(" Sys.Collections.MyMap < Sys.String, List >"); - Assert.AreEqual("MyMap", tr.Identifier); - Assert.AreEqual(2, tr.Namespaces.Count); - Assert.AreEqual("Sys", tr.Namespaces[0]); - Assert.AreEqual("Collections", tr.Namespaces[1]); - Assert.False(tr.IsArray); + Assert.That(tr.Identifier, Is.EqualTo("MyMap")); + Assert.That(tr.Namespaces.Count, Is.EqualTo(2)); + Assert.That(tr.Namespaces[0], Is.EqualTo("Sys")); + Assert.That(tr.Namespaces[1], Is.EqualTo("Collections")); + Assert.That(tr.IsArray, Is.False); - Assert.AreEqual(2, tr.TypeParameters.Count); + Assert.That(tr.TypeParameters.Count, Is.EqualTo(2)); var tp = tr.TypeParameters[0]; - Assert.AreEqual("String", tp.Identifier); - Assert.AreEqual(1, tp.Namespaces.Count); - Assert.False(tp.IsArray); + Assert.That(tp.Identifier, Is.EqualTo("String")); + Assert.That(tp.Namespaces.Count, Is.EqualTo(1)); + Assert.That(tp.IsArray, Is.False); tr = Apex.TypeReference.Parse(" string [ ] "); - Assert.AreEqual("String", tr.Identifier); - Assert.False(tr.Namespaces.Any()); - Assert.True(tr.IsArray); + Assert.That(tr.Identifier, Is.EqualTo("String")); + Assert.That(tr.Namespaces.Any(), Is.False); + Assert.That(tr.IsArray, Is.True); tr = Apex.TypeReference.Parse(" List []"); - Assert.AreEqual("List", tr.Identifier); - Assert.False(tr.Namespaces.Any()); - Assert.True(tr.IsArray); + Assert.That(tr.Identifier, Is.EqualTo("List")); + Assert.That(tr.Namespaces.Any(), Is.False); + Assert.That(tr.IsArray, Is.True); tr = Apex.TypeReference.Parse(" System.TypeException "); - Assert.AreEqual("TypeException", tr.Identifier); + Assert.That(tr.Identifier, Is.EqualTo("TypeException")); } [Test] public void ParameterDeclarationIsTypeAndNamePair() { var pd = Apex.ParameterDeclaration.Parse(" int a"); - Assert.AreEqual("int", pd.Type.Identifier); - Assert.AreEqual("a", pd.Identifier); - Assert.AreEqual(0, pd.Modifiers.Count); + Assert.That(pd.Type.Identifier, Is.EqualTo("int")); + Assert.That(pd.Identifier, Is.EqualTo("a")); + Assert.That(pd.Modifiers.Count, Is.EqualTo(0)); pd = Apex.ParameterDeclaration.Parse(" SomeClass b"); - Assert.AreEqual("SomeClass", pd.Type.Identifier); - Assert.AreEqual("b", pd.Identifier); - Assert.AreEqual(0, pd.Modifiers.Count); + Assert.That(pd.Type.Identifier, Is.EqualTo("SomeClass")); + Assert.That(pd.Identifier, Is.EqualTo("b")); + Assert.That(pd.Modifiers.Count, Is.EqualTo(0)); pd = Apex.ParameterDeclaration.Parse(" List stringList"); - Assert.AreEqual("List", pd.Type.Identifier); - Assert.AreEqual(1, pd.Type.TypeParameters.Count); - Assert.AreEqual("String", pd.Type.TypeParameters[0].Identifier); - Assert.AreEqual("stringList", pd.Identifier); - Assert.AreEqual(0, pd.Modifiers.Count); + Assert.That(pd.Type.Identifier, Is.EqualTo("List")); + Assert.That(pd.Type.TypeParameters.Count, Is.EqualTo(1)); + Assert.That(pd.Type.TypeParameters[0].Identifier, Is.EqualTo("String")); + Assert.That(pd.Identifier, Is.EqualTo("stringList")); + Assert.That(pd.Modifiers.Count, Is.EqualTo(0)); pd = Apex.ParameterDeclaration.Parse(" final int a"); - Assert.AreEqual("int", pd.Type.Identifier); - Assert.AreEqual("a", pd.Identifier); - Assert.AreEqual(1, pd.Modifiers.Count); - Assert.AreEqual("final", pd.Modifiers[0]); + Assert.That(pd.Type.Identifier, Is.EqualTo("int")); + Assert.That(pd.Identifier, Is.EqualTo("a")); + Assert.That(pd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(pd.Modifiers[0], Is.EqualTo("final")); - Assert.Throws(() => Apex.ParameterDeclaration.Parse("Hello!")); + Assert.That(() => Apex.ParameterDeclaration.Parse("Hello!"), Throws.TypeOf()); } [Test] public void ParameterDeclarationsIsACommaSeparaterListOfParameterDeclarations() { var pds = Apex.ParameterDeclarations.Parse(" int a, String b").ToList(); - Assert.AreEqual(2, pds.Count); + Assert.That(pds.Count, Is.EqualTo(2)); var pd = pds[0]; - Assert.AreEqual("int", pd.Type.Identifier); - Assert.AreEqual("a", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("int")); + Assert.That(pd.Identifier, Is.EqualTo("a")); pd = pds[1]; - Assert.AreEqual("String", pd.Type.Identifier); - Assert.AreEqual("b", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("String")); + Assert.That(pd.Identifier, Is.EqualTo("b")); - Assert.Throws(() => Apex.ParameterDeclaration.Parse("Hello!")); + Assert.That(() => Apex.ParameterDeclaration.Parse("Hello!"), Throws.TypeOf()); } [Test] public void MethodParametersCanBeJustEmptyBraces() { var mp = Apex.MethodParameters.Parse(" () "); - Assert.NotNull(mp); - Assert.False(mp.Any()); + Assert.That(mp, Is.Not.Null); + Assert.That(mp.Any(), Is.False); // unmatched braces, bad input, etc - Assert.Throws(() => Apex.MethodParameters.Parse("(")); - Assert.Throws(() => Apex.MethodParameters.Parse("(())")); - Assert.Throws(() => Apex.MethodParameters.Parse("Hello")); + Assert.That(() => Apex.MethodParameters.Parse("("), Throws.TypeOf()); + Assert.That(() => Apex.MethodParameters.Parse("(())"), Throws.TypeOf()); + Assert.That(() => Apex.MethodParameters.Parse("Hello"), Throws.TypeOf()); } [Test] public void MethodParametersIsCommaSeparatedParameterDeclarationsWithinBraces() { var mp = Apex.MethodParameters.Parse(" (Integer a, char b, Sys.MyList c123 ) "); - Assert.NotNull(mp); - Assert.AreEqual(3, mp.Count); + Assert.That(mp, Is.Not.Null); + Assert.That(mp.Count, Is.EqualTo(3)); var pd = mp[0]; - Assert.AreEqual("Integer", pd.Type.Identifier); - Assert.AreEqual("a", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("Integer")); + Assert.That(pd.Identifier, Is.EqualTo("a")); pd = mp[1]; - Assert.AreEqual("char", pd.Type.Identifier); - Assert.AreEqual("b", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("char")); + Assert.That(pd.Identifier, Is.EqualTo("b")); pd = mp[2]; - Assert.AreEqual("MyList", pd.Type.Identifier); - Assert.AreEqual(1, pd.Type.Namespaces.Count); - Assert.AreEqual("Sys", pd.Type.Namespaces[0]); - Assert.AreEqual(1, pd.Type.TypeParameters.Count); - Assert.AreEqual("Boolean", pd.Type.TypeParameters[0].Identifier); - Assert.AreEqual("c123", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("MyList")); + Assert.That(pd.Type.Namespaces.Count, Is.EqualTo(1)); + Assert.That(pd.Type.Namespaces[0], Is.EqualTo("Sys")); + Assert.That(pd.Type.TypeParameters.Count, Is.EqualTo(1)); + Assert.That(pd.Type.TypeParameters[0].Identifier, Is.EqualTo("Boolean")); + Assert.That(pd.Identifier, Is.EqualTo("c123")); // bad input examples - Assert.Throws(() => Apex.MethodParameters.Parse(" (Integer a, char b, Boolean ) ")); - Assert.Throws(() => Apex.MethodParameters.Parse("123")); - Assert.Throws(() => Apex.MethodParameters.Parse("int a")); + Assert.That(() => Apex.MethodParameters.Parse(" (Integer a, char b, Boolean ) "), Throws.TypeOf()); + Assert.That(() => Apex.MethodParameters.Parse("123"), Throws.TypeOf()); + Assert.That(() => Apex.MethodParameters.Parse("int a"), Throws.TypeOf()); } [Test] public void ModifiersCanBePublicPrivateEtc() { - Assert.AreEqual("public", Apex.Modifier.Parse(" \n public ")); - Assert.AreEqual("private", Apex.Modifier.Parse(" private \t")); - Assert.AreEqual("with sharing", Apex.Modifier.Parse(@" with - sharing")); + Assert.That(Apex.Modifier.Parse(" \n public "), Is.EqualTo("public")); + Assert.That(Apex.Modifier.Parse(" private \t"), Is.EqualTo("private")); + Assert.That(Apex.Modifier.Parse(@" with + sharing"), Is.EqualTo("with sharing")); // bad input - Assert.Throws(() => Apex.Modifier.Parse(" whatever ")); + Assert.That(() => Apex.Modifier.Parse(" whatever "), Throws.TypeOf()); } [Test] public void ModifiersAreCaseInsensitive() { - Assert.AreEqual("public", Apex.Modifier.Parse(" \n Public ")); - Assert.AreEqual("private", Apex.Modifier.Parse(" PRIVATE \t")); - Assert.AreEqual("with sharing", Apex.Modifier.Parse(@" With - SHARING")); + Assert.That(Apex.Modifier.Parse(" \n Public "), Is.EqualTo("public")); + Assert.That(Apex.Modifier.Parse(" PRIVATE \t"), Is.EqualTo("private")); + Assert.That(Apex.Modifier.Parse(@" With + SHARING"), Is.EqualTo("with sharing")); // bad input - Assert.Throws(() => Apex.Modifier.Parse(" whatever ")); + Assert.That(() => Apex.Modifier.Parse(" whatever "), Throws.TypeOf()); } [Test] public void BlockSupportsNestedBlocks() { var block = Apex.Block.Parse("{123;}"); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("123", block.Statements[0].Body); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("123")); block = Apex.Block.Parse("{ break; return true; continue; }"); - Assert.AreEqual(3, block.Statements.Count); + Assert.That(block.Statements.Count, Is.EqualTo(3)); var breakStmt = block.Statements[0] as BreakStatementSyntax; - Assert.NotNull(breakStmt); + Assert.That(breakStmt, Is.Not.Null); var ret = block.Statements[1] as ReturnStatementSyntax; - Assert.NotNull(ret); - Assert.NotNull(ret.Expression); - Assert.AreEqual("true", ret.Expression.ExpressionString); - Assert.NotNull(block.Statements[2] as ContinueStatementSyntax); + Assert.That(ret, Is.Not.Null); + Assert.That(ret.Expression, Is.Not.Null); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("true")); + Assert.That(block.Statements[2] as ContinueStatementSyntax, Is.Not.Null); block = Apex.Block.Parse("{ if (false) { } }"); - Assert.AreEqual(1, block.Statements.Count); + Assert.That(block.Statements.Count, Is.EqualTo(1)); var ifstmt = block.Statements[0] as IfStatementSyntax; - Assert.NotNull(ifstmt); - Assert.AreEqual("false", ifstmt.Expression.ExpressionString); - Assert.NotNull(ifstmt.ThenStatement); - Assert.Null(ifstmt.ElseStatement); + Assert.That(ifstmt, Is.Not.Null); + Assert.That(ifstmt.Expression.ExpressionString, Is.EqualTo("false")); + Assert.That(ifstmt.ThenStatement, Is.Not.Null); + Assert.That(ifstmt.ElseStatement, Is.Null); block = ifstmt.ThenStatement as BlockSyntax; - Assert.NotNull(block); - Assert.IsFalse(block.Statements.Any()); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Any(), Is.False); // bad input - Assert.Throws(() => Apex.Block.End().Parse("{}}")); - Assert.Throws(() => Apex.Block.Parse("{")); + Assert.That(() => Apex.Block.End().Parse("{}}"), Throws.TypeOf()); + Assert.That(() => Apex.Block.Parse("{"), Throws.TypeOf()); } [Test] @@ -420,12 +420,12 @@ public void MethodDeclarationIsAMethodSignatureWithABlock() { // parameterless method var md = Apex.MethodDeclaration.Parse("void Test() {}"); - Assert.False(md.IsAbstract); - Assert.False(md.Annotations.Any()); - Assert.False(md.Modifiers.Any()); - Assert.False(md.Parameters.Any()); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.AreEqual("Test", md.Identifier); + Assert.That(md.IsAbstract, Is.False); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Identifier, Is.EqualTo("Test")); // method with parameters md = Apex.MethodDeclaration.Parse(@" @@ -433,23 +433,23 @@ string Hello( String name, Boolean newLine ) { } "); - Assert.False(md.IsAbstract); - Assert.False(md.Annotations.Any()); - Assert.False(md.Modifiers.Any()); - Assert.AreEqual(2, md.Parameters.Count); - Assert.AreEqual("String", md.ReturnType.Identifier); - Assert.AreEqual("Hello", md.Identifier); + Assert.That(md.IsAbstract, Is.False); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Any(), Is.False); + Assert.That(md.Parameters.Count, Is.EqualTo(2)); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("String")); + Assert.That(md.Identifier, Is.EqualTo("Hello")); var mp = md.Parameters; - Assert.AreEqual(2, mp.Count); + Assert.That(mp.Count, Is.EqualTo(2)); var pd = mp[0]; - Assert.AreEqual("String", pd.Type.Identifier); - Assert.AreEqual("name", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("String")); + Assert.That(pd.Identifier, Is.EqualTo("name")); pd = mp[1]; - Assert.AreEqual("Boolean", pd.Type.Identifier); - Assert.AreEqual("newLine", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("Boolean")); + Assert.That(pd.Identifier, Is.EqualTo("newLine")); // method with visibility md = Apex.MethodDeclaration.Parse(@" @@ -457,46 +457,46 @@ public List Add(int x, int y, int z) { } "); - Assert.False(md.IsAbstract); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.AreEqual("List", md.ReturnType.Identifier); - Assert.AreEqual(1, md.ReturnType.TypeParameters.Count); - Assert.AreEqual("int", md.ReturnType.TypeParameters[0].Identifier); - Assert.AreEqual("Add", md.Identifier); - Assert.AreEqual(3, md.Parameters.Count); + Assert.That(md.IsAbstract, Is.False); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("List")); + Assert.That(md.ReturnType.TypeParameters.Count, Is.EqualTo(1)); + Assert.That(md.ReturnType.TypeParameters[0].Identifier, Is.EqualTo("int")); + Assert.That(md.Identifier, Is.EqualTo("Add")); + Assert.That(md.Parameters.Count, Is.EqualTo(3)); mp = md.Parameters; - Assert.AreEqual(3, mp.Count); + Assert.That(mp.Count, Is.EqualTo(3)); pd = mp[0]; - Assert.AreEqual("int", pd.Type.Identifier); - Assert.AreEqual("x", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("int")); + Assert.That(pd.Identifier, Is.EqualTo("x")); // a method with annotation md = Apex.MethodDeclaration.Parse("@isTest void Test() {}"); - Assert.False(md.IsAbstract); - Assert.AreEqual(1, md.Annotations.Count); - Assert.AreEqual("IsTest", md.Annotations[0].Identifier); - Assert.False(md.Modifiers.Any()); - Assert.False(md.Parameters.Any()); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.AreEqual("Test", md.Identifier); + Assert.That(md.IsAbstract, Is.False); + Assert.That(md.Annotations.Count, Is.EqualTo(1)); + Assert.That(md.Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(md.Modifiers.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Identifier, Is.EqualTo("Test")); // a method without the body md = Apex.MethodDeclaration.Parse("@isTest void Test();"); - Assert.True(md.IsAbstract); - Assert.AreEqual(1, md.Annotations.Count); - Assert.AreEqual("IsTest", md.Annotations[0].Identifier); - Assert.False(md.Modifiers.Any()); - Assert.False(md.Parameters.Any()); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.AreEqual("Test", md.Identifier); + Assert.That(md.IsAbstract, Is.True); + Assert.That(md.Annotations.Count, Is.EqualTo(1)); + Assert.That(md.Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(md.Modifiers.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Identifier, Is.EqualTo("Test")); // invalid input - Assert.Throws(() => Apex.MethodDeclaration.Parse("void Test {}")); - Assert.Throws(() => Apex.MethodDeclaration.Parse("void AnotherTest()() {}")); + Assert.That(() => Apex.MethodDeclaration.Parse("void Test {}"), Throws.TypeOf()); + Assert.That(() => Apex.MethodDeclaration.Parse("void AnotherTest()() {}"), Throws.TypeOf()); } [Test] @@ -504,12 +504,12 @@ public void ConstructorDeclarationIsAMethodNamedTheSameAsItsClass() { // parameterless constructor var md = Apex.MethodDeclaration.Parse("public Disposable() {}"); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.False(md.Parameters.Any()); - Assert.AreEqual("Disposable", md.ReturnType.Identifier); - Assert.AreEqual("Disposable", md.Identifier); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.Parameters.Any(), Is.False); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("Disposable")); + Assert.That(md.Identifier, Is.EqualTo("Disposable")); // constructor with parameters md = Apex.MethodDeclaration.Parse(@" @@ -517,280 +517,280 @@ public void ConstructorDeclarationIsAMethodNamedTheSameAsItsClass() { } "); - Assert.False(md.Annotations.Any()); - Assert.False(md.Modifiers.Any()); - Assert.AreEqual(2, md.Parameters.Count); - Assert.AreEqual("MyService", md.ReturnType.Identifier); - Assert.AreEqual("MyService", md.Identifier); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Any(), Is.False); + Assert.That(md.Parameters.Count, Is.EqualTo(2)); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("MyService")); + Assert.That(md.Identifier, Is.EqualTo("MyService")); var mp = md.Parameters; - Assert.AreEqual(2, mp.Count); + Assert.That(mp.Count, Is.EqualTo(2)); var pd = mp[0]; - Assert.AreEqual("String", pd.Type.Identifier); - Assert.AreEqual("name", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("String")); + Assert.That(pd.Identifier, Is.EqualTo("name")); pd = mp[1]; - Assert.AreEqual("Boolean", pd.Type.Identifier); - Assert.AreEqual("newLine", pd.Identifier); + Assert.That(pd.Type.Identifier, Is.EqualTo("Boolean")); + Assert.That(pd.Identifier, Is.EqualTo("newLine")); // a constructor with annotation md = Apex.MethodDeclaration.Parse("@isTest SampleClass() {}"); - Assert.AreEqual(1, md.Annotations.Count); - Assert.AreEqual("IsTest", md.Annotations[0].Identifier); - Assert.False(md.Modifiers.Any()); - Assert.False(md.Parameters.Any()); - Assert.AreEqual("SampleClass", md.ReturnType.Identifier); - Assert.AreEqual("SampleClass", md.Identifier); + Assert.That(md.Annotations.Count, Is.EqualTo(1)); + Assert.That(md.Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(md.Modifiers.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("SampleClass")); + Assert.That(md.Identifier, Is.EqualTo("SampleClass")); // invalid input - Assert.Throws(() => Apex.MethodDeclaration.Parse("public Test {}")); - Assert.Throws(() => Apex.MethodDeclaration.Parse("static AnotherTest()() {}")); + Assert.That(() => Apex.MethodDeclaration.Parse("public Test {}"), Throws.TypeOf()); + Assert.That(() => Apex.MethodDeclaration.Parse("static AnotherTest()() {}"), Throws.TypeOf()); } [Test] public void TypeAndNameIsJustATypeReferenceAndIdentifierPair() { var tn = Apex.TypeAndName.Parse("string a"); - Assert.AreEqual("String", tn.Type.Identifier); - Assert.AreEqual("a", tn.Identifier); + Assert.That(tn.Type.Identifier, Is.EqualTo("String")); + Assert.That(tn.Identifier, Is.EqualTo("a")); tn = Apex.TypeAndName.Parse("void Test"); - Assert.AreEqual("void", tn.Type.Identifier); - Assert.AreEqual("Test", tn.Identifier); + Assert.That(tn.Type.Identifier, Is.EqualTo("void")); + Assert.That(tn.Identifier, Is.EqualTo("Test")); tn = Apex.TypeAndName.Parse("ClassOne"); - Assert.AreEqual("ClassOne", tn.Type.Identifier); - Assert.IsNull(tn.Identifier); + Assert.That(tn.Type.Identifier, Is.EqualTo("ClassOne")); + Assert.That(tn.Identifier, Is.Null); } [Test] public void PropertyAccessorCanBeEmpty() { var get = Apex.PropertyAccessor.Parse(" get ; "); - Assert.False(get.LeadingComments.Any()); - Assert.False(get.Annotations.Any()); - Assert.False(get.Modifiers.Any()); - Assert.True(get.IsGetter); - Assert.Null(get.Body); + Assert.That(get.LeadingComments.Any(), Is.False); + Assert.That(get.Annotations.Any(), Is.False); + Assert.That(get.Modifiers.Any(), Is.False); + Assert.That(get.IsGetter, Is.True); + Assert.That(get.Body, Is.Null); var set = Apex.PropertyAccessor.Parse(" set ; "); - Assert.False(set.LeadingComments.Any()); - Assert.False(set.Annotations.Any()); - Assert.False(set.Modifiers.Any()); - Assert.True(set.IsSetter); - Assert.Null(set.Body); + Assert.That(set.LeadingComments.Any(), Is.False); + Assert.That(set.Annotations.Any(), Is.False); + Assert.That(set.Modifiers.Any(), Is.False); + Assert.That(set.IsSetter, Is.True); + Assert.That(set.Body, Is.Null); } [Test] public void PropertyAccessorCanHaveBlocks() { var get = Apex.PropertyAccessor.Parse(" get { return myProperty; } "); - Assert.False(get.LeadingComments.Any()); - Assert.False(get.Annotations.Any()); - Assert.False(get.Modifiers.Any()); - Assert.True(get.IsGetter); + Assert.That(get.LeadingComments.Any(), Is.False); + Assert.That(get.Annotations.Any(), Is.False); + Assert.That(get.Modifiers.Any(), Is.False); + Assert.That(get.IsGetter, Is.True); var block = get.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("myProperty", (block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That((block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("myProperty")); var set = Apex.PropertyAccessor.Parse(" set { myProperty = value; if (true) { value++; } } "); - Assert.False(set.LeadingComments.Any()); - Assert.False(set.Annotations.Any()); - Assert.False(set.Modifiers.Any()); - Assert.IsTrue(set.IsSetter); + Assert.That(set.LeadingComments.Any(), Is.False); + Assert.That(set.Annotations.Any(), Is.False); + Assert.That(set.Modifiers.Any(), Is.False); + Assert.That(set.IsSetter, Is.True); block = set.Body; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); - Assert.AreEqual("myProperty = value", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); + Assert.That(block.Statements[0].Body, Is.EqualTo("myProperty = value")); var ifstmt = block.Statements[1] as IfStatementSyntax; - Assert.NotNull(ifstmt); - Assert.NotNull(ifstmt.ThenStatement); - Assert.Null(ifstmt.ElseStatement); + Assert.That(ifstmt, Is.Not.Null); + Assert.That(ifstmt.ThenStatement, Is.Not.Null); + Assert.That(ifstmt.ElseStatement, Is.Null); block = ifstmt.ThenStatement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("value++", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("value++")); } [Test] public void PropertyAccessorCanHaveAccessModifiers() { var get = Apex.PropertyAccessor.Parse(" public get { return 0; }"); - Assert.False(get.LeadingComments.Any()); - Assert.False(get.Annotations.Any()); - Assert.AreEqual(1, get.Modifiers.Count); - Assert.AreEqual("public", get.Modifiers[0]); - Assert.True(get.IsGetter); + Assert.That(get.LeadingComments.Any(), Is.False); + Assert.That(get.Annotations.Any(), Is.False); + Assert.That(get.Modifiers.Count, Is.EqualTo(1)); + Assert.That(get.Modifiers[0], Is.EqualTo("public")); + Assert.That(get.IsGetter, Is.True); var block = get.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("0", (block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That((block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("0")); } [Test] public void PropertyAccessorCanHaveComments() { var get = Apex.PropertyAccessor.End().Parse(" get; // getter"); - Assert.False(get.LeadingComments.Any()); - Assert.False(get.Annotations.Any()); - Assert.AreEqual(0, get.Modifiers.Count); - Assert.True(get.IsGetter); - Assert.Null(get.Body); + Assert.That(get.LeadingComments.Any(), Is.False); + Assert.That(get.Annotations.Any(), Is.False); + Assert.That(get.Modifiers.Count, Is.EqualTo(0)); + Assert.That(get.IsGetter, Is.True); + Assert.That(get.Body, Is.Null); } [Test] public void PropertyHasTypeNameGettersAndOrSetters() { var prop = Apex.PropertyDeclaration.Parse(" int x { get; }"); - Assert.AreEqual("int", prop.Type.Identifier); - Assert.AreEqual("x", prop.Identifier); - Assert.Null(prop.Setter); - Assert.NotNull(prop.Getter); - Assert.True(prop.Getter.IsEmpty); + Assert.That(prop.Type.Identifier, Is.EqualTo("int")); + Assert.That(prop.Identifier, Is.EqualTo("x")); + Assert.That(prop.Setter, Is.Null); + Assert.That(prop.Getter, Is.Not.Null); + Assert.That(prop.Getter.IsEmpty, Is.True); prop = Apex.PropertyDeclaration.Parse(" String Version { set { version = value; } }"); - Assert.AreEqual("String", prop.Type.Identifier); - Assert.AreEqual("Version", prop.Identifier); - Assert.Null(prop.Getter); - Assert.NotNull(prop.Setter); + Assert.That(prop.Type.Identifier, Is.EqualTo("String")); + Assert.That(prop.Identifier, Is.EqualTo("Version")); + Assert.That(prop.Getter, Is.Null); + Assert.That(prop.Setter, Is.Not.Null); var block = prop.Setter.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("version = value", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("version = value")); prop = Apex.PropertyDeclaration.Parse(@"// length @dataMember int length { get; }"); - Assert.AreEqual(1, prop.LeadingComments.Count); - Assert.AreEqual("length", prop.LeadingComments[0].Trim()); - Assert.AreEqual(1, prop.Annotations.Count); - Assert.AreEqual("dataMember", prop.Annotations[0].Identifier); - Assert.AreEqual("int", prop.Type.Identifier); - Assert.AreEqual("length", prop.Identifier); - Assert.Null(prop.Setter); - Assert.NotNull(prop.Getter); - Assert.True(prop.Getter.IsEmpty); + Assert.That(prop.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(prop.LeadingComments[0].Trim(), Is.EqualTo("length")); + Assert.That(prop.Annotations.Count, Is.EqualTo(1)); + Assert.That(prop.Annotations[0].Identifier, Is.EqualTo("dataMember")); + Assert.That(prop.Type.Identifier, Is.EqualTo("int")); + Assert.That(prop.Identifier, Is.EqualTo("length")); + Assert.That(prop.Setter, Is.Null); + Assert.That(prop.Getter, Is.Not.Null); + Assert.That(prop.Getter.IsEmpty, Is.True); } [Test] public void FieldHasTypeAndNameWithoutPropertyAccessors() { var field = Apex.FieldDeclaration.Parse(" /* Counter */ @dataMember public static int counter;"); - Assert.AreEqual(1, field.LeadingComments.Count); - Assert.AreEqual("Counter", field.LeadingComments[0].Trim()); - Assert.AreEqual(1, field.Annotations.Count); - Assert.AreEqual("dataMember", field.Annotations[0].Identifier); - Assert.AreEqual(2, field.Modifiers.Count); - Assert.AreEqual("public", field.Modifiers[0]); - Assert.AreEqual("static", field.Modifiers[1]); - Assert.AreEqual("int", field.Type.Identifier); - Assert.AreEqual(1, field.Fields.Count); - Assert.AreEqual("counter", field.Fields[0].Identifier); + Assert.That(field.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(field.LeadingComments[0].Trim(), Is.EqualTo("Counter")); + Assert.That(field.Annotations.Count, Is.EqualTo(1)); + Assert.That(field.Annotations[0].Identifier, Is.EqualTo("dataMember")); + Assert.That(field.Modifiers.Count, Is.EqualTo(2)); + Assert.That(field.Modifiers[0], Is.EqualTo("public")); + Assert.That(field.Modifiers[1], Is.EqualTo("static")); + Assert.That(field.Type.Identifier, Is.EqualTo("int")); + Assert.That(field.Fields.Count, Is.EqualTo(1)); + Assert.That(field.Fields[0].Identifier, Is.EqualTo("counter")); // not a field declaration - Assert.Throws(() => Apex.FieldDeclaration.Parse("int x { get; }")); + Assert.That(() => Apex.FieldDeclaration.Parse("int x { get; }"), Throws.TypeOf()); } [Test] public void FieldDeclarationCanHaveInitializerExpression() { var field = Apex.FieldDeclaration.Parse(" public string name = 'Bozo';"); - Assert.AreEqual(1, field.Modifiers.Count); - Assert.AreEqual("public", field.Modifiers[0]); - Assert.AreEqual("String", field.Type.Identifier); - Assert.AreEqual(1, field.Fields.Count); - Assert.AreEqual("name", field.Fields[0].Identifier); - Assert.AreEqual("'Bozo'", field.Fields[0].Expression.ExpressionString); + Assert.That(field.Modifiers.Count, Is.EqualTo(1)); + Assert.That(field.Modifiers[0], Is.EqualTo("public")); + Assert.That(field.Type.Identifier, Is.EqualTo("String")); + Assert.That(field.Fields.Count, Is.EqualTo(1)); + Assert.That(field.Fields[0].Identifier, Is.EqualTo("name")); + Assert.That(field.Fields[0].Expression.ExpressionString, Is.EqualTo("'Bozo'")); field = Apex.FieldDeclaration.Parse("public Set stringSet = new Set{};"); - Assert.AreEqual(1, field.Modifiers.Count); - Assert.AreEqual("public", field.Modifiers[0]); - Assert.AreEqual("Set", field.Type.Identifier); - Assert.AreEqual(1, field.Fields.Count); - Assert.AreEqual("stringSet", field.Fields[0].Identifier); - Assert.AreEqual("new Set{}", field.Fields[0].Expression.ExpressionString); + Assert.That(field.Modifiers.Count, Is.EqualTo(1)); + Assert.That(field.Modifiers[0], Is.EqualTo("public")); + Assert.That(field.Type.Identifier, Is.EqualTo("Set")); + Assert.That(field.Fields.Count, Is.EqualTo(1)); + Assert.That(field.Fields[0].Identifier, Is.EqualTo("stringSet")); + Assert.That(field.Fields[0].Expression.ExpressionString, Is.EqualTo("new Set{}")); // incomplete field declaration - Assert.Throws(() => Apex.FieldDeclaration.Parse("int x =")); + Assert.That(() => Apex.FieldDeclaration.Parse("int x ="), Throws.TypeOf()); } [Test] public void FieldDeclarationCanHaveInitializedWithCommasInItsExpression() { var field = Apex.FieldDeclaration.Parse("public Map stringMap = new Map() { 1, 2, 3 };"); - Assert.AreEqual(1, field.Modifiers.Count); - Assert.AreEqual("public", field.Modifiers[0]); - Assert.AreEqual("Map", field.Type.Identifier); - Assert.AreEqual(1, field.Fields.Count); - Assert.AreEqual("stringMap", field.Fields[0].Identifier); - Assert.AreEqual("new Map(){1, 2, 3}", field.Fields[0].Expression.ExpressionString); + Assert.That(field.Modifiers.Count, Is.EqualTo(1)); + Assert.That(field.Modifiers[0], Is.EqualTo("public")); + Assert.That(field.Type.Identifier, Is.EqualTo("Map")); + Assert.That(field.Fields.Count, Is.EqualTo(1)); + Assert.That(field.Fields[0].Identifier, Is.EqualTo("stringMap")); + Assert.That(field.Fields[0].Expression.ExpressionString, Is.EqualTo("new Map(){1, 2, 3}")); } [Test] public void FieldDeclarationCanHaveMultipleDeclarators() { var field = Apex.FieldDeclaration.Parse(" string name, lastName; "); - Assert.AreEqual("String", field.Type.Identifier); - Assert.AreEqual(2, field.Fields.Count); - Assert.AreEqual("name", field.Fields[0].Identifier); - Assert.IsNull(field.Fields[0].Expression); - Assert.AreEqual("lastName", field.Fields[1].Identifier); - Assert.IsNull(field.Fields[1].Expression); + Assert.That(field.Type.Identifier, Is.EqualTo("String")); + Assert.That(field.Fields.Count, Is.EqualTo(2)); + Assert.That(field.Fields[0].Identifier, Is.EqualTo("name")); + Assert.That(field.Fields[0].Expression, Is.Null); + Assert.That(field.Fields[1].Identifier, Is.EqualTo("lastName")); + Assert.That(field.Fields[1].Expression, Is.Null); field = Apex.FieldDeclaration.Parse(@" string name = 'a\'b', lastName = 'b'; "); - Assert.AreEqual("String", field.Type.Identifier); - Assert.AreEqual(2, field.Fields.Count); - Assert.AreEqual("name", field.Fields[0].Identifier); - Assert.AreEqual(@"'a\'b'", field.Fields[0].Expression.ExpressionString); - Assert.AreEqual("lastName", field.Fields[1].Identifier); - Assert.AreEqual("'b'", field.Fields[1].Expression.ExpressionString); + Assert.That(field.Type.Identifier, Is.EqualTo("String")); + Assert.That(field.Fields.Count, Is.EqualTo(2)); + Assert.That(field.Fields[0].Identifier, Is.EqualTo("name")); + Assert.That(field.Fields[0].Expression.ExpressionString, Is.EqualTo(@"'a\'b'")); + Assert.That(field.Fields[1].Identifier, Is.EqualTo("lastName")); + Assert.That(field.Fields[1].Expression.ExpressionString, Is.EqualTo("'b'")); field = Apex.FieldDeclaration.Parse(" Map map1 = new Map(), map2 = null; "); - Assert.AreEqual("Map", field.Type.Identifier); - Assert.AreEqual(2, field.Fields.Count); - Assert.AreEqual("map1", field.Fields[0].Identifier); - Assert.AreEqual(@"new Map()", field.Fields[0].Expression.ExpressionString); - Assert.AreEqual("map2", field.Fields[1].Identifier); - Assert.AreEqual("null", field.Fields[1].Expression.ExpressionString); + Assert.That(field.Type.Identifier, Is.EqualTo("Map")); + Assert.That(field.Fields.Count, Is.EqualTo(2)); + Assert.That(field.Fields[0].Identifier, Is.EqualTo("map1")); + Assert.That(field.Fields[0].Expression.ExpressionString, Is.EqualTo(@"new Map()")); + Assert.That(field.Fields[1].Identifier, Is.EqualTo("map2")); + Assert.That(field.Fields[1].Expression.ExpressionString, Is.EqualTo("null")); } [Test] public void ClassMemberHeadingConstistsOfCommentsAttributesAndModifiers() { var cm = Apex.MemberDeclarationHeading.Parse(" /* test */ "); - Assert.AreEqual(1, cm.LeadingComments.Count); - Assert.AreEqual(" test ", cm.LeadingComments[0]); - Assert.False(cm.Annotations.Any()); - Assert.False(cm.Modifiers.Any()); + Assert.That(cm.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(cm.LeadingComments[0], Is.EqualTo(" test ")); + Assert.That(cm.Annotations.Any(), Is.False); + Assert.That(cm.Modifiers.Any(), Is.False); cm = Apex.MemberDeclarationHeading.Parse(" public static "); - Assert.AreEqual(2, cm.Modifiers.Count); - Assert.AreEqual("public", cm.Modifiers[0]); - Assert.AreEqual("static", cm.Modifiers[1]); - Assert.False(cm.LeadingComments.Any()); - Assert.False(cm.Annotations.Any()); + Assert.That(cm.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cm.Modifiers[0], Is.EqualTo("public")); + Assert.That(cm.Modifiers[1], Is.EqualTo("static")); + Assert.That(cm.LeadingComments.Any(), Is.False); + Assert.That(cm.Annotations.Any(), Is.False); cm = Apex.MemberDeclarationHeading.Parse(" @isTest "); - Assert.AreEqual(1, cm.Annotations.Count); - Assert.AreEqual("IsTest", cm.Annotations[0].Identifier); - Assert.False(cm.LeadingComments.Any()); - Assert.False(cm.Modifiers.Any()); + Assert.That(cm.Annotations.Count, Is.EqualTo(1)); + Assert.That(cm.Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(cm.LeadingComments.Any(), Is.False); + Assert.That(cm.Modifiers.Any(), Is.False); cm = Apex.MemberDeclarationHeading.Parse(" /* my class */ @isTest override "); - Assert.AreEqual(1, cm.Annotations.Count); - Assert.AreEqual("IsTest", cm.Annotations[0].Identifier); - Assert.AreEqual(1, cm.LeadingComments.Count); - Assert.AreEqual(" my class ", cm.LeadingComments[0]); - Assert.AreEqual(1, cm.Modifiers.Count); - Assert.AreEqual("override", cm.Modifiers[0]); + Assert.That(cm.Annotations.Count, Is.EqualTo(1)); + Assert.That(cm.Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(cm.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(cm.LeadingComments[0], Is.EqualTo(" my class ")); + Assert.That(cm.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cm.Modifiers[0], Is.EqualTo("override")); } [Test] @@ -798,269 +798,269 @@ public void MethodOrPropertyDeclarationCanReturnEitherMethodOrProperty() { var pm = Apex.MethodOrPropertyDeclaration.Parse("void Test(int x) {}"); var md = pm as MethodDeclarationSyntax; - Assert.NotNull(md); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.AreEqual("Test", md.Identifier); - Assert.AreEqual(1, md.Parameters.Count); - Assert.AreEqual("int", md.Parameters[0].Type.Identifier); - Assert.AreEqual("x", md.Parameters[0].Identifier); + Assert.That(md, Is.Not.Null); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Identifier, Is.EqualTo("Test")); + Assert.That(md.Parameters.Count, Is.EqualTo(1)); + Assert.That(md.Parameters[0].Type.Identifier, Is.EqualTo("int")); + Assert.That(md.Parameters[0].Identifier, Is.EqualTo("x")); var block = md.Body; - Assert.NotNull(block); - Assert.False(block.Statements.Any()); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Any(), Is.False); pm = Apex.MethodOrPropertyDeclaration.Parse("string Test { get; }"); var pd = pm as PropertyDeclarationSyntax; - Assert.NotNull(pd); - Assert.AreEqual("String", pd.Type.Identifier); - Assert.AreEqual("Test", pd.Identifier); - Assert.NotNull(pd.Getter); - Assert.True(pd.Getter.IsEmpty); - Assert.Null(pd.Setter); + Assert.That(pd, Is.Not.Null); + Assert.That(pd.Type.Identifier, Is.EqualTo("String")); + Assert.That(pd.Identifier, Is.EqualTo("Test")); + Assert.That(pd.Getter, Is.Not.Null); + Assert.That(pd.Getter.IsEmpty, Is.True); + Assert.That(pd.Setter, Is.Null); // not supported anymore - Assert.Throws(() => + Assert.That(() => { pm = Apex.MethodOrPropertyDeclaration.Parse("DateTime now = DateTime.Now();"); var fd = pm as FieldDeclarationSyntax; - Assert.NotNull(fd); - Assert.AreEqual("DateTime", fd.Type.Identifier); - Assert.AreEqual(1, fd.Fields.Count); - Assert.AreEqual("now", fd.Fields[0].Identifier); - Assert.AreEqual("DateTime.Now()", fd.Fields[0].Expression); - }); + Assert.That(fd, Is.Not.Null); + Assert.That(fd.Type.Identifier, Is.EqualTo("DateTime")); + Assert.That(fd.Fields.Count, Is.EqualTo(1)); + Assert.That(fd.Fields[0].Identifier, Is.EqualTo("now")); + Assert.That(fd.Fields[0].Expression, Is.EqualTo("DateTime.Now()")); + }, Throws.TypeOf()); } [Test] public void ClassDeclarationBodyCanBeEmpty() { var cd = Apex.ClassDeclarationBody.Parse(" class Test {}"); - Assert.False(cd.IsInterface); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Methods.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.AreEqual("Test", cd.Identifier); + Assert.That(cd.IsInterface, Is.False); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("Test")); cd = Apex.ClassDeclarationBody.Parse(" class Test /* another one */ {}"); - Assert.False(cd.IsInterface); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Methods.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.AreEqual("Test", cd.Identifier); + Assert.That(cd.IsInterface, Is.False); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("Test")); // incomplete class declarations - Assert.Throws(() => Apex.ClassDeclarationBody.Parse(" class Test {")); - Assert.Throws(() => Apex.ClassDeclarationBody.Parse(" class {}")); + Assert.That(() => Apex.ClassDeclarationBody.Parse(" class Test {"), Throws.TypeOf()); + Assert.That(() => Apex.ClassDeclarationBody.Parse(" class {}"), Throws.TypeOf()); } [Test] public void InterfaceDeclarationBodyCanBeEmpty() { var cd = Apex.ClassDeclarationBody.Parse(" interface Test {}"); - Assert.True(cd.IsInterface); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Methods.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.AreEqual("Test", cd.Identifier); + Assert.That(cd.IsInterface, Is.True); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("Test")); // incomplete class declarations - Assert.Throws(() => Apex.ClassDeclarationBody.Parse(" class Test {")); - Assert.Throws(() => Apex.ClassDeclarationBody.Parse(" class {}")); + Assert.That(() => Apex.ClassDeclarationBody.Parse(" class Test {"), Throws.TypeOf()); + Assert.That(() => Apex.ClassDeclarationBody.Parse(" class {}"), Throws.TypeOf()); } [Test] public void ClassDeclarationCanBeEmpty() { var cd = Apex.ClassDeclaration.Parse(" class Test {}"); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Methods.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.AreEqual("Test", cd.Identifier); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("Test")); // incomplete class declarations - Assert.Throws(() => Apex.ClassDeclaration.Parse(" class Test {")); - Assert.Throws(() => Apex.ClassDeclaration.Parse("class {}")); + Assert.That(() => Apex.ClassDeclaration.Parse(" class Test {"), Throws.TypeOf()); + Assert.That(() => Apex.ClassDeclaration.Parse("class {}"), Throws.TypeOf()); } [Test] public void ClassDeclarationCanBeEmptyWithComments() { var cd = Apex.ClassDeclaration.Parse(" class Test /* Comment1 */ { /* Comment2 */ } // Comment3"); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Methods.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.AreEqual("Test", cd.Identifier); - Assert.AreEqual(1, cd.InnerComments.Count); - Assert.AreEqual("Comment2", cd.InnerComments[0].Trim()); - Assert.AreEqual(1, cd.TrailingComments.Count); - Assert.AreEqual("Comment3", cd.TrailingComments[0].Trim()); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("Test")); + Assert.That(cd.InnerComments.Count, Is.EqualTo(1)); + Assert.That(cd.InnerComments[0].Trim(), Is.EqualTo("Comment2")); + Assert.That(cd.TrailingComments.Count, Is.EqualTo(1)); + Assert.That(cd.TrailingComments[0].Trim(), Is.EqualTo("Comment3")); } [Test] public void ClassDeclarationCanHaveAnnotations() { var cd = Apex.ClassDeclaration.Parse("@one @two class Three {}"); - Assert.AreEqual(2, cd.Annotations.Count); - Assert.AreEqual("one", cd.Annotations[0].Identifier); - Assert.AreEqual("two", cd.Annotations[1].Identifier); - Assert.IsNull(cd.BaseType); - Assert.False(cd.Methods.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.AreEqual("Three", cd.Identifier); + Assert.That(cd.Annotations.Count, Is.EqualTo(2)); + Assert.That(cd.Annotations[0].Identifier, Is.EqualTo("one")); + Assert.That(cd.Annotations[1].Identifier, Is.EqualTo("two")); + Assert.That(cd.BaseType, Is.Null); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("Three")); // bad class declarations - Assert.Throws(() => Apex.ClassDeclaration.Parse("@class Test {")); + Assert.That(() => Apex.ClassDeclaration.Parse("@class Test {"), Throws.TypeOf()); } [Test] public void ClassCanExtendOtherClass() { var cd = Apex.ClassDeclaration.Parse("class Derived extends Base {}"); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.False(cd.Interfaces.Any()); - Assert.NotNull(cd.BaseType); - Assert.AreEqual("Derived", cd.Identifier); - Assert.AreEqual("Base", cd.BaseType.Identifier); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.Interfaces.Any(), Is.False); + Assert.That(cd.BaseType, Is.Not.Null); + Assert.That(cd.Identifier, Is.EqualTo("Derived")); + Assert.That(cd.BaseType.Identifier, Is.EqualTo("Base")); // bad inheritance list - Assert.Throws(() => Apex.ClassDeclaration.Parse("class Derived extends Base, OtherBase {}")); + Assert.That(() => Apex.ClassDeclaration.Parse("class Derived extends Base, OtherBase {}"), Throws.TypeOf()); } [Test] public void ClassCanImplementInterfaces() { var cd = Apex.ClassDeclaration.Parse("class Disposable implements IDisposable {}"); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.Null(cd.BaseType); - Assert.AreEqual("Disposable", cd.Identifier); - Assert.AreEqual(1, cd.Interfaces.Count); - Assert.AreEqual("IDisposable", cd.Interfaces[0].Identifier); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.BaseType, Is.Null); + Assert.That(cd.Identifier, Is.EqualTo("Disposable")); + Assert.That(cd.Interfaces.Count, Is.EqualTo(1)); + Assert.That(cd.Interfaces[0].Identifier, Is.EqualTo("IDisposable")); cd = Apex.ClassDeclaration.Parse("class MyClass implements IEntity, IMyInterface {}"); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.Null(cd.BaseType); - Assert.AreEqual("MyClass", cd.Identifier); - Assert.AreEqual(2, cd.Interfaces.Count); - Assert.AreEqual("IEntity", cd.Interfaces[0].Identifier); - Assert.AreEqual("IMyInterface", cd.Interfaces[1].Identifier); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.BaseType, Is.Null); + Assert.That(cd.Identifier, Is.EqualTo("MyClass")); + Assert.That(cd.Interfaces.Count, Is.EqualTo(2)); + Assert.That(cd.Interfaces[0].Identifier, Is.EqualTo("IEntity")); + Assert.That(cd.Interfaces[1].Identifier, Is.EqualTo("IMyInterface")); // incomplete class declaration - Assert.Throws(() => Apex.ClassDeclaration.Parse("class Derived implements {}")); + Assert.That(() => Apex.ClassDeclaration.Parse("class Derived implements {}"), Throws.TypeOf()); } [Test] public void ClassCanExtendBaseClassAndImplementMultipleInterfaces() { var cd = Apex.ClassDeclaration.Parse("class Derived extends Base implements IOne, ITwo {}"); - Assert.False(cd.Annotations.Any()); - Assert.False(cd.Modifiers.Any()); - Assert.NotNull(cd.BaseType); - Assert.AreEqual("Derived", cd.Identifier); - Assert.AreEqual("Base", cd.BaseType.Identifier); - Assert.AreEqual(2, cd.Interfaces.Count); - Assert.AreEqual("IOne", cd.Interfaces[0].Identifier); - Assert.AreEqual("ITwo", cd.Interfaces[1].Identifier); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Modifiers.Any(), Is.False); + Assert.That(cd.BaseType, Is.Not.Null); + Assert.That(cd.Identifier, Is.EqualTo("Derived")); + Assert.That(cd.BaseType.Identifier, Is.EqualTo("Base")); + Assert.That(cd.Interfaces.Count, Is.EqualTo(2)); + Assert.That(cd.Interfaces[0].Identifier, Is.EqualTo("IOne")); + Assert.That(cd.Interfaces[1].Identifier, Is.EqualTo("ITwo")); // bad inheritance list - Assert.Throws(() => Apex.ClassDeclaration.Parse("class Derived extends {}")); + Assert.That(() => Apex.ClassDeclaration.Parse("class Derived extends {}"), Throws.TypeOf()); } [Test] public void ClassDeclarationBodyCanDeclareMethods() { var cd = Apex.ClassDeclarationBody.Parse(" class Program { void main() {} }"); - Assert.True(cd.Methods.Any()); - Assert.AreEqual("Program", cd.Identifier); + Assert.That(cd.Methods.Any(), Is.True); + Assert.That(cd.Identifier, Is.EqualTo("Program")); var md = cd.Methods.Single(); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.AreEqual("main", md.Identifier); - Assert.False(md.Parameters.Any()); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Identifier, Is.EqualTo("main")); + Assert.That(md.Parameters.Any(), Is.False); // class declarations with bad methods - Assert.Throws(() => Apex.ClassDeclarationBody.Parse(" class Test { void Main }")); - Assert.Throws(() => Apex.ClassDeclarationBody.Parse(" class Apex { int main() }")); + Assert.That(() => Apex.ClassDeclarationBody.Parse(" class Test { void Main }"), Throws.TypeOf()); + Assert.That(() => Apex.ClassDeclarationBody.Parse(" class Apex { int main() }"), Throws.TypeOf()); } [Test] public void ClassDeclarationBodyCanDeclareEnums() { var cd = Apex.ClassDeclarationBody.Parse(" class Dummy { enum Boo { Tru, Fal, Unk } }"); - Assert.False(cd.Methods.Any()); - Assert.AreEqual(1, cd.Enums.Count); - Assert.AreEqual("Dummy", cd.Identifier); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Enums.Count, Is.EqualTo(1)); + Assert.That(cd.Identifier, Is.EqualTo("Dummy")); var ed = cd.Enums.Single(); - Assert.AreEqual("Boo", ed.Identifier); - Assert.AreEqual(3, ed.Members.Count); - Assert.AreEqual("Tru", ed.Members[0].Identifier); - Assert.AreEqual("Fal", ed.Members[1].Identifier); - Assert.AreEqual("Unk", ed.Members[2].Identifier); + Assert.That(ed.Identifier, Is.EqualTo("Boo")); + Assert.That(ed.Members.Count, Is.EqualTo(3)); + Assert.That(ed.Members[0].Identifier, Is.EqualTo("Tru")); + Assert.That(ed.Members[1].Identifier, Is.EqualTo("Fal")); + Assert.That(ed.Members[2].Identifier, Is.EqualTo("Unk")); // class declarations with bad methods - Assert.Throws(() => Apex.ClassDeclarationBody.Parse(" class Test { enum Boo }")); - Assert.Throws(() => Apex.ClassDeclarationBody.Parse(" class Apex { enum Boo{} }")); + Assert.That(() => Apex.ClassDeclarationBody.Parse(" class Test { enum Boo }"), Throws.TypeOf()); + Assert.That(() => Apex.ClassDeclarationBody.Parse(" class Apex { enum Boo{} }"), Throws.TypeOf()); } [Test] public void ClassDeclarationCanDeclareMethods() { var cd = Apex.ClassDeclaration.Parse(" class Program { void main() {} }"); - Assert.True(cd.Methods.Any()); - Assert.AreEqual("Program", cd.Identifier); + Assert.That(cd.Methods.Any(), Is.True); + Assert.That(cd.Identifier, Is.EqualTo("Program")); var md = cd.Methods.Single(); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.AreEqual("main", md.Identifier); - Assert.False(md.Parameters.Any()); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Identifier, Is.EqualTo("main")); + Assert.That(md.Parameters.Any(), Is.False); // class declarations with bad methods - Assert.Throws(() => Apex.ClassDeclaration.Parse(" class Test { void Main }")); - Assert.Throws(() => Apex.ClassDeclaration.Parse("class Apex { int main() }")); + Assert.That(() => Apex.ClassDeclaration.Parse(" class Test { void Main }"), Throws.TypeOf()); + Assert.That(() => Apex.ClassDeclaration.Parse("class Apex { int main() }"), Throws.TypeOf()); } [Test] public void ClassDeclarationCanHaveMultipleModifiers() { var cd = Apex.ClassDeclaration.Parse(" public with sharing webservice class Program { }"); - Assert.False(cd.Methods.Any()); - Assert.AreEqual("Program", cd.Identifier); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("Program")); - Assert.AreEqual(3, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("with sharing", cd.Modifiers[1]); - Assert.AreEqual("webservice", cd.Modifiers[2]); + Assert.That(cd.Modifiers.Count, Is.EqualTo(3)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("with sharing")); + Assert.That(cd.Modifiers[2], Is.EqualTo("webservice")); // class declarations with bad methods - Assert.Throws(() => Apex.ClassDeclaration.Parse(" class with Test { }")); - Assert.Throws(() => Apex.ClassDeclaration.Parse("class sharing Test { }")); + Assert.That(() => Apex.ClassDeclaration.Parse(" class with Test { }"), Throws.TypeOf()); + Assert.That(() => Apex.ClassDeclaration.Parse("class sharing Test { }"), Throws.TypeOf()); } [Test] public void ClassInitializerIsABlockWithOptionalStaticModifier() { var ci = Apex.ClassInitializer.Parse(" /* initial value */ { i = 0; } "); - Assert.NotNull(ci.Body); - Assert.AreEqual(0, ci.Modifiers.Count); - Assert.AreEqual(1, ci.LeadingComments.Count); - Assert.AreEqual("initial value", ci.LeadingComments[0].Trim()); - Assert.AreEqual(1, ci.Body.Statements.Count); - Assert.AreEqual("i = 0", ci.Body.Statements[0].Body); + Assert.That(ci.Body, Is.Not.Null); + Assert.That(ci.Modifiers.Count, Is.EqualTo(0)); + Assert.That(ci.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(ci.LeadingComments[0].Trim(), Is.EqualTo("initial value")); + Assert.That(ci.Body.Statements.Count, Is.EqualTo(1)); + Assert.That(ci.Body.Statements[0].Body, Is.EqualTo("i = 0")); ci = Apex.ClassInitializer.Parse(" static { counter = 0; } "); - Assert.NotNull(ci.Body); - Assert.AreEqual(0, ci.LeadingComments.Count); - Assert.AreEqual(1, ci.Modifiers.Count); - Assert.AreEqual("static", ci.Modifiers[0]); - Assert.AreEqual(1, ci.Body.Statements.Count); - Assert.AreEqual("counter = 0", ci.Body.Statements[0].Body); + Assert.That(ci.Body, Is.Not.Null); + Assert.That(ci.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(ci.Modifiers.Count, Is.EqualTo(1)); + Assert.That(ci.Modifiers[0], Is.EqualTo("static")); + Assert.That(ci.Body.Statements.Count, Is.EqualTo(1)); + Assert.That(ci.Body.Statements[0].Body, Is.EqualTo("counter = 0")); // bad class initializers - Assert.Throws(() => Apex.ClassInitializer.Parse("}")); - Assert.Throws(() => Apex.ClassInitializer.End().Parse("{}}")); + Assert.That(() => Apex.ClassInitializer.Parse("}"), Throws.TypeOf()); + Assert.That(() => Apex.ClassInitializer.End().Parse("{}}"), Throws.TypeOf()); } [Test] @@ -1081,32 +1081,32 @@ public void ClassDeclarationCanHaveInstanceInitializationCode() } }"); - Assert.False(cd.Methods.Any()); - Assert.AreEqual(3, cd.Initializers.Count); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Initializers.Count, Is.EqualTo(3)); var init = cd.Initializers[0]; - Assert.AreEqual(0, init.Modifiers.Count); - Assert.AreEqual(1, init.LeadingComments.Count); - Assert.AreEqual("instance initializer", init.LeadingComments[0].Trim()); - Assert.NotNull(init.Body); - Assert.AreEqual(1, init.Body.Statements.Count); - Assert.AreEqual("System.debug('instance initialization code #1')", init.Body.Statements[0].Body); + Assert.That(init.Modifiers.Count, Is.EqualTo(0)); + Assert.That(init.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(init.LeadingComments[0].Trim(), Is.EqualTo("instance initializer")); + Assert.That(init.Body, Is.Not.Null); + Assert.That(init.Body.Statements.Count, Is.EqualTo(1)); + Assert.That(init.Body.Statements[0].Body, Is.EqualTo("System.debug('instance initialization code #1')")); init = cd.Initializers[1]; - Assert.AreEqual(0, init.LeadingComments.Count); - Assert.AreEqual(1, init.Modifiers.Count); - Assert.AreEqual("static", init.Modifiers[0]); - Assert.NotNull(init.Body); - Assert.AreEqual(1, init.Body.Statements.Count); - Assert.AreEqual("System.debug('static initialization code #0')", init.Body.Statements[0].Body); + Assert.That(init.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(init.Modifiers.Count, Is.EqualTo(1)); + Assert.That(init.Modifiers[0], Is.EqualTo("static")); + Assert.That(init.Body, Is.Not.Null); + Assert.That(init.Body.Statements.Count, Is.EqualTo(1)); + Assert.That(init.Body.Statements[0].Body, Is.EqualTo("System.debug('static initialization code #0')")); init = cd.Initializers[2]; - Assert.AreEqual(1, init.LeadingComments.Count); - Assert.AreEqual("another instance initializer", init.LeadingComments[0].Trim()); - Assert.AreEqual(0, init.Modifiers.Count); - Assert.NotNull(init.Body); - Assert.AreEqual(1, init.Body.Statements.Count); - Assert.AreEqual("System.debug('instance initialization code #2')", init.Body.Statements[0].Body); + Assert.That(init.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(init.LeadingComments[0].Trim(), Is.EqualTo("another instance initializer")); + Assert.That(init.Modifiers.Count, Is.EqualTo(0)); + Assert.That(init.Body, Is.Not.Null); + Assert.That(init.Body.Statements.Count, Is.EqualTo(1)); + Assert.That(init.Body.Statements[0].Body, Is.EqualTo("System.debug('instance initialization code #2')")); } [Test] @@ -1114,301 +1114,301 @@ public void ClassMemberDeclarationCanBeMethodPropertyOrClass() { var cm = Apex.ClassMemberDeclaration.Parse("@testFixture public with sharing class Program { }"); var cd = cm as ClassDeclarationSyntax; - Assert.NotNull(cd); - Assert.False(cd.Methods.Any()); - Assert.AreEqual("Program", cd.Identifier); + Assert.That(cd, Is.Not.Null); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("Program")); - Assert.AreEqual(1, cd.Annotations.Count); - Assert.AreEqual("testFixture", cd.Annotations[0].Identifier); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("with sharing", cd.Modifiers[1]); + Assert.That(cd.Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Annotations[0].Identifier, Is.EqualTo("testFixture")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("with sharing")); cm = Apex.ClassMemberDeclaration.Parse("private Disposable() { return null; }"); var md = cm as MethodDeclarationSyntax; - Assert.NotNull(md); + Assert.That(md, Is.Not.Null); - Assert.AreEqual("Disposable", md.Identifier); - Assert.AreEqual("Disposable", md.ReturnType.Identifier); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("private", md.Modifiers[0]); + Assert.That(md.Identifier, Is.EqualTo("Disposable")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("Disposable")); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("private")); var block = md.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("null", (block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That((block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("null")); cm = Apex.ClassMemberDeclaration.Parse("@required Boolean flag { set { throw; } get; }"); var pd = cm as PropertyDeclarationSyntax; - Assert.NotNull(pd); + Assert.That(pd, Is.Not.Null); - Assert.AreEqual("flag", pd.Identifier); - Assert.AreEqual("Boolean", pd.Type.Identifier); - Assert.NotNull(pd.Getter); - Assert.True(pd.Getter.IsEmpty); + Assert.That(pd.Identifier, Is.EqualTo("flag")); + Assert.That(pd.Type.Identifier, Is.EqualTo("Boolean")); + Assert.That(pd.Getter, Is.Not.Null); + Assert.That(pd.Getter.IsEmpty, Is.True); - Assert.NotNull(pd.Setter); + Assert.That(pd.Setter, Is.Not.Null); block = pd.Setter.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.IsInstanceOf(block.Statements[0]); - Assert.AreEqual(1, pd.Annotations.Count); - Assert.AreEqual("required", pd.Annotations[0].Identifier); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0], Is.InstanceOf()); + Assert.That(pd.Annotations.Count, Is.EqualTo(1)); + Assert.That(pd.Annotations[0].Identifier, Is.EqualTo("required")); cm = Apex.ClassMemberDeclaration.Parse("className Test { get; set; }"); pd = cm as PropertyDeclarationSyntax; - Assert.NotNull(pd); - Assert.NotNull(pd.Getter); - Assert.NotNull(pd.Setter); - Assert.True(pd.Getter.IsEmpty); - Assert.True(pd.Setter.IsEmpty); + Assert.That(pd, Is.Not.Null); + Assert.That(pd.Getter, Is.Not.Null); + Assert.That(pd.Setter, Is.Not.Null); + Assert.That(pd.Getter.IsEmpty, Is.True); + Assert.That(pd.Setter.IsEmpty, Is.True); cm = Apex.ClassMemberDeclaration.Parse("int a;"); var fd = cm as FieldDeclarationSyntax; - Assert.NotNull(fd); - Assert.NotNull(fd.Type); - Assert.NotNull(fd.Fields); - Assert.AreEqual(1, fd.Fields.Count); + Assert.That(fd, Is.Not.Null); + Assert.That(fd.Type, Is.Not.Null); + Assert.That(fd.Fields, Is.Not.Null); + Assert.That(fd.Fields.Count, Is.EqualTo(1)); cm = Apex.ClassMemberDeclaration.Parse("int a = 1;"); fd = cm as FieldDeclarationSyntax; - Assert.NotNull(fd); - Assert.NotNull(fd.Type); - Assert.NotNull(fd.Fields); - Assert.AreEqual(1, fd.Fields.Count); + Assert.That(fd, Is.Not.Null); + Assert.That(fd.Type, Is.Not.Null); + Assert.That(fd.Fields, Is.Not.Null); + Assert.That(fd.Fields.Count, Is.EqualTo(1)); cm = Apex.ClassMemberDeclaration.Parse("int a, b;"); fd = cm as FieldDeclarationSyntax; - Assert.NotNull(fd); - Assert.NotNull(fd.Type); - Assert.NotNull(fd.Fields); - Assert.AreEqual(2, fd.Fields.Count); + Assert.That(fd, Is.Not.Null); + Assert.That(fd.Type, Is.Not.Null); + Assert.That(fd.Fields, Is.Not.Null); + Assert.That(fd.Fields.Count, Is.EqualTo(2)); cm = Apex.ClassMemberDeclaration.Parse("int a = 1, b = 2;"); fd = cm as FieldDeclarationSyntax; - Assert.NotNull(fd); - Assert.NotNull(fd.Type); - Assert.NotNull(fd.Fields); - Assert.AreEqual(2, fd.Fields.Count); + Assert.That(fd, Is.Not.Null); + Assert.That(fd.Type, Is.Not.Null); + Assert.That(fd.Fields, Is.Not.Null); + Assert.That(fd.Fields.Count, Is.EqualTo(2)); cm = Apex.ClassMemberDeclaration.Parse("int a = 1, /* comment */ b = 2;"); fd = cm as FieldDeclarationSyntax; - Assert.NotNull(fd); - Assert.NotNull(fd.Type); - Assert.NotNull(fd.Fields); - Assert.AreEqual(2, fd.Fields.Count); + Assert.That(fd, Is.Not.Null); + Assert.That(fd.Type, Is.Not.Null); + Assert.That(fd.Fields, Is.Not.Null); + Assert.That(fd.Fields.Count, Is.EqualTo(2)); } [Test] public void EnumMemberDeclarationIsAnIdenfierWithPossibleComments() { var em = Apex.EnumMember.Parse(" /* default */ @test SomeValue "); - Assert.AreEqual(1, em.LeadingComments.Count); - Assert.AreEqual("default", em.LeadingComments[0].Trim()); - Assert.AreEqual(1, em.Annotations.Count); - Assert.AreEqual("test", em.Annotations[0].Identifier); - Assert.AreEqual("SomeValue", em.Identifier); + Assert.That(em.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(em.LeadingComments[0].Trim(), Is.EqualTo("default")); + Assert.That(em.Annotations.Count, Is.EqualTo(1)); + Assert.That(em.Annotations[0].Identifier, Is.EqualTo("test")); + Assert.That(em.Identifier, Is.EqualTo("SomeValue")); em = Apex.EnumMember.End().Parse(" SomeValue /* some value */"); - Assert.AreEqual(0, em.Annotations.Count); - Assert.AreEqual("SomeValue", em.Identifier); + Assert.That(em.Annotations.Count, Is.EqualTo(0)); + Assert.That(em.Identifier, Is.EqualTo("SomeValue")); - Assert.Throws(() => Apex.EnumMember.Parse(" enum ")); + Assert.That(() => Apex.EnumMember.Parse(" enum "), Throws.TypeOf()); } [Test] public void EnumDeclarationIsANamedListOfCommaDelimitedIdentifiers() { var en = Apex.EnumDeclaration.Parse(" enum Boo { Tru, Fa } "); - Assert.AreEqual("Boo", en.Identifier); - Assert.AreEqual(0, en.Modifiers.Count); - Assert.AreEqual(0, en.LeadingComments.Count); - Assert.AreEqual(0, en.Annotations.Count); - Assert.AreEqual(2, en.Members.Count); - Assert.AreEqual("Tru", en.Members[0].Identifier); - Assert.AreEqual("Fa", en.Members[1].Identifier); + Assert.That(en.Identifier, Is.EqualTo("Boo")); + Assert.That(en.Modifiers.Count, Is.EqualTo(0)); + Assert.That(en.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(en.Annotations.Count, Is.EqualTo(0)); + Assert.That(en.Members.Count, Is.EqualTo(2)); + Assert.That(en.Members[0].Identifier, Is.EqualTo("Tru")); + Assert.That(en.Members[1].Identifier, Is.EqualTo("Fa")); en = Apex.EnumDeclaration.Parse(" /* Months */ @test public enum Month { /* January */ Jan, Mar, Dec } "); - Assert.AreEqual("Month", en.Identifier); - Assert.AreEqual(1, en.Modifiers.Count); - Assert.AreEqual("public", en.Modifiers[0]); - Assert.AreEqual(1, en.LeadingComments.Count); - Assert.AreEqual("Months", en.LeadingComments[0].Trim()); - Assert.AreEqual(1, en.Annotations.Count); - Assert.AreEqual("test", en.Annotations[0].Identifier); - Assert.AreEqual(3, en.Members.Count); - Assert.AreEqual("Jan", en.Members[0].Identifier); - Assert.AreEqual(1, en.Members[0].LeadingComments.Count); - Assert.AreEqual("January", en.Members[0].LeadingComments[0].Trim()); - Assert.AreEqual("Mar", en.Members[1].Identifier); - Assert.AreEqual("Dec", en.Members[2].Identifier); + Assert.That(en.Identifier, Is.EqualTo("Month")); + Assert.That(en.Modifiers.Count, Is.EqualTo(1)); + Assert.That(en.Modifiers[0], Is.EqualTo("public")); + Assert.That(en.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(en.LeadingComments[0].Trim(), Is.EqualTo("Months")); + Assert.That(en.Annotations.Count, Is.EqualTo(1)); + Assert.That(en.Annotations[0].Identifier, Is.EqualTo("test")); + Assert.That(en.Members.Count, Is.EqualTo(3)); + Assert.That(en.Members[0].Identifier, Is.EqualTo("Jan")); + Assert.That(en.Members[0].LeadingComments.Count, Is.EqualTo(1)); + Assert.That(en.Members[0].LeadingComments[0].Trim(), Is.EqualTo("January")); + Assert.That(en.Members[1].Identifier, Is.EqualTo("Mar")); + Assert.That(en.Members[2].Identifier, Is.EqualTo("Dec")); en = Apex.EnumDeclaration.Parse(" enum Boo /* Boolean */ { Tru, Fa } "); - Assert.AreEqual("Boo", en.Identifier); - Assert.AreEqual(0, en.Modifiers.Count); - Assert.AreEqual(0, en.LeadingComments.Count); - Assert.AreEqual(0, en.Annotations.Count); - Assert.AreEqual(2, en.Members.Count); - Assert.AreEqual("Tru", en.Members[0].Identifier); - Assert.AreEqual("Fa", en.Members[1].Identifier); + Assert.That(en.Identifier, Is.EqualTo("Boo")); + Assert.That(en.Modifiers.Count, Is.EqualTo(0)); + Assert.That(en.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(en.Annotations.Count, Is.EqualTo(0)); + Assert.That(en.Members.Count, Is.EqualTo(2)); + Assert.That(en.Members[0].Identifier, Is.EqualTo("Tru")); + Assert.That(en.Members[1].Identifier, Is.EqualTo("Fa")); } [Test] public void KeywordExpressionStatementHandlesInsertDeleteAndReturn() { var ret = Apex.ReturnStatement.Parse(" return contact; "); - Assert.AreEqual("contact", ret.Expression.ExpressionString); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("contact")); ret = Apex.ReturnStatement.Parse(" return; "); - Assert.IsNull(ret.Expression); + Assert.That(ret.Expression, Is.Null); var ins = Apex.InsertStatement.Parse(" insert contact; "); - Assert.AreEqual("contact", ins.Expression.ExpressionString); + Assert.That(ins.Expression.ExpressionString, Is.EqualTo("contact")); var del = Apex.DeleteStatement.Parse(" delete\tuser;"); - Assert.AreEqual("user", del.Expression.ExpressionString); + Assert.That(del.Expression.ExpressionString, Is.EqualTo("user")); var upd = Apex.UpdateStatement.Parse(" update \r\n items;"); - Assert.AreEqual("items", upd.Expression.ExpressionString); + Assert.That(upd.Expression.ExpressionString, Is.EqualTo("items")); - Assert.Throws(() => Apex.InsertStatement.Parse(" insert ;")); - Assert.Throws(() => Apex.DeleteStatement.Parse(" delete ;")); - Assert.Throws(() => Apex.UpdateStatement.Parse(" update ;")); + Assert.That(() => Apex.InsertStatement.Parse(" insert ;"), Throws.TypeOf()); + Assert.That(() => Apex.DeleteStatement.Parse(" delete ;"), Throws.TypeOf()); + Assert.That(() => Apex.UpdateStatement.Parse(" update ;"), Throws.TypeOf()); } [Test] public void UnknownGenericStatementIsAnythingExceptBlockEndingWithATerminator() { var stmt = Apex.UnknownGenericStatement.Parse("return 'Hello World';"); - Assert.AreEqual("return 'Hello World'", stmt.Body); + Assert.That(stmt.Body, Is.EqualTo("return 'Hello World'")); - Assert.Throws(() => Apex.UnknownGenericStatement.Parse("if {}")); + Assert.That(() => Apex.UnknownGenericStatement.Parse("if {}"), Throws.TypeOf()); } [Test] public void StringLiteralIsAnExpressionInSingleQuotes() { var str = Apex.StringLiteral.Parse(" 'Hello' "); - Assert.AreEqual("'Hello'", str); + Assert.That(str, Is.EqualTo("'Hello'")); str = Apex.StringLiteral.Parse(@" 'wo\rld\'!' "); - Assert.AreEqual(@"'wo\rld\'!'", str); + Assert.That(str, Is.EqualTo(@"'wo\rld\'!'")); str = Apex.StringLiteral.Parse(@" ' wo\rld\'! ' "); - Assert.AreEqual(@"' wo\rld\'! '", str); + Assert.That(str, Is.EqualTo(@"' wo\rld\'! '")); - Assert.Throws(() => Apex.StringLiteral.Parse("'")); + Assert.That(() => Apex.StringLiteral.Parse("'"), Throws.TypeOf()); } [Test] public void GenericExpressionInBracesCanBeAnythingProvidedThatBracesAreMatched() { var expr = Apex.GenericExpressionInBraces().Parse("(something.IsEmpty)"); - Assert.AreEqual("something.IsEmpty", expr); + Assert.That(expr, Is.EqualTo("something.IsEmpty")); expr = Apex.GenericExpressionInBraces().Parse(" ( something.IsEmpty( ) ) "); - Assert.AreEqual("something.IsEmpty()", expr); + Assert.That(expr, Is.EqualTo("something.IsEmpty()")); - Assert.Throws(() => Apex.GenericExpressionInBraces().Parse("(something.IsEmpty(()")); - Assert.Throws(() => Apex.GenericExpressionInBraces().Parse("(")); - Assert.Throws(() => Apex.GenericExpressionInBraces().Parse(")")); + Assert.That(() => Apex.GenericExpressionInBraces().Parse("(something.IsEmpty(()"), Throws.TypeOf()); + Assert.That(() => Apex.GenericExpressionInBraces().Parse("("), Throws.TypeOf()); + Assert.That(() => Apex.GenericExpressionInBraces().Parse(")"), Throws.TypeOf()); } [Test] public void GenericExpressionCanBeAnythingProvidedThatBracesAreMatched() { var expr = Apex.GenericExpression.Parse("something.IsEmpty()"); - Assert.AreEqual("something.IsEmpty()", expr); + Assert.That(expr, Is.EqualTo("something.IsEmpty()")); expr = Apex.GenericExpression.Parse("(something.IsEmpty)"); - Assert.AreEqual("(something.IsEmpty)", expr); + Assert.That(expr, Is.EqualTo("(something.IsEmpty)")); expr = Apex.GenericExpression.Parse(" ( something.IsEmpty( ) ) "); - Assert.AreEqual("(something.IsEmpty())", expr); + Assert.That(expr, Is.EqualTo("(something.IsEmpty())")); expr = Apex.GenericExpression.Parse("(a, b, c(d, e))"); - Assert.AreEqual("(a, b, c(d, e))", expr); + Assert.That(expr, Is.EqualTo("(a, b, c(d, e))")); expr = Apex.GenericExpression.Parse("[select a, b from users]"); - Assert.AreEqual("[select a, b from users]", expr); + Assert.That(expr, Is.EqualTo("[select a, b from users]")); expr = Apex.GenericExpression.Parse("';'"); - Assert.AreEqual("';'", expr); + Assert.That(expr, Is.EqualTo("';'")); expr = Apex.GenericExpression.Parse(" new Map "); - Assert.AreEqual("new Map", expr); + Assert.That(expr, Is.EqualTo("new Map")); - Assert.Throws(() => Apex.GenericExpression.Parse("(something.IsEmpty(()")); - Assert.Throws(() => Apex.GenericExpression.Parse("(")); - Assert.Throws(() => Apex.GenericExpression.Parse(")")); + Assert.That(() => Apex.GenericExpression.Parse("(something.IsEmpty(()"), Throws.TypeOf()); + Assert.That(() => Apex.GenericExpression.Parse("("), Throws.TypeOf()); + Assert.That(() => Apex.GenericExpression.Parse(")"), Throws.TypeOf()); } [Test] public void GenericNewExpressionIsANewKeywordFollowedByATypeReference() { var nx = Apex.GenericNewExpression.Parse(" new string "); - Assert.AreEqual("new String", nx); + Assert.That(nx, Is.EqualTo("new String")); nx = Apex.GenericNewExpression.Parse(" new Map "); - Assert.AreEqual("new Map", nx); + Assert.That(nx, Is.EqualTo("new Map")); nx = Apex.GenericNewExpression.Parse(" new Map< List < string, boolean >, string> "); - Assert.AreEqual("new Map, String>", nx); + Assert.That(nx, Is.EqualTo("new Map, String>")); - Assert.Throws(() => Apex.GenericNewExpression.Parse(" new ")); - Assert.Throws(() => Apex.GenericNewExpression.End().Parse(" new map <>")); + Assert.That(() => Apex.GenericNewExpression.Parse(" new "), Throws.TypeOf()); + Assert.That(() => Apex.GenericNewExpression.End().Parse(" new map <>"), Throws.TypeOf()); } [Test] public void SimpleIfStatementCanCompileWithoutElseBranch() { var ifstmt = Apex.IfStatement.Parse("if (true) return null;"); - Assert.AreEqual("true", ifstmt.Expression.ExpressionString); - Assert.AreEqual("null", (ifstmt.ThenStatement as ReturnStatementSyntax).Expression.ExpressionString); - Assert.IsNull(ifstmt.ElseStatement); + Assert.That(ifstmt.Expression.ExpressionString, Is.EqualTo("true")); + Assert.That((ifstmt.ThenStatement as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("null")); + Assert.That(ifstmt.ElseStatement, Is.Null); - Assert.Throws(() => Apex.IfStatement.Parse("if {}")); - Assert.Throws(() => Apex.IfStatement.Parse("if )")); + Assert.That(() => Apex.IfStatement.Parse("if {}"), Throws.TypeOf()); + Assert.That(() => Apex.IfStatement.Parse("if )"), Throws.TypeOf()); } [Test] public void IfStatementCanCompileWithElseBranch() { var ifstmt = Apex.IfStatement.Parse("if (false) return 'yes'; else return 'no';"); - Assert.AreEqual("false", ifstmt.Expression.ExpressionString); - Assert.AreEqual("'yes'", (ifstmt.ThenStatement as ReturnStatementSyntax).Expression.ExpressionString); - Assert.AreEqual("'no'", (ifstmt.ElseStatement as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(ifstmt.Expression.ExpressionString, Is.EqualTo("false")); + Assert.That((ifstmt.ThenStatement as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'yes'")); + Assert.That((ifstmt.ElseStatement as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'no'")); - Assert.Throws(() => Apex.IfStatement.End().Parse("if (true) return null; else}")); + Assert.That(() => Apex.IfStatement.End().Parse("if (true) return null; else}"), Throws.TypeOf()); } [Test] public void IfStatementCanCompileWithACommentBeforeTheElseBranch() { var ifstmt = Apex.IfStatement.Parse("if (false) return 'yes'; /* oops */ else return 'no';"); - Assert.AreEqual("false", ifstmt.Expression.ExpressionString); - Assert.AreEqual("'yes'", (ifstmt.ThenStatement as ReturnStatementSyntax).Expression.ExpressionString); - Assert.AreEqual("'no'", (ifstmt.ElseStatement as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(ifstmt.Expression.ExpressionString, Is.EqualTo("false")); + Assert.That((ifstmt.ThenStatement as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'yes'")); + Assert.That((ifstmt.ElseStatement as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'no'")); - Assert.Throws(() => Apex.IfStatement.End().Parse("if (true) return null; else")); + Assert.That(() => Apex.IfStatement.End().Parse("if (true) return null; else"), Throws.TypeOf()); } [Test] public void IfStatementCanHaveBlocksForThenAndElseBranches() { var ifstmt = Apex.IfStatement.Parse("if (false) { return 'yes'; } else { return 'no'; }"); - Assert.AreEqual("false", ifstmt.Expression.ExpressionString); + Assert.That(ifstmt.Expression.ExpressionString, Is.EqualTo("false")); var block = ifstmt.ThenStatement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("'yes'", (block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That((block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'yes'")); block = ifstmt.ElseStatement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("'no'", (block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That((block.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'no'")); - Assert.Throws(() => Apex.IfStatement.End().Parse("if (true) {return null; else {}")); + Assert.That(() => Apex.IfStatement.End().Parse("if (true) {return null; else {}"), Throws.TypeOf()); } [Test] @@ -1420,16 +1420,16 @@ public void ForEachStatementHasAnExpressionAndABody() System.debug(c.Email); }"); - Assert.AreEqual("Contact", forStmt.Type.Identifier); - Assert.AreEqual("c", forStmt.Identifier); - Assert.AreEqual("contacts", forStmt.Expression.ExpressionString); + Assert.That(forStmt.Type.Identifier, Is.EqualTo("Contact")); + Assert.That(forStmt.Identifier, Is.EqualTo("c")); + Assert.That(forStmt.Expression.ExpressionString, Is.EqualTo("contacts")); var blockStmt = forStmt.Statement as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); - Assert.AreEqual("System.debug(c.Email)", blockStmt.Statements[0].Body); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); + Assert.That(blockStmt.Statements[0].Body, Is.EqualTo("System.debug(c.Email)")); - Assert.Throws(() => Apex.ForEachStatement.Parse("for (;;) {}")); + Assert.That(() => Apex.ForEachStatement.Parse("for (;;) {}"), Throws.TypeOf()); } [Test] @@ -1440,18 +1440,18 @@ public void ForStatementHasAnExpressionAndABody() { System.debug(c.Email); }"); - Assert.NotNull(forStmt); - Assert.IsNull(forStmt.Declaration); - Assert.IsNull(forStmt.Condition); - Assert.NotNull(forStmt.Incrementors); - Assert.False(forStmt.Incrementors.Any()); + Assert.That(forStmt, Is.Not.Null); + Assert.That(forStmt.Declaration, Is.Null); + Assert.That(forStmt.Condition, Is.Null); + Assert.That(forStmt.Incrementors, Is.Not.Null); + Assert.That(forStmt.Incrementors.Any(), Is.False); var blockStmt = forStmt.Statement as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); - Assert.AreEqual("System.debug(c.Email)", blockStmt.Statements[0].Body); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); + Assert.That(blockStmt.Statements[0].Body, Is.EqualTo("System.debug(c.Email)")); - Assert.Throws(() => Apex.ForStatement.Parse("for {}")); + Assert.That(() => Apex.ForStatement.Parse("for {}"), Throws.TypeOf()); } [Test] @@ -1464,89 +1464,89 @@ public void DoStatementHasABodyAndAnExpression() } while (list.isEmpty());"); - Assert.NotNull(doWhileStmt); - Assert.AreEqual("list.isEmpty()", doWhileStmt.Expression.ExpressionString); + Assert.That(doWhileStmt, Is.Not.Null); + Assert.That(doWhileStmt.Expression.ExpressionString, Is.EqualTo("list.isEmpty()")); var blockStmt = doWhileStmt.Statement as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); - Assert.AreEqual("list.add(c.Email)", blockStmt.Statements[0].Body); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); + Assert.That(blockStmt.Statements[0].Body, Is.EqualTo("list.add(c.Email)")); - Assert.Throws(() => Apex.ForStatement.Parse("do {} while;")); + Assert.That(() => Apex.ForStatement.Parse("do {} while;"), Throws.TypeOf()); } [Test] public void VariableDeclarationCanDeclareOneOrMoreVariablesWithOptionalInitializerExpressions() { var variable = Apex.VariableDeclaration.Parse(" int x ; "); - Assert.AreEqual("int", variable.Type.Identifier); - Assert.IsFalse(variable.Type.IsArray); - Assert.AreEqual(1, variable.Variables.Count); - Assert.AreEqual("x", variable.Variables[0].Identifier); - Assert.IsNull(variable.Variables[0].Expression); + Assert.That(variable.Type.Identifier, Is.EqualTo("int")); + Assert.That(variable.Type.IsArray, Is.False); + Assert.That(variable.Variables.Count, Is.EqualTo(1)); + Assert.That(variable.Variables[0].Identifier, Is.EqualTo("x")); + Assert.That(variable.Variables[0].Expression, Is.Null); variable = Apex.VariableDeclaration.Parse(" string name, lastName; "); - Assert.AreEqual("String", variable.Type.Identifier); - Assert.IsFalse(variable.Type.IsArray); - Assert.AreEqual(2, variable.Variables.Count); - Assert.AreEqual("name", variable.Variables[0].Identifier); - Assert.IsNull(variable.Variables[0].Expression); - Assert.AreEqual("lastName", variable.Variables[1].Identifier); - Assert.IsNull(variable.Variables[1].Expression); + Assert.That(variable.Type.Identifier, Is.EqualTo("String")); + Assert.That(variable.Type.IsArray, Is.False); + Assert.That(variable.Variables.Count, Is.EqualTo(2)); + Assert.That(variable.Variables[0].Identifier, Is.EqualTo("name")); + Assert.That(variable.Variables[0].Expression, Is.Null); + Assert.That(variable.Variables[1].Identifier, Is.EqualTo("lastName")); + Assert.That(variable.Variables[1].Expression, Is.Null); variable = Apex.VariableDeclaration.Parse(" Map[] dates = GetDates(), temp, other; "); - Assert.AreEqual("Map", variable.Type.Identifier); - Assert.IsTrue(variable.Type.IsArray); - Assert.AreEqual(2, variable.Type.TypeParameters.Count); - Assert.AreEqual("String", variable.Type.TypeParameters[0].Identifier); - Assert.AreEqual("Datetime", variable.Type.TypeParameters[1].Identifier); - Assert.AreEqual(3, variable.Variables.Count); - Assert.AreEqual("dates", variable.Variables[0].Identifier); - Assert.AreEqual("GetDates()", variable.Variables[0].Expression.ExpressionString); - Assert.AreEqual("temp", variable.Variables[1].Identifier); - Assert.IsNull(variable.Variables[1].Expression); - Assert.AreEqual("other", variable.Variables[2].Identifier); - Assert.IsNull(variable.Variables[2].Expression); + Assert.That(variable.Type.Identifier, Is.EqualTo("Map")); + Assert.That(variable.Type.IsArray, Is.True); + Assert.That(variable.Type.TypeParameters.Count, Is.EqualTo(2)); + Assert.That(variable.Type.TypeParameters[0].Identifier, Is.EqualTo("String")); + Assert.That(variable.Type.TypeParameters[1].Identifier, Is.EqualTo("Datetime")); + Assert.That(variable.Variables.Count, Is.EqualTo(3)); + Assert.That(variable.Variables[0].Identifier, Is.EqualTo("dates")); + Assert.That(variable.Variables[0].Expression.ExpressionString, Is.EqualTo("GetDates()")); + Assert.That(variable.Variables[1].Identifier, Is.EqualTo("temp")); + Assert.That(variable.Variables[1].Expression, Is.Null); + Assert.That(variable.Variables[2].Identifier, Is.EqualTo("other")); + Assert.That(variable.Variables[2].Expression, Is.Null); // incomplete variable declarations - Assert.Throws(() => Apex.VariableDeclarator.End().Parse("int x = ")); - Assert.Throws(() => Apex.VariableDeclarator.End().Parse("char c, b = ;")); + Assert.That(() => Apex.VariableDeclarator.End().Parse("int x = "), Throws.TypeOf()); + Assert.That(() => Apex.VariableDeclarator.End().Parse("char c, b = ;"), Throws.TypeOf()); } [Test] public void VariableDeclarationCanHaveExpressionsWithCommasInIt() { var variable = Apex.VariableDeclaration.Parse("int a = test(1,2,3);"); - Assert.AreEqual("int", variable.Type.Identifier); - Assert.AreEqual(1, variable.Variables.Count); - Assert.AreEqual("a", variable.Variables[0].Identifier); - Assert.AreEqual("test(1,2,3)", variable.Variables[0].Expression.ExpressionString); + Assert.That(variable.Type.Identifier, Is.EqualTo("int")); + Assert.That(variable.Variables.Count, Is.EqualTo(1)); + Assert.That(variable.Variables[0].Identifier, Is.EqualTo("a")); + Assert.That(variable.Variables[0].Expression.ExpressionString, Is.EqualTo("test(1,2,3)")); variable = Apex.VariableDeclaration.Parse("int x = new[] {1,2,3};"); - Assert.AreEqual("int", variable.Type.Identifier); - Assert.AreEqual(1, variable.Variables.Count); - Assert.AreEqual("x", variable.Variables[0].Identifier); - Assert.AreEqual("new[]{1,2,3}", variable.Variables[0].Expression.ExpressionString); + Assert.That(variable.Type.Identifier, Is.EqualTo("int")); + Assert.That(variable.Variables.Count, Is.EqualTo(1)); + Assert.That(variable.Variables[0].Identifier, Is.EqualTo("x")); + Assert.That(variable.Variables[0].Expression.ExpressionString, Is.EqualTo("new[]{1,2,3}")); } [Test] public void VariableDeclaratorIsAnIdentifierFollowedByOptionalExpression() { var variable = Apex.VariableDeclarator.Parse(" name = 'Bozo'"); - Assert.AreEqual("name", variable.Identifier); - Assert.AreEqual("'Bozo'", variable.Expression.ExpressionString); + Assert.That(variable.Identifier, Is.EqualTo("name")); + Assert.That(variable.Expression.ExpressionString, Is.EqualTo("'Bozo'")); variable = Apex.VariableDeclarator.Parse(" date "); - Assert.AreEqual("date", variable.Identifier); - Assert.IsNull(variable.Expression); + Assert.That(variable.Identifier, Is.EqualTo("date")); + Assert.That(variable.Expression, Is.Null); variable = Apex.VariableDeclarator.Parse(" now = DateTime.Now()"); - Assert.AreEqual("now", variable.Identifier); - Assert.AreEqual("DateTime.Now()", variable.Expression.ExpressionString); + Assert.That(variable.Identifier, Is.EqualTo("now")); + Assert.That(variable.Expression.ExpressionString, Is.EqualTo("DateTime.Now()")); // incomplete variable declarator - Assert.Throws(() => Apex.VariableDeclarator.End().Parse("x = ")); - Assert.Throws(() => Apex.VariableDeclarator.End().Parse("y = ;")); + Assert.That(() => Apex.VariableDeclarator.End().Parse("x = "), Throws.TypeOf()); + Assert.That(() => Apex.VariableDeclarator.End().Parse("y = ;"), Throws.TypeOf()); } [Test] @@ -1558,33 +1558,33 @@ public void WhileStatementHasAnExpressionAndABody() list.add(c.Email); }"); - Assert.NotNull(whileStmt); - Assert.AreEqual("list.isEmpty()", whileStmt.Expression.ExpressionString); + Assert.That(whileStmt, Is.Not.Null); + Assert.That(whileStmt.Expression.ExpressionString, Is.EqualTo("list.isEmpty()")); var blockStmt = whileStmt.Statement as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); - Assert.AreEqual("list.add(c.Email)", blockStmt.Statements[0].Body); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); + Assert.That(blockStmt.Statements[0].Body, Is.EqualTo("list.add(c.Email)")); - Assert.Throws(() => Apex.ForStatement.Parse("while true {}")); + Assert.That(() => Apex.ForStatement.Parse("while true {}"), Throws.TypeOf()); } [Test] public void BreakStatementHasNoParameters() { var breakStmt = Apex.BreakStatement.Parse(" break ; "); - Assert.NotNull(breakStmt); + Assert.That(breakStmt, Is.Not.Null); - Assert.Throws(() => Apex.BreakStatement.Parse("break")); + Assert.That(() => Apex.BreakStatement.Parse("break"), Throws.TypeOf()); } [Test] public void ContinueStatementHasNoParameters() { var contStmt = Apex.ContinueStatement.Parse(" continue ; "); - Assert.NotNull(contStmt); + Assert.That(contStmt, Is.Not.Null); - Assert.Throws(() => Apex.ContinueStatement.Parse("continue")); + Assert.That(() => Apex.ContinueStatement.Parse("continue"), Throws.TypeOf()); } [Test] @@ -1594,30 +1594,30 @@ public void RunAsMethodHasSpecialSyntaxHenceIsHandledAsAStatement() System.RunAs(new Version(1, 0)) { System.debug('wow!'); }"); - Assert.AreEqual("new Version(1, 0)", runAs.Expression.ExpressionString); + Assert.That(runAs.Expression.ExpressionString, Is.EqualTo("new Version(1, 0)")); var block = runAs.Statement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug('wow!')", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug('wow!')")); runAs = Apex.RunAsStatement.Parse(@" System.RunAs(new Version(1, 0)) System.debug('wow!');"); - Assert.AreEqual("new Version(1, 0)", runAs.Expression.ExpressionString); - Assert.NotNull(runAs.Statement); - Assert.AreEqual("System.debug('wow!')", runAs.Statement.Body); + Assert.That(runAs.Expression.ExpressionString, Is.EqualTo("new Version(1, 0)")); + Assert.That(runAs.Statement, Is.Not.Null); + Assert.That(runAs.Statement.Body, Is.EqualTo("System.debug('wow!')")); } [Test] public void ThrowStatementIsParsed() { var thr = Apex.ThrowStatement.Parse(" throw new NotImplementedException('Oops');"); - Assert.NotNull(thr); - Assert.AreEqual("new NotImplementedException('Oops')", thr.Expression.ExpressionString); + Assert.That(thr, Is.Not.Null); + Assert.That(thr.Expression.ExpressionString, Is.EqualTo("new NotImplementedException('Oops')")); thr = Apex.ThrowStatement.Parse(" throw;"); - Assert.NotNull(thr); - Assert.IsNull(thr.Expression); + Assert.That(thr, Is.Not.Null); + Assert.That(thr.Expression, Is.Null); } [Test] @@ -1625,41 +1625,41 @@ public void StatementRuleParsesStatementsOfAnyKind() { var stmt = Apex.Statement.Parse("if (false) return 'yes'; else return 'no';"); var ifstmt = stmt as IfStatementSyntax; - Assert.NotNull(ifstmt); - Assert.AreEqual("false", ifstmt.Expression.ExpressionString); + Assert.That(ifstmt, Is.Not.Null); + Assert.That(ifstmt.Expression.ExpressionString, Is.EqualTo("false")); var ret = ifstmt.ThenStatement as ReturnStatementSyntax; - Assert.NotNull(ret); - Assert.NotNull(ret.Expression); - Assert.AreEqual("'yes'", ret.Expression.ExpressionString); + Assert.That(ret, Is.Not.Null); + Assert.That(ret.Expression, Is.Not.Null); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("'yes'")); ret = ifstmt.ElseStatement as ReturnStatementSyntax; - Assert.NotNull(ret); - Assert.NotNull(ret.Expression); - Assert.AreEqual("'no'", ret.Expression.ExpressionString); + Assert.That(ret, Is.Not.Null); + Assert.That(ret.Expression, Is.Not.Null); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("'no'")); stmt = Apex.Statement.Parse("{ return x; }"); var blockStmt = stmt as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); ret = blockStmt.Statements[0] as ReturnStatementSyntax; - Assert.NotNull(ret); - Assert.NotNull(ret.Expression); - Assert.AreEqual("x", ret.Expression.ExpressionString); + Assert.That(ret, Is.Not.Null); + Assert.That(ret.Expression, Is.Not.Null); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("x")); stmt = Apex.Statement.Parse("return 'Hello World';"); ret = stmt as ReturnStatementSyntax; - Assert.NotNull(ret); - Assert.NotNull(ret.Expression); - Assert.AreEqual("'Hello World'", ret.Expression.ExpressionString); + Assert.That(ret, Is.Not.Null); + Assert.That(ret.Expression, Is.Not.Null); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("'Hello World'")); stmt = Apex.Statement.Parse("insert something;"); var ins = stmt as InsertStatementSyntax; - Assert.NotNull(ins); - Assert.AreEqual("something", ins.Expression.ExpressionString); + Assert.That(ins, Is.Not.Null); + Assert.That(ins.Expression.ExpressionString, Is.EqualTo("something")); stmt = Apex.Statement.Parse("return null;"); ret = stmt as ReturnStatementSyntax; - Assert.NotNull(ret); - Assert.AreEqual("null", ret.Expression.ExpressionString); + Assert.That(ret, Is.Not.Null); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("null")); stmt = Apex.Statement.Parse(@" for (Contact c : contacts) @@ -1667,15 +1667,15 @@ public void StatementRuleParsesStatementsOfAnyKind() System.debug(c.Email); }"); var forEachStmt = stmt as ForEachStatementSyntax; - Assert.NotNull(forEachStmt); - Assert.AreEqual("Contact", forEachStmt.Type.Identifier); - Assert.AreEqual("c", forEachStmt.Identifier); - Assert.AreEqual("contacts", forEachStmt.Expression.ExpressionString); + Assert.That(forEachStmt, Is.Not.Null); + Assert.That(forEachStmt.Type.Identifier, Is.EqualTo("Contact")); + Assert.That(forEachStmt.Identifier, Is.EqualTo("c")); + Assert.That(forEachStmt.Expression.ExpressionString, Is.EqualTo("contacts")); blockStmt = forEachStmt.Statement as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); - Assert.AreEqual("System.debug(c.Email)", blockStmt.Statements[0].Body); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); + Assert.That(blockStmt.Statements[0].Body, Is.EqualTo("System.debug(c.Email)")); stmt = Apex.ForStatement.Parse(@" for (;;) @@ -1683,16 +1683,16 @@ public void StatementRuleParsesStatementsOfAnyKind() System.debug(c.Email); }"); var forStmt = stmt as ForStatementSyntax; - Assert.NotNull(forStmt); - Assert.IsNull(forStmt.Declaration); - Assert.IsNull(forStmt.Condition); - Assert.NotNull(forStmt.Incrementors); - Assert.False(forStmt.Incrementors.Any()); + Assert.That(forStmt, Is.Not.Null); + Assert.That(forStmt.Declaration, Is.Null); + Assert.That(forStmt.Condition, Is.Null); + Assert.That(forStmt.Incrementors, Is.Not.Null); + Assert.That(forStmt.Incrementors.Any(), Is.False); blockStmt = forStmt.Statement as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); - Assert.AreEqual("System.debug(c.Email)", blockStmt.Statements[0].Body); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); + Assert.That(blockStmt.Statements[0].Body, Is.EqualTo("System.debug(c.Email)")); stmt = Apex.Statement.Parse(@" do @@ -1702,14 +1702,14 @@ public void StatementRuleParsesStatementsOfAnyKind() while (list.isEmpty());"); var doWhileStmt = stmt as DoStatementSyntax; - Assert.NotNull(doWhileStmt); - Assert.AreEqual("list.isEmpty()", doWhileStmt.Expression.ExpressionString); + Assert.That(doWhileStmt, Is.Not.Null); + Assert.That(doWhileStmt.Expression.ExpressionString, Is.EqualTo("list.isEmpty()")); blockStmt = doWhileStmt.Statement as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); var breakStmt = blockStmt.Statements[0] as BreakStatementSyntax; - Assert.NotNull(breakStmt); + Assert.That(breakStmt, Is.Not.Null); stmt = Apex.Statement.Parse(@" while (list.isEmpty()) @@ -1718,60 +1718,60 @@ public void StatementRuleParsesStatementsOfAnyKind() }"); var whileStmt = stmt as WhileStatementSyntax; - Assert.NotNull(whileStmt); - Assert.AreEqual("list.isEmpty()", whileStmt.Expression.ExpressionString); + Assert.That(whileStmt, Is.Not.Null); + Assert.That(whileStmt.Expression.ExpressionString, Is.EqualTo("list.isEmpty()")); blockStmt = whileStmt.Statement as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); - Assert.AreEqual("list.add(c.Email)", blockStmt.Statements[0].Body); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); + Assert.That(blockStmt.Statements[0].Body, Is.EqualTo("list.add(c.Email)")); stmt = Apex.Statement.Parse(@" int x = 10;"); var varDecl = stmt as VariableDeclarationSyntax; - Assert.NotNull(varDecl); + Assert.That(varDecl, Is.Not.Null); stmt = Apex.Statement.Parse(@" System.RunAs(new Version(1, 0)) { System.debug('wow!'); }"); var runAs = stmt as RunAsStatementSyntax; - Assert.NotNull(runAs); - Assert.AreEqual("new Version(1, 0)", runAs.Expression.ExpressionString); + Assert.That(runAs, Is.Not.Null); + Assert.That(runAs.Expression.ExpressionString, Is.EqualTo("new Version(1, 0)")); var block = runAs.Statement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug('wow!')", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug('wow!')")); stmt = Apex.Statement.Parse(" insert contact; "); ins = stmt as InsertStatementSyntax; - Assert.NotNull(ins); - Assert.AreEqual("contact", ins.Expression.ExpressionString); + Assert.That(ins, Is.Not.Null); + Assert.That(ins.Expression.ExpressionString, Is.EqualTo("contact")); stmt = Apex.Statement.Parse(" delete\tuser;"); var del = stmt as DeleteStatementSyntax; - Assert.NotNull(del); - Assert.AreEqual("user", del.Expression.ExpressionString); + Assert.That(del, Is.Not.Null); + Assert.That(del.Expression.ExpressionString, Is.EqualTo("user")); stmt = Apex.Statement.Parse(" update \r\n items;"); var upd = stmt as UpdateStatementSyntax; - Assert.NotNull(upd); - Assert.AreEqual("items", upd.Expression.ExpressionString); + Assert.That(upd, Is.Not.Null); + Assert.That(upd.Expression.ExpressionString, Is.EqualTo("items")); stmt = Apex.Statement.Parse(" upsert contact; "); var ups = stmt as UpsertStatementSyntax; - Assert.NotNull(ups); - Assert.AreEqual("contact", ups.Expression.ExpressionString); + Assert.That(ups, Is.Not.Null); + Assert.That(ups.Expression.ExpressionString, Is.EqualTo("contact")); stmt = Apex.Statement.Parse(" throw new NotImplementedException('Oops');"); var thr = stmt as ThrowStatementSyntax; - Assert.NotNull(thr); - Assert.AreEqual("new NotImplementedException('Oops')", thr.Expression.ExpressionString); + Assert.That(thr, Is.Not.Null); + Assert.That(thr.Expression.ExpressionString, Is.EqualTo("new NotImplementedException('Oops')")); stmt = Apex.Statement.Parse(" switch on x { when y { return; } when else { return; } }"); var swst = stmt as SwitchStatementSyntax; - Assert.NotNull(swst); - Assert.AreEqual("x", swst.Expression.ExpressionString); - Assert.AreEqual(2, swst.WhenClauses.Count); + Assert.That(swst, Is.Not.Null); + Assert.That(swst.Expression.ExpressionString, Is.EqualTo("x")); + Assert.That(swst.WhenClauses.Count, Is.EqualTo(2)); } [Test] @@ -1781,111 +1781,111 @@ public void StatementRuleSupportsComments() // this is a dumb comment if (false) return 'yes'; else return 'no';"); var ifstmt = stmt as IfStatementSyntax; - Assert.NotNull(ifstmt); - Assert.AreEqual("false", ifstmt.Expression.ExpressionString); - Assert.AreEqual("'yes'", (ifstmt.ThenStatement as ReturnStatementSyntax).Expression.ExpressionString); - Assert.AreEqual("'no'", (ifstmt.ElseStatement as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(ifstmt, Is.Not.Null); + Assert.That(ifstmt.Expression.ExpressionString, Is.EqualTo("false")); + Assert.That((ifstmt.ThenStatement as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'yes'")); + Assert.That((ifstmt.ElseStatement as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'no'")); stmt = Apex.Statement.Parse("/* here goes the block statement */ { return x; }"); var blockStmt = stmt as BlockSyntax; - Assert.NotNull(blockStmt); - Assert.AreEqual(1, blockStmt.Statements.Count); - Assert.AreEqual("x", (blockStmt.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(blockStmt, Is.Not.Null); + Assert.That(blockStmt.Statements.Count, Is.EqualTo(1)); + Assert.That((blockStmt.Statements[0] as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("x")); stmt = Apex.Statement.Parse("/* greeting //*/ return 'Hello World';"); - Assert.AreEqual("'Hello World'", (stmt as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That((stmt as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("'Hello World'")); } [Test] public void CatchExpressionClauseIsATypeAndNameInBraces() { var cexpr = Apex.CatchExpressionTypeName.Parse(" ( exception )"); - Assert.AreEqual("Exception", cexpr.Type.Identifier); - Assert.IsNull(cexpr.Identifier); + Assert.That(cexpr.Type.Identifier, Is.EqualTo("Exception")); + Assert.That(cexpr.Identifier, Is.Null); cexpr = Apex.CatchExpressionTypeName.Parse("(NullReferenceException ex )"); - Assert.AreEqual("NullReferenceException", cexpr.Type.Identifier); - Assert.AreEqual("ex", cexpr.Identifier); + Assert.That(cexpr.Type.Identifier, Is.EqualTo("NullReferenceException")); + Assert.That(cexpr.Identifier, Is.EqualTo("ex")); - Assert.Throws(() => Apex.CatchExpressionTypeName.Parse("()")); + Assert.That(() => Apex.CatchExpressionTypeName.Parse("()"), Throws.TypeOf()); } [Test] public void CatchExpressionClauseCanHaveTypeNameOrNothing() { var cexpr = Apex.CatchClause.Parse("catch ( exception ) { return; }"); - Assert.AreEqual("Exception", cexpr.Type.Identifier); - Assert.IsNull(cexpr.Identifier); - Assert.NotNull(cexpr.Block); - Assert.AreEqual(1, cexpr.Block.Statements.Count); + Assert.That(cexpr.Type.Identifier, Is.EqualTo("Exception")); + Assert.That(cexpr.Identifier, Is.Null); + Assert.That(cexpr.Block, Is.Not.Null); + Assert.That(cexpr.Block.Statements.Count, Is.EqualTo(1)); cexpr = Apex.CatchClause.Parse("catch (NullReferenceException ex ) { break; }"); - Assert.AreEqual("NullReferenceException", cexpr.Type.Identifier); - Assert.AreEqual("ex", cexpr.Identifier); - Assert.NotNull(cexpr.Block); - Assert.AreEqual(1, cexpr.Block.Statements.Count); + Assert.That(cexpr.Type.Identifier, Is.EqualTo("NullReferenceException")); + Assert.That(cexpr.Identifier, Is.EqualTo("ex")); + Assert.That(cexpr.Block, Is.Not.Null); + Assert.That(cexpr.Block.Statements.Count, Is.EqualTo(1)); cexpr = Apex.CatchClause.Parse("catch { throw; }"); - Assert.IsNull(cexpr.Type); - Assert.IsNull(cexpr.Identifier); - Assert.NotNull(cexpr.Block); - Assert.AreEqual(1, cexpr.Block.Statements.Count); + Assert.That(cexpr.Type, Is.Null); + Assert.That(cexpr.Identifier, Is.Null); + Assert.That(cexpr.Block, Is.Not.Null); + Assert.That(cexpr.Block.Statements.Count, Is.EqualTo(1)); - Assert.Throws(() => Apex.CatchClause.Parse("catch () {}")); + Assert.That(() => Apex.CatchClause.Parse("catch () {}"), Throws.TypeOf()); } [Test] public void FinallyClauseIsParsed() { var fc = Apex.FinallyClause.Parse(" finally { /* nothing here */ return; } "); - Assert.NotNull(fc.Block); - Assert.AreEqual(1, fc.Block.Statements.Count); + Assert.That(fc.Block, Is.Not.Null); + Assert.That(fc.Block.Statements.Count, Is.EqualTo(1)); - Assert.Throws(() => Apex.FinallyClause.Parse("finally () {}")); + Assert.That(() => Apex.FinallyClause.Parse("finally () {}"), Throws.TypeOf()); } [Test] public void TryCatchStatementCanHaveTypeNameOrNothing() { var ts = Apex.TryCatchFinallyStatement.Parse(" try { break; } catch ( exception ) { return; }"); - Assert.NotNull(ts.Block); - Assert.AreEqual(1, ts.Block.Statements.Count); - Assert.AreEqual(1, ts.Catches.Count); + Assert.That(ts.Block, Is.Not.Null); + Assert.That(ts.Block.Statements.Count, Is.EqualTo(1)); + Assert.That(ts.Catches.Count, Is.EqualTo(1)); var cexpr = ts.Catches[0]; - Assert.AreEqual("Exception", cexpr.Type.Identifier); - Assert.IsNull(cexpr.Identifier); - Assert.NotNull(cexpr.Block); - Assert.AreEqual(1, cexpr.Block.Statements.Count); + Assert.That(cexpr.Type.Identifier, Is.EqualTo("Exception")); + Assert.That(cexpr.Identifier, Is.Null); + Assert.That(cexpr.Block, Is.Not.Null); + Assert.That(cexpr.Block.Statements.Count, Is.EqualTo(1)); ts = Apex.TryCatchFinallyStatement.Parse("try { /* nothing */ } catch (NullReferenceException ex) { break; } catch { throw; }"); - Assert.NotNull(ts.Block); - Assert.AreEqual(0, ts.Block.Statements.Count); - Assert.AreEqual(2, ts.Catches.Count); + Assert.That(ts.Block, Is.Not.Null); + Assert.That(ts.Block.Statements.Count, Is.EqualTo(0)); + Assert.That(ts.Catches.Count, Is.EqualTo(2)); cexpr = ts.Catches[0]; - Assert.AreEqual("NullReferenceException", cexpr.Type.Identifier); - Assert.AreEqual("ex", cexpr.Identifier); - Assert.NotNull(cexpr.Block); - Assert.AreEqual(1, cexpr.Block.Statements.Count); + Assert.That(cexpr.Type.Identifier, Is.EqualTo("NullReferenceException")); + Assert.That(cexpr.Identifier, Is.EqualTo("ex")); + Assert.That(cexpr.Block, Is.Not.Null); + Assert.That(cexpr.Block.Statements.Count, Is.EqualTo(1)); cexpr = ts.Catches[1]; - Assert.IsNull(cexpr.Type); - Assert.IsNull(cexpr.Identifier); - Assert.NotNull(cexpr.Block); - Assert.AreEqual(1, cexpr.Block.Statements.Count); + Assert.That(cexpr.Type, Is.Null); + Assert.That(cexpr.Identifier, Is.Null); + Assert.That(cexpr.Block, Is.Not.Null); + Assert.That(cexpr.Block.Statements.Count, Is.EqualTo(1)); ts = Apex.TryCatchFinallyStatement.Parse(" try { break; } catch { return; } finally { throw; }"); - Assert.NotNull(ts.Block); - Assert.AreEqual(1, ts.Block.Statements.Count); - Assert.AreEqual(1, ts.Catches.Count); + Assert.That(ts.Block, Is.Not.Null); + Assert.That(ts.Block.Statements.Count, Is.EqualTo(1)); + Assert.That(ts.Catches.Count, Is.EqualTo(1)); cexpr = ts.Catches[0]; - Assert.IsNull(cexpr.Type); - Assert.IsNull(cexpr.Identifier); - Assert.NotNull(cexpr.Block); - Assert.AreEqual(1, cexpr.Block.Statements.Count); - Assert.NotNull(ts.Finally); - Assert.NotNull(ts.Finally.Block); - Assert.AreEqual(1, ts.Finally.Block.Statements.Count); + Assert.That(cexpr.Type, Is.Null); + Assert.That(cexpr.Identifier, Is.Null); + Assert.That(cexpr.Block, Is.Not.Null); + Assert.That(cexpr.Block.Statements.Count, Is.EqualTo(1)); + Assert.That(ts.Finally, Is.Not.Null); + Assert.That(ts.Finally.Block, Is.Not.Null); + Assert.That(ts.Finally.Block.Statements.Count, Is.EqualTo(1)); ts = Apex.TryCatchFinallyStatement.Parse(@" try // leading for block @@ -1902,20 +1902,20 @@ public void TryCatchStatementCanHaveTypeNameOrNothing() { // inside the block } // trailing for the block"); - Assert.Throws(() => Apex.TryCatchFinallyStatement.Parse("try {}")); + Assert.That(() => Apex.TryCatchFinallyStatement.Parse("try {}"), Throws.TypeOf()); } [Test] public void TryFinallyStatementCanBeWithoutAnyCatches() { var ts = Apex.TryCatchFinallyStatement.Parse("try {} finally {}"); - Assert.NotNull(ts.Block); - Assert.False(ts.Block.Statements.Any()); - Assert.NotNull(ts.Finally); - Assert.NotNull(ts.Finally.Block); - Assert.False(ts.Finally.Block.Statements.Any()); + Assert.That(ts.Block, Is.Not.Null); + Assert.That(ts.Block.Statements.Any(), Is.False); + Assert.That(ts.Finally, Is.Not.Null); + Assert.That(ts.Finally.Block, Is.Not.Null); + Assert.That(ts.Finally.Block.Statements.Any(), Is.False); - Assert.Throws(() => Apex.TryCatchFinallyStatement.Parse("try {} finally")); + Assert.That(() => Apex.TryCatchFinallyStatement.Parse("try {} finally"), Throws.TypeOf()); } [Test] @@ -1927,12 +1927,12 @@ public void BlockStatementCanBeCommented() return new List(); /* comments */ }"); - Assert.AreEqual(2, stmt.Statements.Count); - Assert.AreEqual("final string methodSig = 'Something'", stmt.Statements[0].Body); + Assert.That(stmt.Statements.Count, Is.EqualTo(2)); + Assert.That(stmt.Statements[0].Body, Is.EqualTo("final string methodSig = 'Something'")); var ret = stmt.Statements[1] as ReturnStatementSyntax; - Assert.NotNull(ret); - Assert.NotNull(ret.Expression); - Assert.AreEqual("new List()", ret.Expression.ExpressionString); + Assert.That(ret, Is.Not.Null); + Assert.That(ret.Expression, Is.Not.Null); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("new List()")); } [Test] @@ -1947,16 +1947,16 @@ It has two lines. */ return new List(); /* comments */ }"); - Assert.AreEqual(3, stmt.LeadingComments.Count); - Assert.AreEqual(2, stmt.Statements.Count); - Assert.AreEqual("final string methodSig = 'Something'", stmt.Statements[0].Body); - Assert.AreEqual(1, stmt.Statements[0].TrailingComments.Count); - Assert.AreEqual("method contents might not be valid", stmt.Statements[0].TrailingComments[0].Trim()); + Assert.That(stmt.LeadingComments.Count, Is.EqualTo(3)); + Assert.That(stmt.Statements.Count, Is.EqualTo(2)); + Assert.That(stmt.Statements[0].Body, Is.EqualTo("final string methodSig = 'Something'")); + Assert.That(stmt.Statements[0].TrailingComments.Count, Is.EqualTo(1)); + Assert.That(stmt.Statements[0].TrailingComments[0].Trim(), Is.EqualTo("method contents might not be valid")); var ret = stmt.Statements[1] as ReturnStatementSyntax; - Assert.AreEqual("new List()", ret.Expression.ExpressionString); - Assert.AreEqual(1, stmt.Statements[1].TrailingComments.Count); - Assert.AreEqual("comments", stmt.Statements[1].TrailingComments[0].Trim()); - Assert.AreEqual(0, stmt.TrailingComments.Count); + Assert.That(ret.Expression.ExpressionString, Is.EqualTo("new List()")); + Assert.That(stmt.Statements[1].TrailingComments.Count, Is.EqualTo(1)); + Assert.That(stmt.Statements[1].TrailingComments[0].Trim(), Is.EqualTo("comments")); + Assert.That(stmt.TrailingComments.Count, Is.EqualTo(0)); } // [Test] // TODO: Try to improve the diagnostics @@ -1978,7 +1978,7 @@ private List sort(List pkgList) } catch (ParseExceptionCustom ex) { - Assert.AreEqual(5, ex.LineNumber); + Assert.That(ex.LineNumber, Is.EqualTo(5)); } } @@ -1991,9 +1991,9 @@ public void WhenElseClause() delete x; }"); - Assert.NotNull(stmt); - Assert.NotNull(stmt.Block); - Assert.AreEqual(1, stmt.Block.Statements.Count); + Assert.That(stmt, Is.Not.Null); + Assert.That(stmt.Block, Is.Not.Null); + Assert.That(stmt.Block.Statements.Count, Is.EqualTo(1)); } [Test] @@ -2004,32 +2004,32 @@ when Agent x { insert x; }"); - Assert.NotNull(stmt); - Assert.NotNull(stmt.Block); - Assert.AreEqual(1, stmt.Block.Statements.Count); + Assert.That(stmt, Is.Not.Null); + Assert.That(stmt.Block, Is.Not.Null); + Assert.That(stmt.Block.Statements.Count, Is.EqualTo(1)); } [Test] public void SwitchExpression() { - Assert.AreEqual("1", Apex.SwitchExpression.Parse(" 1 ")); - Assert.AreEqual("1 + 2 + 3.0", Apex.SwitchExpression.Parse(" 1 + 2 + 3.0 // hoho ")); - Assert.AreEqual("'two'", Apex.SwitchExpression.Parse(" 'two' ")); - Assert.AreEqual("SUNDAY", Apex.SwitchExpression.Parse(" SUNDAY ")); - Assert.AreEqual("WeekDays . Friday", Apex.SwitchExpression.Parse(" WeekDays . Friday ")); + Assert.That(Apex.SwitchExpression.Parse(" 1 "), Is.EqualTo("1")); + Assert.That(Apex.SwitchExpression.Parse(" 1 + 2 + 3.0 // hoho "), Is.EqualTo("1 + 2 + 3.0")); + Assert.That(Apex.SwitchExpression.Parse(" 'two' "), Is.EqualTo("'two'")); + Assert.That(Apex.SwitchExpression.Parse(" SUNDAY "), Is.EqualTo("SUNDAY")); + Assert.That(Apex.SwitchExpression.Parse(" WeekDays . Friday "), Is.EqualTo("WeekDays . Friday")); } [Test] public void WhenExpressionListWithAFewItems() { var exprs = Apex.WhenExpressions.Parse(" 1, 'two', 1+2+3.0 "); - Assert.NotNull(exprs); + Assert.That(exprs, Is.Not.Null); var xl = exprs.ToList(); - Assert.AreEqual(3, xl.Count); - Assert.AreEqual("1", xl[0].ExpressionString); - Assert.AreEqual("'two'", xl[1].ExpressionString); - Assert.AreEqual("1+2+3.0", xl[2].ExpressionString); + Assert.That(xl.Count, Is.EqualTo(3)); + Assert.That(xl[0].ExpressionString, Is.EqualTo("1")); + Assert.That(xl[1].ExpressionString, Is.EqualTo("'two'")); + Assert.That(xl[2].ExpressionString, Is.EqualTo("1+2+3.0")); } [Test] @@ -2040,9 +2040,9 @@ public void WhenExpressionsClauseWithSingleExpression() return null; }"); - Assert.NotNull(stmt); - Assert.NotNull(stmt.Block); - Assert.AreEqual(1, stmt.Block.Statements.Count); + Assert.That(stmt, Is.Not.Null); + Assert.That(stmt.Block, Is.Not.Null); + Assert.That(stmt.Block.Statements.Count, Is.EqualTo(1)); } [Test] @@ -2057,9 +2057,9 @@ public void WhenClauses() foreach (var s in samples) { var stmt = Apex.WhenClause.Parse(s); - Assert.NotNull(stmt); - Assert.NotNull(stmt.Block); - Assert.AreEqual(0, stmt.Block.Statements.Count); + Assert.That(stmt, Is.Not.Null); + Assert.That(stmt.Block, Is.Not.Null); + Assert.That(stmt.Block.Statements.Count, Is.EqualTo(0)); } // invalid samples — all these are parsed as when expression { } @@ -2093,152 +2093,152 @@ when string s { } }"); - Assert.NotNull(stmt); - Assert.AreEqual("a + x[10]* 5 + 'two'", stmt.Expression.ExpressionString); - Assert.NotNull(stmt.WhenClauses); - Assert.AreEqual(3, stmt.WhenClauses.Count); + Assert.That(stmt, Is.Not.Null); + Assert.That(stmt.Expression.ExpressionString, Is.EqualTo("a + x[10]* 5 + 'two'")); + Assert.That(stmt.WhenClauses, Is.Not.Null); + Assert.That(stmt.WhenClauses.Count, Is.EqualTo(3)); var wx = stmt.WhenClauses[0] as WhenExpressionsClauseSyntax; - Assert.IsNotNull(wx); - Assert.AreEqual(1, wx.LeadingComments.Count); - Assert.AreEqual(0, wx.TrailingComments.Count); - Assert.AreEqual(3, wx.Expressions.Count); - Assert.IsNotNull(wx.Block); - Assert.AreEqual(1, wx.Block.Statements.Count); - Assert.AreEqual(0, wx.Block.LeadingComments.Count); - Assert.AreEqual(0, wx.Block.TrailingComments.Count); + Assert.That(wx, Is.Not.Null); + Assert.That(wx.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(wx.TrailingComments.Count, Is.EqualTo(0)); + Assert.That(wx.Expressions.Count, Is.EqualTo(3)); + Assert.That(wx.Block, Is.Not.Null); + Assert.That(wx.Block.Statements.Count, Is.EqualTo(1)); + Assert.That(wx.Block.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(wx.Block.TrailingComments.Count, Is.EqualTo(0)); var wt = stmt.WhenClauses[1] as WhenTypeClauseSyntax; - Assert.IsNotNull(wt); - Assert.AreEqual(1, wt.LeadingComments.Count); - Assert.AreEqual(0, wt.TrailingComments.Count); - Assert.AreEqual("String", wt.Type.Identifier); - Assert.IsNotNull(wt.Block); - Assert.AreEqual(2, wt.Block.Statements.Count); - Assert.AreEqual(0, wt.Block.LeadingComments.Count); - Assert.AreEqual(1, wt.Block.TrailingComments.Count); + Assert.That(wt, Is.Not.Null); + Assert.That(wt.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(wt.TrailingComments.Count, Is.EqualTo(0)); + Assert.That(wt.Type.Identifier, Is.EqualTo("String")); + Assert.That(wt.Block, Is.Not.Null); + Assert.That(wt.Block.Statements.Count, Is.EqualTo(2)); + Assert.That(wt.Block.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(wt.Block.TrailingComments.Count, Is.EqualTo(1)); var we = stmt.WhenClauses[2] as WhenElseClauseSyntax; - Assert.IsNotNull(we); - Assert.AreEqual(1, we.LeadingComments.Count); - Assert.AreEqual(0, we.TrailingComments.Count); - Assert.IsNotNull(we.Block); - Assert.AreEqual(3, we.Block.Statements.Count); - Assert.AreEqual(0, we.Block.LeadingComments.Count); - Assert.AreEqual(0, we.Block.TrailingComments.Count); + Assert.That(we, Is.Not.Null); + Assert.That(we.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(we.TrailingComments.Count, Is.EqualTo(0)); + Assert.That(we.Block, Is.Not.Null); + Assert.That(we.Block.Statements.Count, Is.EqualTo(3)); + Assert.That(we.Block.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(we.Block.TrailingComments.Count, Is.EqualTo(0)); } [Test] public void DecimalLiteralExpression() { var expr = Apex.DecimalLiteralExpression.Parse("1.23"); - Assert.NotNull(expr); - Assert.AreEqual("1.23", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("1.23")); expr = Apex.DecimalLiteralExpression.Parse(".234567890"); - Assert.NotNull(expr); - Assert.AreEqual(".234567890", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo(".234567890")); - Assert.Throws(() => Apex.DecimalLiteralExpression.Parse("")); - Assert.Throws(() => Apex.DecimalLiteralExpression.Parse("'123'")); - Assert.Throws(() => Apex.DecimalLiteralExpression.Parse("true")); + Assert.That(() => Apex.DecimalLiteralExpression.Parse(""), Throws.TypeOf()); + Assert.That(() => Apex.DecimalLiteralExpression.Parse("'123'"), Throws.TypeOf()); + Assert.That(() => Apex.DecimalLiteralExpression.Parse("true"), Throws.TypeOf()); } [Test] public void StringLiteralExpression() { var expr = Apex.StringLiteralExpression.Parse("'hi there'"); - Assert.NotNull(expr); - Assert.AreEqual("'hi there'", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("'hi there'")); expr = Apex.StringLiteralExpression.Parse("'oh great!\\r\\n'"); - Assert.NotNull(expr); - Assert.AreEqual("'oh great!\\r\\n'", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("'oh great!\\r\\n'")); - Assert.Throws(() => Apex.StringLiteralExpression.Parse("")); - Assert.Throws(() => Apex.StringLiteralExpression.Parse("123")); - Assert.Throws(() => Apex.StringLiteralExpression.Parse("true")); + Assert.That(() => Apex.StringLiteralExpression.Parse(""), Throws.TypeOf()); + Assert.That(() => Apex.StringLiteralExpression.Parse("123"), Throws.TypeOf()); + Assert.That(() => Apex.StringLiteralExpression.Parse("true"), Throws.TypeOf()); } [Test] public void BooleanLiteralExpression() { var expr = Apex.BooleanLiteralExpression.Parse("true"); - Assert.NotNull(expr); - Assert.AreEqual("true", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("true")); expr = Apex.BooleanLiteralExpression.Parse("false"); - Assert.NotNull(expr); - Assert.AreEqual("false", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("false")); // keywords are normalized expr = Apex.BooleanLiteralExpression.Parse("True"); - Assert.NotNull(expr); - Assert.AreEqual("true", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("true")); expr = Apex.BooleanLiteralExpression.Parse("FALSE"); - Assert.NotNull(expr); - Assert.AreEqual("false", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("false")); - Assert.Throws(() => Apex.BooleanLiteralExpression.Parse("")); - Assert.Throws(() => Apex.BooleanLiteralExpression.Parse("123")); - Assert.Throws(() => Apex.BooleanLiteralExpression.Parse("'true'")); + Assert.That(() => Apex.BooleanLiteralExpression.Parse(""), Throws.TypeOf()); + Assert.That(() => Apex.BooleanLiteralExpression.Parse("123"), Throws.TypeOf()); + Assert.That(() => Apex.BooleanLiteralExpression.Parse("'true'"), Throws.TypeOf()); } [Test] public void LiteralExpression() { var expr = Apex.LiteralExpression.Parse("true"); - Assert.NotNull(expr); - Assert.AreEqual("true", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("true")); expr = Apex.LiteralExpression.Parse("1.23"); - Assert.NotNull(expr); - Assert.AreEqual("1.23", expr.Token); - Assert.AreEqual(LiteralType.Numeric, expr.LiteralType); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("1.23")); + Assert.That(expr.LiteralType, Is.EqualTo(LiteralType.Numeric)); expr = Apex.LiteralExpression.Parse("FALSE"); - Assert.NotNull(expr); - Assert.AreEqual("false", expr.Token); - Assert.AreEqual(LiteralType.Boolean, expr.LiteralType); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("false")); + Assert.That(expr.LiteralType, Is.EqualTo(LiteralType.Boolean)); expr = Apex.LiteralExpression.Parse("NULL"); - Assert.NotNull(expr); - Assert.AreEqual("null", expr.Token); - Assert.AreEqual(LiteralType.Null, expr.LiteralType); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("null")); + Assert.That(expr.LiteralType, Is.EqualTo(LiteralType.Null)); expr = Apex.LiteralExpression.Parse("'foo\\rbar\\n'"); - Assert.NotNull(expr); - Assert.AreEqual("'foo\\rbar\\n'", expr.Token); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("'foo\\rbar\\n'")); expr = Apex.LiteralExpression.Parse(@"// behold! 'cool' // a cool string"); - Assert.NotNull(expr); - Assert.AreEqual("'cool'", expr.Token); - Assert.AreEqual(1, expr.LeadingComments.Count); - Assert.AreEqual("behold!", expr.LeadingComments.First().Trim()); - Assert.AreEqual(1, expr.TrailingComments.Count); - Assert.AreEqual("a cool string", expr.TrailingComments.First().Trim()); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("'cool'")); + Assert.That(expr.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(expr.LeadingComments.First().Trim(), Is.EqualTo("behold!")); + Assert.That(expr.TrailingComments.Count, Is.EqualTo(1)); + Assert.That(expr.TrailingComments.First().Trim(), Is.EqualTo("a cool string")); - Assert.Throws(() => Apex.LiteralExpression.End().Parse("")); - Assert.Throws(() => Apex.LiteralExpression.End().Parse("123+345")); - Assert.Throws(() => Apex.LiteralExpression.End().Parse("true | false")); + Assert.That(() => Apex.LiteralExpression.End().Parse(""), Throws.TypeOf()); + Assert.That(() => Apex.LiteralExpression.End().Parse("123+345"), Throws.TypeOf()); + Assert.That(() => Apex.LiteralExpression.End().Parse("true | false"), Throws.TypeOf()); } [Test] public void FactorExpression() { var expr = Apex.FactorExpression.Parse("true") as LiteralExpressionSyntax; - Assert.NotNull(expr); - Assert.AreEqual("true", expr.Token); - Assert.AreEqual(LiteralType.Boolean, expr.LiteralType); + Assert.That(expr, Is.Not.Null); + Assert.That(expr.Token, Is.EqualTo("true")); + Assert.That(expr.LiteralType, Is.EqualTo(LiteralType.Boolean)); var pexpr = Apex.FactorExpression.Parse("(1+2)"); - Assert.NotNull(pexpr); - Assert.AreEqual("(1+2)", pexpr.ExpressionString); + Assert.That(pexpr, Is.Not.Null); + Assert.That(pexpr.ExpressionString, Is.EqualTo("(1+2)")); - Assert.Throws(() => Apex.FactorExpression.End().Parse("")); - Assert.Throws(() => Apex.FactorExpression.End().Parse("123+345")); + Assert.That(() => Apex.FactorExpression.End().Parse(""), Throws.TypeOf()); + Assert.That(() => Apex.FactorExpression.End().Parse("123+345"), Throws.TypeOf()); } } } diff --git a/ApexSharp.ApexParser.Tests/Parser/ApexRegressionTests.cs b/ApexSharp.ApexParser.Tests/Parser/ApexRegressionTests.cs index 3565aac..efb81e4 100644 --- a/ApexSharp.ApexParser.Tests/Parser/ApexRegressionTests.cs +++ b/ApexSharp.ApexParser.Tests/Parser/ApexRegressionTests.cs @@ -19,18 +19,18 @@ public class ApexRegressionTests public void AccountDaoExtendsBaseDaoIsParsed() { var cd = Apex.ClassDeclaration.Parse("public with sharing class AccountDAO extends BaseDAO { }"); - Assert.AreEqual("AccountDAO", cd.Identifier); - Assert.AreEqual("BaseDAO", cd.BaseType.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("AccountDAO")); + Assert.That(cd.BaseType.Identifier, Is.EqualTo("BaseDAO")); } [Test] public void AccountDaoTestIsParsed() { var cd = Apex.ClassDeclaration.Parse("@IsTest(seeAllData = false) private class AccountDAOTest { }"); - Assert.AreEqual("AccountDAOTest", cd.Identifier); - Assert.AreEqual(1, cd.Annotations.Count); - Assert.AreEqual("IsTest", cd.Annotations[0].Identifier); - Assert.AreEqual("seeAllData = false", cd.Annotations[0].Parameters); + Assert.That(cd.Identifier, Is.EqualTo("AccountDAOTest")); + Assert.That(cd.Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(cd.Annotations[0].Parameters, Is.EqualTo("seeAllData = false")); } [Test] @@ -40,29 +40,29 @@ public void AccountTeamBatchClassIsParsed() var pt = Apex.TypeReference.Parse("Database.batchable"); var cd = Apex.ClassDeclaration.Parse("global class AccountTeamBatchClass implements Database.batchable { }"); - Assert.AreEqual("AccountTeamBatchClass", cd.Identifier); - Assert.AreEqual(1, cd.Interfaces.Count); - Assert.AreEqual(1, cd.Interfaces[0].Namespaces.Count); - Assert.AreEqual("Database", cd.Interfaces[0].Namespaces[0]); - Assert.AreEqual("batchable", cd.Interfaces[0].Identifier); + Assert.That(cd.Identifier, Is.EqualTo("AccountTeamBatchClass")); + Assert.That(cd.Interfaces.Count, Is.EqualTo(1)); + Assert.That(cd.Interfaces[0].Namespaces.Count, Is.EqualTo(1)); + Assert.That(cd.Interfaces[0].Namespaces[0], Is.EqualTo("Database")); + Assert.That(cd.Interfaces[0].Identifier, Is.EqualTo("batchable")); } [Test] public void TestMethodMyUnitTestIsParsed() { var md = Apex.MethodDeclaration.Parse("static testMethod void myUnitTest() { }"); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.AreEqual("myUnitTest", md.Identifier); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Identifier, Is.EqualTo("myUnitTest")); } [Test] public void AccountTeamScheduleBatchIsParsed() { var cd = Apex.ClassDeclaration.Parse("global class AccountTeamschduleBatch implements Schedulable { }"); - Assert.AreEqual("AccountTeamschduleBatch", cd.Identifier); - Assert.AreEqual(1, cd.Interfaces.Count); - Assert.False(cd.Interfaces[0].Namespaces.Any()); - Assert.AreEqual("Schedulable", cd.Interfaces[0].Identifier); + Assert.That(cd.Identifier, Is.EqualTo("AccountTeamschduleBatch")); + Assert.That(cd.Interfaces.Count, Is.EqualTo(1)); + Assert.That(cd.Interfaces[0].Namespaces.Any(), Is.False); + Assert.That(cd.Interfaces[0].Identifier, Is.EqualTo("Schedulable")); } [Test] @@ -75,7 +75,7 @@ class RecurrencyHelper static bool recurring = false; }"); - Assert.AreEqual(1, cd.Fields.Count); + Assert.That(cd.Fields.Count, Is.EqualTo(1)); } [Test] @@ -87,19 +87,19 @@ class DummyController Public String strVIN { get;set; } }"); - Assert.AreEqual(1, cd.Properties.Count); - Assert.AreEqual("strVIN", cd.Properties[0].Identifier); - Assert.AreEqual("String", cd.Properties[0].Type.Identifier); + Assert.That(cd.Properties.Count, Is.EqualTo(1)); + Assert.That(cd.Properties[0].Identifier, Is.EqualTo("strVIN")); + Assert.That(cd.Properties[0].Type.Identifier, Is.EqualTo("String")); } [Test] public void PostPaymentResponseExtendsExampleCompanyApi2ResponseObjectsResponseIsParsed() { var cd = Apex.ClassDeclaration.Parse("global class PostPaymentResponse extends ExampleCompany_API2_ResponseObjects.Response {}"); - Assert.AreEqual("PostPaymentResponse", cd.Identifier); - Assert.AreEqual(1, cd.BaseType.Namespaces.Count); - Assert.AreEqual("ExampleCompany_API2_ResponseObjects", cd.BaseType.Namespaces[0]); - Assert.AreEqual("Response", cd.BaseType.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("PostPaymentResponse")); + Assert.That(cd.BaseType.Namespaces.Count, Is.EqualTo(1)); + Assert.That(cd.BaseType.Namespaces[0], Is.EqualTo("ExampleCompany_API2_ResponseObjects")); + Assert.That(cd.BaseType.Identifier, Is.EqualTo("Response")); } [Test] @@ -115,8 +115,8 @@ void DummyMethod() } }"); - Assert.AreEqual(1, cd.Methods.Count); - Assert.AreEqual(1, cd.Methods[0].Body.Statements.Count); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[0].Body.Statements.Count, Is.EqualTo(1)); } [Test] @@ -130,8 +130,8 @@ static testMethod void testMethodForAgreementControllerX() } }"); - Assert.AreEqual(1, cd.Methods.Count); - Assert.AreEqual("testMethodForAgreementControllerX", cd.Methods[0].Identifier); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[0].Identifier, Is.EqualTo("testMethodForAgreementControllerX")); } [Test] @@ -144,7 +144,7 @@ class Dummy private integer batchSize = 0; }"); - Assert.AreEqual(2, cd.Fields.Count); + Assert.That(cd.Fields.Count, Is.EqualTo(2)); } [Test] @@ -158,13 +158,13 @@ public List getRecordsByVersionIdsStatusType(Set Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -298,7 +298,7 @@ public class Text private Map availableFields = new Map(); }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -313,7 +313,7 @@ private class Test public string commas = 'a,b,c', semicolons = 'c;d;e;'; // comments }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -339,19 +339,19 @@ void Test() } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] public void SystemTodayExpressionIsAllowed() { - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(@"class Text { DateTime t = System.today(); }")); + Assert.That(() => Apex.ClassDeclaration.Parse(@"class Text { DateTime t = System.today(); }"), Throws.Nothing); } [Test] public void SetKeywordCanBeUsedAsName() { - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(@"class Set { }")); + Assert.That(() => Apex.ClassDeclaration.Parse(@"class Set { }"), Throws.Nothing); } [Test] @@ -377,7 +377,7 @@ private class ExampleCompany_API_Utils_LoggerTest { } */ }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -397,7 +397,7 @@ global class Tax { } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -425,7 +425,7 @@ public Static ExampleCompany_API_QuoteManagementFacade.QuoteLineItem getProductR } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -450,7 +450,7 @@ static testMethod void RequestCertUsingAppVersionIdIdString() { } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -463,7 +463,7 @@ public static decimal convertCurrency(String fromISO, String toISO, Decimal amt) } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -479,7 +479,7 @@ String instrument(final String s) } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -494,7 +494,7 @@ private List sort(List pkgList) } "; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -513,7 +513,7 @@ public boolean isChangeCommitted } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -536,7 +536,7 @@ public static void eventSold(String vin ) } } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -554,7 +554,7 @@ @isTest public static void LogErrorExceptionWithMessage() } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -572,7 +572,7 @@ public void Test() } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -591,7 +591,7 @@ public void Test() } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -620,7 +620,7 @@ public void Test() } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -635,7 +635,7 @@ public void Test() } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -652,7 +652,7 @@ int b // second parameter } }"; - Assert.DoesNotThrow(() => Apex.ClassDeclaration.Parse(text)); + Assert.That(() => Apex.ClassDeclaration.Parse(text), Throws.Nothing); } [Test] @@ -667,11 +667,11 @@ interface InnerTest }"; var cd = Apex.ClassDeclaration.Parse(text); - Assert.AreEqual(1, cd.Members.Count); - Assert.AreEqual(1, cd.InnerClasses.Count); + Assert.That(cd.Members.Count, Is.EqualTo(1)); + Assert.That(cd.InnerClasses.Count, Is.EqualTo(1)); var inner = cd.Members.OfType().FirstOrDefault(); - Assert.NotNull(inner); + Assert.That(inner, Is.Not.Null); } [Test] @@ -690,9 +690,9 @@ void Hello() }"; var cd = Apex.ClassDeclaration.Parse(text); - Assert.AreEqual(1, cd.Methods.Count); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); var md = cd.Methods[0]; - Assert.AreEqual(1, md.LeadingComments.Count); + Assert.That(md.LeadingComments.Count, Is.EqualTo(1)); } [Test] @@ -711,13 +711,13 @@ class InnerTest }"; var cd = Apex.ClassDeclaration.Parse(text); - Assert.AreEqual(1, cd.InnerClasses.Count); - Assert.AreEqual(1, cd.InnerComments.Count); + Assert.That(cd.InnerClasses.Count, Is.EqualTo(1)); + Assert.That(cd.InnerComments.Count, Is.EqualTo(1)); cd = cd.InnerClasses[0]; - Assert.AreEqual(1, cd.LeadingComments.Count); - Assert.AreEqual(1, cd.InnerComments.Count); - Assert.AreEqual(1, cd.TrailingComments.Count); + Assert.That(cd.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(cd.InnerComments.Count, Is.EqualTo(1)); + Assert.That(cd.TrailingComments.Count, Is.EqualTo(1)); } [Test] @@ -747,7 +747,7 @@ global void finish(Database.BatchableContext BC) { }"; var cd = Apex.ClassDeclaration.Parse(text); - Assert.AreEqual("BatchCleanLandingZoneCharts", cd.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("BatchCleanLandingZoneCharts")); } [Test] @@ -760,7 +760,7 @@ class Sample { b = '321'; }"); - Assert.AreEqual("Sample", cd.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("Sample")); } } -} +} \ No newline at end of file diff --git a/ApexSharp.ApexParser.Tests/Parser/ApexResourceTests.cs b/ApexSharp.ApexParser.Tests/Parser/ApexResourceTests.cs index 99d6de3..527b3ce 100644 --- a/ApexSharp.ApexParser.Tests/Parser/ApexResourceTests.cs +++ b/ApexSharp.ApexParser.Tests/Parser/ApexResourceTests.cs @@ -16,13 +16,13 @@ private void CompareIgnoreFormatting(string expected, string actual) { if (string.IsNullOrEmpty(expected) || string.IsNullOrEmpty(actual)) { - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } var ignoreWhiteSpace = new Regex(@"\s+"); expected = ignoreWhiteSpace.Replace(expected, " ").Trim(); actual = ignoreWhiteSpace.Replace(actual, " ").Trim(); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [Test] @@ -31,7 +31,7 @@ public void CompareIgnoresFormattingDifferences() CompareIgnoreFormatting(" hello ", "hello"); CompareIgnoreFormatting(" hello world!", "hello world!"); - Assert.Throws(() => CompareIgnoreFormatting("hello", "world")); + Assert.That(() => CompareIgnoreFormatting("hello", "world"), Throws.Exception); } // The original file location in the description is kept for future reference. @@ -48,28 +48,28 @@ public void ClassOneIsParsed() void ParseAndValidate(string text) { var cd = Apex.ParseClass(text); - Assert.AreEqual("ClassOne", cd.Identifier); - Assert.AreEqual(1, cd.Methods.Count); + Assert.That(cd.Identifier, Is.EqualTo("ClassOne")); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); var md = cd.Methods[0]; - Assert.AreEqual("CallClassTwo", md.Identifier); - Assert.False(md.LeadingComments.Any()); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.AreEqual("void", md.ReturnType.Identifier); + Assert.That(md.Identifier, Is.EqualTo("CallClassTwo")); + Assert.That(md.LeadingComments.Any(), Is.False); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); var block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); var varDecl = block.Statements[0] as VariableDeclarationSyntax; - Assert.NotNull(varDecl); - Assert.AreEqual("ClassTwo", varDecl.Type.Identifier); - Assert.AreEqual(1, varDecl.Variables.Count); - Assert.AreEqual("classTwo", varDecl.Variables[0].Identifier); - Assert.AreEqual("new ClassTwo()", varDecl.Variables[0].Expression.ExpressionString); - Assert.AreEqual("System.debug('Test')", block.Statements[1].Body); + Assert.That(varDecl, Is.Not.Null); + Assert.That(varDecl.Type.Identifier, Is.EqualTo("ClassTwo")); + Assert.That(varDecl.Variables.Count, Is.EqualTo(1)); + Assert.That(varDecl.Variables[0].Identifier, Is.EqualTo("classTwo")); + Assert.That(varDecl.Variables[0].Expression.ExpressionString, Is.EqualTo("new ClassTwo()")); + Assert.That(block.Statements[1].Body, Is.EqualTo("System.debug('Test')")); } } @@ -82,34 +82,34 @@ public void ClassTwoIsParsed() void ParseAndValidate(string text) { var cd = Apex.ParseClass(text); - Assert.AreEqual("ClassTwo", cd.Identifier); - Assert.False(cd.Methods.Any()); - Assert.AreEqual(2, cd.Constructors.Count); + Assert.That(cd.Identifier, Is.EqualTo("ClassTwo")); + Assert.That(cd.Methods.Any(), Is.False); + Assert.That(cd.Constructors.Count, Is.EqualTo(2)); var md = cd.Constructors[0]; - Assert.AreEqual("ClassTwo", md.Identifier); - Assert.False(md.LeadingComments.Any()); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.AreEqual("ClassTwo", md.ReturnType.Identifier); + Assert.That(md.Identifier, Is.EqualTo("ClassTwo")); + Assert.That(md.LeadingComments.Any(), Is.False); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("ClassTwo")); var block = md.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug('Test')", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug('Test')")); md = cd.Constructors[1]; - Assert.AreEqual("ClassTwo", md.Identifier); - Assert.False(md.LeadingComments.Any()); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.AreEqual("ClassTwo", md.ReturnType.Identifier); + Assert.That(md.Identifier, Is.EqualTo("ClassTwo")); + Assert.That(md.LeadingComments.Any(), Is.False); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("ClassTwo")); block = md.Body; - Assert.NotNull(block); - Assert.False(block.Statements.Any()); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Any(), Is.False); } } @@ -122,66 +122,66 @@ public void ClassWithCommentsIsParsed() void ParseAndValidate(string text) { var cd = Apex.ParseClass(text); - Assert.AreEqual("ClassTwo", cd.Identifier); - Assert.AreEqual(2, cd.Constructors.Count); - Assert.AreEqual(1, cd.Methods.Count); + Assert.That(cd.Identifier, Is.EqualTo("ClassTwo")); + Assert.That(cd.Constructors.Count, Is.EqualTo(2)); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); var cc = cd.Constructors[0]; - Assert.AreEqual("ClassTwo", cc.Identifier); - Assert.False(cc.LeadingComments.Any()); - Assert.False(cc.Annotations.Any()); - Assert.False(cc.Parameters.Any()); - Assert.AreEqual(1, cc.Modifiers.Count); - Assert.AreEqual("public", cc.Modifiers[0]); - Assert.AreEqual("ClassTwo", cc.ReturnType.Identifier); + Assert.That(cc.Identifier, Is.EqualTo("ClassTwo")); + Assert.That(cc.LeadingComments.Any(), Is.False); + Assert.That(cc.Annotations.Any(), Is.False); + Assert.That(cc.Parameters.Any(), Is.False); + Assert.That(cc.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cc.Modifiers[0], Is.EqualTo("public")); + Assert.That(cc.ReturnType.Identifier, Is.EqualTo("ClassTwo")); var block = cc.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug('Test')", block.Statements[0].Body); - Assert.AreEqual(1, block.Statements[0].LeadingComments.Count); - Assert.AreEqual("constructor", block.Statements[0].LeadingComments[0].Trim()); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug('Test')")); + Assert.That(block.Statements[0].LeadingComments.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].LeadingComments[0].Trim(), Is.EqualTo("constructor")); cc = cd.Constructors[1]; - Assert.AreEqual("ClassTwo", cc.Identifier); - Assert.False(cc.LeadingComments.Any()); - Assert.False(cc.Annotations.Any()); - Assert.AreEqual(1, cc.Modifiers.Count); - Assert.AreEqual("public", cc.Modifiers[0]); - Assert.AreEqual("ClassTwo", cc.ReturnType.Identifier); - Assert.AreEqual(1, cc.Parameters.Count); - Assert.AreEqual("String", cc.Parameters[0].Type.Identifier); - Assert.AreEqual("vin", cc.Parameters[0].Identifier); + Assert.That(cc.Identifier, Is.EqualTo("ClassTwo")); + Assert.That(cc.LeadingComments.Any(), Is.False); + Assert.That(cc.Annotations.Any(), Is.False); + Assert.That(cc.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cc.Modifiers[0], Is.EqualTo("public")); + Assert.That(cc.ReturnType.Identifier, Is.EqualTo("ClassTwo")); + Assert.That(cc.Parameters.Count, Is.EqualTo(1)); + Assert.That(cc.Parameters[0].Type.Identifier, Is.EqualTo("String")); + Assert.That(cc.Parameters[0].Identifier, Is.EqualTo("vin")); block = cc.Body; - Assert.NotNull(block); - Assert.False(block.Statements.Any()); - Assert.AreEqual(2, block.InnerComments.Count); - Assert.AreEqual("another constructor", block.InnerComments[0].Trim()); - Assert.AreEqual("with a lot of misplaced comments", block.InnerComments[1].Trim()); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Any(), Is.False); + Assert.That(block.InnerComments.Count, Is.EqualTo(2)); + Assert.That(block.InnerComments[0].Trim(), Is.EqualTo("another constructor")); + Assert.That(block.InnerComments[1].Trim(), Is.EqualTo("with a lot of misplaced comments")); var mp = cc.Parameters[0]; - Assert.AreEqual("String", mp.Type.Identifier); - Assert.False(mp.Type.TypeParameters.Any()); - Assert.AreEqual("vin", mp.Identifier); + Assert.That(mp.Type.Identifier, Is.EqualTo("String")); + Assert.That(mp.Type.TypeParameters.Any(), Is.False); + Assert.That(mp.Identifier, Is.EqualTo("vin")); var md = cd.Methods[0]; - Assert.AreEqual("Hello", md.Identifier); - Assert.AreEqual(1, md.LeadingComments.Count); + Assert.That(md.Identifier, Is.EqualTo("Hello")); + Assert.That(md.LeadingComments.Count, Is.EqualTo(1)); CompareIgnoreFormatting(@" * This is a comment line one * This is a comment // line two", md.LeadingComments[0]); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.AreEqual("void", md.ReturnType.Identifier); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); block = md.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug('Hello')", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug('Hello')")); } } @@ -189,101 +189,101 @@ void ParseAndValidate(string text) public void Demo2IsParsed() { var cd = Apex.ParseClass(Demo2); - Assert.AreEqual("Demo2", cd.Identifier); - Assert.AreEqual(1, cd.Methods.Count); + Assert.That(cd.Identifier, Is.EqualTo("Demo2")); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); var md = cd.Methods[0]; - Assert.AreEqual("MethodOne", md.Identifier); - Assert.False(md.LeadingComments.Any()); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.AreEqual("void", md.ReturnType.Identifier); + Assert.That(md.Identifier, Is.EqualTo("MethodOne")); + Assert.That(md.LeadingComments.Any(), Is.False); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); var block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); var ifstmt = block.Statements[0] as IfStatementSyntax; - Assert.NotNull(ifstmt); - Assert.AreEqual("x == 5", ifstmt.Expression.ExpressionString); - Assert.NotNull(ifstmt.ThenStatement); - Assert.NotNull(ifstmt.ElseStatement); + Assert.That(ifstmt, Is.Not.Null); + Assert.That(ifstmt.Expression.ExpressionString, Is.EqualTo("x == 5")); + Assert.That(ifstmt.ThenStatement, Is.Not.Null); + Assert.That(ifstmt.ElseStatement, Is.Not.Null); block = ifstmt.ThenStatement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(4, block.Statements.Count); - Assert.AreEqual("Console.WriteLine(1)", block.Statements[0].Body); - Assert.AreEqual("Console.WriteLine(2)", block.Statements[2].Body); - Assert.AreEqual("Console.WriteLine(3)", block.Statements[3].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(4)); + Assert.That(block.Statements[0].Body, Is.EqualTo("Console.WriteLine(1)")); + Assert.That(block.Statements[2].Body, Is.EqualTo("Console.WriteLine(2)")); + Assert.That(block.Statements[3].Body, Is.EqualTo("Console.WriteLine(3)")); var innerIf = block.Statements[1] as IfStatementSyntax; - Assert.NotNull(innerIf); - Assert.AreEqual("x == 8", innerIf.Expression.ExpressionString); - Assert.NotNull(innerIf.ThenStatement); - Assert.Null(innerIf.ElseStatement); + Assert.That(innerIf, Is.Not.Null); + Assert.That(innerIf.Expression.ExpressionString, Is.EqualTo("x == 8")); + Assert.That(innerIf.ThenStatement, Is.Not.Null); + Assert.That(innerIf.ElseStatement, Is.Null); block = innerIf.ThenStatement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("Console.WriteLine(8)", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("Console.WriteLine(8)")); ifstmt = ifstmt.ElseStatement as IfStatementSyntax; - Assert.NotNull(ifstmt); - Assert.NotNull(ifstmt.ThenStatement); - Assert.NotNull(ifstmt.ElseStatement); + Assert.That(ifstmt, Is.Not.Null); + Assert.That(ifstmt.ThenStatement, Is.Not.Null); + Assert.That(ifstmt.ElseStatement, Is.Not.Null); block = ifstmt.ThenStatement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("Console.WriteLine(6)", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("Console.WriteLine(6)")); block = ifstmt.ElseStatement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("Console.WriteLine(7)", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("Console.WriteLine(7)")); } [Test(Description = @"SalesForceApexSharp\src\classes\Demo.cls")] public void DemoIsParsed() { var cd = Apex.ParseClass(Demo); - Assert.AreEqual("Demo", cd.Identifier); - Assert.AreEqual(1, cd.Methods.Count); + Assert.That(cd.Identifier, Is.EqualTo("Demo")); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); var md = cd.Methods[0]; - Assert.AreEqual("RunContactDemo", md.Identifier); - Assert.False(md.LeadingComments.Any()); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(2, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.AreEqual("static", md.Modifiers[1]); - Assert.AreEqual("void", md.ReturnType.Identifier); + Assert.That(md.Identifier, Is.EqualTo("RunContactDemo")); + Assert.That(md.LeadingComments.Any(), Is.False); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(2)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.Modifiers[1], Is.EqualTo("static")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); var block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(11, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(11)); var forStmt = block.Statements[4] as ForEachStatementSyntax; - Assert.NotNull(forStmt); - Assert.AreEqual("Contact", forStmt.Type.Identifier); - Assert.AreEqual("c", forStmt.Identifier); - Assert.AreEqual("contacts", forStmt.Expression.ExpressionString); + Assert.That(forStmt, Is.Not.Null); + Assert.That(forStmt.Type.Identifier, Is.EqualTo("Contact")); + Assert.That(forStmt.Identifier, Is.EqualTo("c")); + Assert.That(forStmt.Expression.ExpressionString, Is.EqualTo("contacts")); var loopBody = forStmt.Statement as BlockSyntax; - Assert.NotNull(loopBody); - Assert.AreEqual(2, loopBody.Statements.Count); - Assert.AreEqual("System.debug(c.Email)", loopBody.Statements[0].Body); - Assert.AreEqual("c.Email = 'new@new.com'", loopBody.Statements[1].Body); + Assert.That(loopBody, Is.Not.Null); + Assert.That(loopBody.Statements.Count, Is.EqualTo(2)); + Assert.That(loopBody.Statements[0].Body, Is.EqualTo("System.debug(c.Email)")); + Assert.That(loopBody.Statements[1].Body, Is.EqualTo("c.Email = 'new@new.com'")); var ifStmt = block.Statements[10] as IfStatementSyntax; - Assert.NotNull(ifStmt); - Assert.NotNull(ifStmt.ThenStatement); - Assert.Null(ifStmt.ElseStatement); + Assert.That(ifStmt, Is.Not.Null); + Assert.That(ifStmt.ThenStatement, Is.Not.Null); + Assert.That(ifStmt.ElseStatement, Is.Null); block = ifStmt.ThenStatement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug('Del Worked')", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug('Del Worked')")); } [Test(Description = @"SalesForceApexSharp\src\classes\CustomerDto.cls")] @@ -295,49 +295,49 @@ public void CustomerDtoIsParsed() void ParseAndValidate(string text) { var cd = Apex.ParseClass(text); - Assert.False(cd.Annotations.Any()); - Assert.AreEqual("CustomerDto", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(3, cd.Properties.Count); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("CustomerDto")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Properties.Count, Is.EqualTo(3)); var pd = cd.Properties[0]; - Assert.False(pd.Annotations.Any()); - Assert.AreEqual(1, pd.Modifiers.Count); - Assert.AreEqual("public", pd.Modifiers[0]); - Assert.AreEqual("String", pd.Type.Identifier); - Assert.AreEqual("make", pd.Identifier); + Assert.That(pd.Annotations.Any(), Is.False); + Assert.That(pd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(pd.Modifiers[0], Is.EqualTo("public")); + Assert.That(pd.Type.Identifier, Is.EqualTo("String")); + Assert.That(pd.Identifier, Is.EqualTo("make")); pd = cd.Properties[1]; - Assert.False(pd.Annotations.Any()); - Assert.AreEqual(1, pd.Modifiers.Count); - Assert.AreEqual("public", pd.Modifiers[0]); - Assert.AreEqual("String", pd.Type.Identifier); - Assert.AreEqual("year", pd.Identifier); + Assert.That(pd.Annotations.Any(), Is.False); + Assert.That(pd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(pd.Modifiers[0], Is.EqualTo("public")); + Assert.That(pd.Type.Identifier, Is.EqualTo("String")); + Assert.That(pd.Identifier, Is.EqualTo("year")); pd = cd.Properties[2]; - Assert.False(pd.Annotations.Any()); - Assert.AreEqual(1, pd.Modifiers.Count); - Assert.AreEqual("public", pd.Modifiers[0]); - Assert.AreEqual("User", pd.Type.Identifier); - Assert.AreEqual(1, pd.Type.Namespaces.Count); - Assert.AreEqual("CustomerDto", pd.Type.Namespaces[0]); - Assert.AreEqual("user", pd.Identifier); - - Assert.AreEqual(1, cd.InnerClasses.Count); + Assert.That(pd.Annotations.Any(), Is.False); + Assert.That(pd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(pd.Modifiers[0], Is.EqualTo("public")); + Assert.That(pd.Type.Identifier, Is.EqualTo("User")); + Assert.That(pd.Type.Namespaces.Count, Is.EqualTo(1)); + Assert.That(pd.Type.Namespaces[0], Is.EqualTo("CustomerDto")); + Assert.That(pd.Identifier, Is.EqualTo("user")); + + Assert.That(cd.InnerClasses.Count, Is.EqualTo(1)); cd = cd.InnerClasses[0]; - Assert.AreEqual("User", cd.Identifier); - Assert.False(cd.Annotations.Any()); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(1, cd.Properties.Count); + Assert.That(cd.Identifier, Is.EqualTo("User")); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Properties.Count, Is.EqualTo(1)); pd = cd.Properties[0]; - Assert.False(pd.Annotations.Any()); - Assert.AreEqual(1, pd.Modifiers.Count); - Assert.AreEqual("public", pd.Modifiers[0]); - Assert.AreEqual("String", pd.Type.Identifier); - Assert.AreEqual("userName", pd.Identifier); + Assert.That(pd.Annotations.Any(), Is.False); + Assert.That(pd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(pd.Modifiers[0], Is.EqualTo("public")); + Assert.That(pd.Type.Identifier, Is.EqualTo("String")); + Assert.That(pd.Identifier, Is.EqualTo("userName")); } } @@ -345,793 +345,793 @@ void ParseAndValidate(string text) public void ForIfWhileLoopsAreParsed() { var cd = Apex.ParseClass(ForIfWhile); - Assert.False(cd.Annotations.Any()); - Assert.AreEqual("ForIfWhile", cd.Identifier); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("with sharing", cd.Modifiers[1]); - Assert.AreEqual(5, cd.Methods.Count); - Assert.False(cd.Properties.Any()); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("ForIfWhile")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("with sharing")); + Assert.That(cd.Methods.Count, Is.EqualTo(5)); + Assert.That(cd.Properties.Any(), Is.False); var md = cd.Methods[0]; - Assert.AreEqual("MethodIfClean", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodIfClean")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); var block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(3, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(3)); md = cd.Methods[1]; - Assert.AreEqual("MethodForTraditional", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodForTraditional")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); var forStmt = block.Statements[0] as ForStatementSyntax; - Assert.NotNull(forStmt); - Assert.NotNull(forStmt.Declaration); - Assert.AreEqual("Integer", forStmt.Declaration.Type.Identifier); - Assert.AreEqual(2, forStmt.Declaration.Variables.Count); - Assert.AreEqual("i", forStmt.Declaration.Variables[0].Identifier); - Assert.AreEqual("0", forStmt.Declaration.Variables[0].Expression.ExpressionString); - Assert.AreEqual("j", forStmt.Declaration.Variables[1].Identifier); - Assert.AreEqual("0", forStmt.Declaration.Variables[1].Expression.ExpressionString); - Assert.AreEqual("i < 10", forStmt.Condition.ExpressionString); - Assert.NotNull(forStmt.Incrementors); - Assert.AreEqual(1, forStmt.Incrementors.Count); - Assert.AreEqual("i++", forStmt.Incrementors[0].ExpressionString); + Assert.That(forStmt, Is.Not.Null); + Assert.That(forStmt.Declaration, Is.Not.Null); + Assert.That(forStmt.Declaration.Type.Identifier, Is.EqualTo("Integer")); + Assert.That(forStmt.Declaration.Variables.Count, Is.EqualTo(2)); + Assert.That(forStmt.Declaration.Variables[0].Identifier, Is.EqualTo("i")); + Assert.That(forStmt.Declaration.Variables[0].Expression.ExpressionString, Is.EqualTo("0")); + Assert.That(forStmt.Declaration.Variables[1].Identifier, Is.EqualTo("j")); + Assert.That(forStmt.Declaration.Variables[1].Expression.ExpressionString, Is.EqualTo("0")); + Assert.That(forStmt.Condition.ExpressionString, Is.EqualTo("i < 10")); + Assert.That(forStmt.Incrementors, Is.Not.Null); + Assert.That(forStmt.Incrementors.Count, Is.EqualTo(1)); + Assert.That(forStmt.Incrementors[0].ExpressionString, Is.EqualTo("i++")); block = forStmt.Statement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug (i + 1)", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug (i + 1)")); md = cd.Methods[2]; - Assert.AreEqual("MethodForIteration", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodForIteration")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); var forEachStmt = block.Statements[1] as ForEachStatementSyntax; - Assert.NotNull(forEachStmt); - Assert.AreEqual("Integer", forEachStmt.Type.Identifier); - Assert.AreEqual("i", forEachStmt.Identifier); - Assert.AreEqual("myInts", forEachStmt.Expression.ExpressionString); + Assert.That(forEachStmt, Is.Not.Null); + Assert.That(forEachStmt.Type.Identifier, Is.EqualTo("Integer")); + Assert.That(forEachStmt.Identifier, Is.EqualTo("i")); + Assert.That(forEachStmt.Expression.ExpressionString, Is.EqualTo("myInts")); block = forEachStmt.Statement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug (i)", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug (i)")); md = cd.Methods[3]; - Assert.AreEqual("MethodDo", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodDo")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); md = cd.Methods[4]; - Assert.AreEqual("MethodWhile", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodWhile")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); } [Test(Description = @"SalesForceApexSharp\src\classes\DataAccessDemo.cls")] public void DataAccessDemoIsParsed() { var cd = Apex.ParseClass(DataAccessDemo); - Assert.False(cd.Annotations.Any()); - Assert.AreEqual("DataAccessDemo", cd.Identifier); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("with sharing", cd.Modifiers[1]); - Assert.AreEqual(1, cd.Constructors.Count); - Assert.AreEqual(1, cd.Methods.Count); - Assert.False(cd.Properties.Any()); - Assert.AreEqual(1, cd.Fields.Count); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("DataAccessDemo")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("with sharing")); + Assert.That(cd.Constructors.Count, Is.EqualTo(1)); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Properties.Any(), Is.False); + Assert.That(cd.Fields.Count, Is.EqualTo(1)); var fd = cd.Fields[0]; - Assert.False(fd.Annotations.Any()); - Assert.False(fd.LeadingComments.Any()); - Assert.AreEqual(1, fd.Modifiers.Count); - Assert.AreEqual("private", fd.Modifiers[0]); - Assert.AreEqual("DataAccessLayerI", fd.Type.Identifier); - Assert.AreEqual(1, fd.Fields.Count); - Assert.AreEqual("dl", fd.Fields[0].Identifier); + Assert.That(fd.Annotations.Any(), Is.False); + Assert.That(fd.LeadingComments.Any(), Is.False); + Assert.That(fd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(fd.Modifiers[0], Is.EqualTo("private")); + Assert.That(fd.Type.Identifier, Is.EqualTo("DataAccessLayerI")); + Assert.That(fd.Fields.Count, Is.EqualTo(1)); + Assert.That(fd.Fields[0].Identifier, Is.EqualTo("dl")); var cc = cd.Constructors[0]; - Assert.AreEqual("DataAccessDemo", cc.Identifier); - Assert.AreEqual("DataAccessDemo", cc.ReturnType.Identifier); - Assert.False(cc.Annotations.Any()); - Assert.False(cc.Parameters.Any()); - Assert.AreEqual(1, cc.Modifiers.Count); - Assert.AreEqual("public", cc.Modifiers[0]); + Assert.That(cc.Identifier, Is.EqualTo("DataAccessDemo")); + Assert.That(cc.ReturnType.Identifier, Is.EqualTo("DataAccessDemo")); + Assert.That(cc.Annotations.Any(), Is.False); + Assert.That(cc.Parameters.Any(), Is.False); + Assert.That(cc.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cc.Modifiers[0], Is.EqualTo("public")); var block = cc.Body; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); var ifstmt = block.Statements[0] as IfStatementSyntax; - Assert.NotNull(ifstmt); - Assert.NotNull(ifstmt.ThenStatement as BlockSyntax); - Assert.NotNull(ifstmt.ElseStatement as BlockSyntax); + Assert.That(ifstmt, Is.Not.Null); + Assert.That(ifstmt.ThenStatement as BlockSyntax, Is.Not.Null); + Assert.That(ifstmt.ElseStatement as BlockSyntax, Is.Not.Null); var md = cd.Methods[0]; - Assert.AreEqual("UpdateContactEmailAddress", md.Identifier); - Assert.AreEqual("String", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); - Assert.AreEqual(3, md.Parameters.Count); + Assert.That(md.Identifier, Is.EqualTo("UpdateContactEmailAddress")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("String")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); + Assert.That(md.Parameters.Count, Is.EqualTo(3)); } [Test(Description = @"SalesForceApexSharp\src\classes\PropertyAndField.cls")] public void PropertyAndFieldIsParsed() { var cd = Apex.ParseClass(PropertyAndField); - Assert.AreEqual("PropertyAndField", cd.Identifier); - Assert.AreEqual(1, cd.LeadingComments.Count); - Assert.AreEqual("ClassDeclaration", cd.LeadingComments[0].Trim()); - Assert.AreEqual(1, cd.Methods.Count); - Assert.AreEqual(3, cd.Properties.Count); - Assert.AreEqual(8, cd.Fields.Count); + Assert.That(cd.Identifier, Is.EqualTo("PropertyAndField")); + Assert.That(cd.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(cd.LeadingComments[0].Trim(), Is.EqualTo("ClassDeclaration")); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Properties.Count, Is.EqualTo(3)); + Assert.That(cd.Fields.Count, Is.EqualTo(8)); var pd = cd.Properties[2]; - Assert.AreEqual("DateTimeGetSetArray", pd.Identifier); - Assert.AreEqual("Datetime", pd.Type.Identifier); - Assert.False(pd.Type.TypeParameters.Any()); - Assert.IsTrue(pd.Type.IsArray); - Assert.NotNull(pd.Getter); - Assert.NotNull(pd.Setter); + Assert.That(pd.Identifier, Is.EqualTo("DateTimeGetSetArray")); + Assert.That(pd.Type.Identifier, Is.EqualTo("Datetime")); + Assert.That(pd.Type.TypeParameters.Any(), Is.False); + Assert.That(pd.Type.IsArray, Is.True); + Assert.That(pd.Getter, Is.Not.Null); + Assert.That(pd.Setter, Is.Not.Null); var fd = cd.Fields[2]; - Assert.AreEqual("DateTimeList", fd.Fields[0].Identifier); - Assert.AreEqual("List", fd.Type.Identifier); - Assert.AreEqual(1, fd.Type.TypeParameters.Count); - Assert.AreEqual("Datetime", fd.Type.TypeParameters[0].Identifier); - Assert.IsFalse(fd.Type.IsArray); - Assert.AreEqual("new List()", fd.Fields[0].Expression.ExpressionString); + Assert.That(fd.Fields[0].Identifier, Is.EqualTo("DateTimeList")); + Assert.That(fd.Type.Identifier, Is.EqualTo("List")); + Assert.That(fd.Type.TypeParameters.Count, Is.EqualTo(1)); + Assert.That(fd.Type.TypeParameters[0].Identifier, Is.EqualTo("Datetime")); + Assert.That(fd.Type.IsArray, Is.False); + Assert.That(fd.Fields[0].Expression.ExpressionString, Is.EqualTo("new List()")); fd = cd.Fields[3]; - Assert.False(fd.Annotations.Any()); - Assert.AreEqual("DateTimeArrary", fd.Fields[0].Identifier); - Assert.AreEqual("Datetime", fd.Type.Identifier); - Assert.False(fd.Type.TypeParameters.Any()); - Assert.IsTrue(fd.Type.IsArray); - Assert.AreEqual(1, fd.Modifiers.Count); - Assert.AreEqual("public", fd.Modifiers[0]); - Assert.AreEqual("new Datetime[5]", fd.Fields[0].Expression.ExpressionString); + Assert.That(fd.Annotations.Any(), Is.False); + Assert.That(fd.Fields[0].Identifier, Is.EqualTo("DateTimeArrary")); + Assert.That(fd.Type.Identifier, Is.EqualTo("Datetime")); + Assert.That(fd.Type.TypeParameters.Any(), Is.False); + Assert.That(fd.Type.IsArray, Is.True); + Assert.That(fd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(fd.Modifiers[0], Is.EqualTo("public")); + Assert.That(fd.Fields[0].Expression.ExpressionString, Is.EqualTo("new Datetime[5]")); fd = cd.Fields[7]; - Assert.False(fd.Annotations.Any()); - Assert.AreEqual("NameStaticFinal", fd.Fields[0].Identifier); - Assert.AreEqual("String", fd.Type.Identifier); - Assert.False(fd.Type.TypeParameters.Any()); - Assert.False(fd.Type.IsArray); - Assert.AreEqual(3, fd.Modifiers.Count); - Assert.AreEqual("public", fd.Modifiers[0]); - Assert.AreEqual("static", fd.Modifiers[1]); - Assert.AreEqual("final", fd.Modifiers[2]); - Assert.AreEqual("'jay'", fd.Fields[0].Expression.ExpressionString); + Assert.That(fd.Annotations.Any(), Is.False); + Assert.That(fd.Fields[0].Identifier, Is.EqualTo("NameStaticFinal")); + Assert.That(fd.Type.Identifier, Is.EqualTo("String")); + Assert.That(fd.Type.TypeParameters.Any(), Is.False); + Assert.That(fd.Type.IsArray, Is.False); + Assert.That(fd.Modifiers.Count, Is.EqualTo(3)); + Assert.That(fd.Modifiers[0], Is.EqualTo("public")); + Assert.That(fd.Modifiers[1], Is.EqualTo("static")); + Assert.That(fd.Modifiers[2], Is.EqualTo("final")); + Assert.That(fd.Fields[0].Expression.ExpressionString, Is.EqualTo("'jay'")); var md = cd.Methods[0]; - Assert.AreEqual("MethodOne", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); + Assert.That(md.Identifier, Is.EqualTo("MethodOne")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); var block = md.Body; - Assert.NotNull(block); - Assert.AreEqual(8, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(8)); } [Test(Description = @"SalesForceApexSharp\src\classes\SoqlDemo.cls")] public void SoqlDemoIsParsed() { var soql = Apex.ParseClass(SoqlDemo); - Assert.AreEqual(1, soql.Methods.Count); - Assert.AreEqual("void", soql.Methods[0].ReturnType.Identifier); - Assert.AreEqual("CrudExample", soql.Methods[0].Identifier); + Assert.That(soql.Methods.Count, Is.EqualTo(1)); + Assert.That(soql.Methods[0].ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(soql.Methods[0].Identifier, Is.EqualTo("CrudExample")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassAbstract.cls")] public void ClassAbstractIsParsed() { var cd = Apex.ParseClass(ClassAbstract); - Assert.AreEqual("ClassAbstract", cd.Identifier); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("abstract", cd.Modifiers[1]); + Assert.That(cd.Identifier, Is.EqualTo("ClassAbstract")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("abstract")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassEnum.cls")] public void ClassEnumIsParsed() { var ed = Apex.ParseFile(ClassEnum) as EnumDeclarationSyntax; - Assert.AreEqual("ClassEnum", ed.Identifier); - Assert.AreEqual(1, ed.Modifiers.Count); - Assert.AreEqual("public", ed.Modifiers[0]); - - Assert.AreEqual(3, ed.Members.Count); - Assert.AreEqual("America", ed.Members[0].Identifier); - Assert.AreEqual("Canada", ed.Members[1].Identifier); - Assert.AreEqual("Russia", ed.Members[2].Identifier); + Assert.That(ed.Identifier, Is.EqualTo("ClassEnum")); + Assert.That(ed.Modifiers.Count, Is.EqualTo(1)); + Assert.That(ed.Modifiers[0], Is.EqualTo("public")); + + Assert.That(ed.Members.Count, Is.EqualTo(3)); + Assert.That(ed.Members[0].Identifier, Is.EqualTo("America")); + Assert.That(ed.Members[1].Identifier, Is.EqualTo("Canada")); + Assert.That(ed.Members[2].Identifier, Is.EqualTo("Russia")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassException.cls")] public void ClassExceptionIsParsed() { var cd = Apex.ParseClass(ClassException); - Assert.AreEqual("ClassException", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("Exception", cd.BaseType.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("ClassException")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.BaseType.Identifier, Is.EqualTo("Exception")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassGlobal.cls")] public void ClassGlobalIsParsed() { var cd = Apex.ParseClass(ClassGlobal); - Assert.AreEqual("ClassGlobal", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("global", cd.Modifiers[0]); + Assert.That(cd.Identifier, Is.EqualTo("ClassGlobal")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("global")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassInterface.cls")] public void ClassInterfaceIsParsed() { var cd = Apex.ParseClass(ClassInterface); - Assert.AreEqual("ClassInterface", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(1, cd.Interfaces.Count); - Assert.AreEqual("IClassInterface", cd.Interfaces[0].Identifier); - - Assert.AreEqual(2, cd.Methods.Count); - Assert.AreEqual("ID", cd.Methods[0].ReturnType.Identifier); - Assert.AreEqual("GetId", cd.Methods[0].Identifier); - Assert.AreEqual(1, cd.Methods[0].Body.Statements.Count); - Assert.AreEqual("String", cd.Methods[1].ReturnType.Identifier); - Assert.AreEqual("GetName", cd.Methods[1].Identifier); - Assert.AreEqual(1, cd.Methods[0].Body.Statements.Count); + Assert.That(cd.Identifier, Is.EqualTo("ClassInterface")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Interfaces.Count, Is.EqualTo(1)); + Assert.That(cd.Interfaces[0].Identifier, Is.EqualTo("IClassInterface")); + + Assert.That(cd.Methods.Count, Is.EqualTo(2)); + Assert.That(cd.Methods[0].ReturnType.Identifier, Is.EqualTo("ID")); + Assert.That(cd.Methods[0].Identifier, Is.EqualTo("GetId")); + Assert.That(cd.Methods[0].Body.Statements.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[1].ReturnType.Identifier, Is.EqualTo("String")); + Assert.That(cd.Methods[1].Identifier, Is.EqualTo("GetName")); + Assert.That(cd.Methods[0].Body.Statements.Count, Is.EqualTo(1)); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassInternal.cls")] public void ClassInternalIsParsed() { var cd = Apex.ParseClass(ClassInternal); - Assert.AreEqual("ClassInternal", cd.Identifier); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("with sharing", cd.Modifiers[1]); - Assert.AreEqual(2, cd.InnerClasses.Count); - Assert.AreEqual("InternalClassOne", cd.InnerClasses[0].Identifier); - Assert.AreEqual("InternalClassTwo", cd.InnerClasses[1].Identifier); + Assert.That(cd.Identifier, Is.EqualTo("ClassInternal")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("with sharing")); + Assert.That(cd.InnerClasses.Count, Is.EqualTo(2)); + Assert.That(cd.InnerClasses[0].Identifier, Is.EqualTo("InternalClassOne")); + Assert.That(cd.InnerClasses[1].Identifier, Is.EqualTo("InternalClassTwo")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassRest.cls")] public void ClassRestIsParsed() { var cd = Apex.ParseClass(ClassRest); - Assert.AreEqual("ClassRest", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("global", cd.Modifiers[0]); - Assert.AreEqual(5, cd.Methods.Count); - Assert.AreEqual(1, cd.Annotations.Count); - Assert.AreEqual("RestResource", cd.Annotations[0].Identifier); - Assert.AreEqual("urlMapping='/api/v1/RestDemo'", cd.Annotations[0].Parameters); - - Assert.AreEqual(1, cd.Methods[0].Annotations.Count); - Assert.AreEqual("HttpDelete", cd.Methods[0].Annotations[0].Identifier); - Assert.AreEqual("DoDelete", cd.Methods[0].Identifier); - Assert.AreEqual("void", cd.Methods[0].ReturnType.Identifier); - - Assert.AreEqual(1, cd.Methods[1].Annotations.Count); - Assert.AreEqual("HttpPost", cd.Methods[1].Annotations[0].Identifier); - Assert.AreEqual("Post", cd.Methods[1].Identifier); - Assert.AreEqual("void", cd.Methods[1].ReturnType.Identifier); - - Assert.AreEqual(1, cd.Methods[2].Annotations.Count); - Assert.AreEqual("HttpGet", cd.Methods[2].Annotations[0].Identifier); - Assert.AreEqual("Get", cd.Methods[2].Identifier); - Assert.AreEqual("String", cd.Methods[2].ReturnType.Identifier); - - Assert.AreEqual(1, cd.Methods[3].Annotations.Count); - Assert.AreEqual("HttpPatch", cd.Methods[3].Annotations[0].Identifier); - Assert.AreEqual("Patch", cd.Methods[3].Identifier); - Assert.AreEqual("void", cd.Methods[3].ReturnType.Identifier); - - Assert.AreEqual(1, cd.Methods[4].Annotations.Count); - Assert.AreEqual("HttpPut", cd.Methods[4].Annotations[0].Identifier); - Assert.AreEqual("Put", cd.Methods[4].Identifier); - Assert.AreEqual("void", cd.Methods[4].ReturnType.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("ClassRest")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("global")); + Assert.That(cd.Methods.Count, Is.EqualTo(5)); + Assert.That(cd.Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Annotations[0].Identifier, Is.EqualTo("RestResource")); + Assert.That(cd.Annotations[0].Parameters, Is.EqualTo("urlMapping='/api/v1/RestDemo'")); + + Assert.That(cd.Methods[0].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[0].Annotations[0].Identifier, Is.EqualTo("HttpDelete")); + Assert.That(cd.Methods[0].Identifier, Is.EqualTo("DoDelete")); + Assert.That(cd.Methods[0].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[1].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[1].Annotations[0].Identifier, Is.EqualTo("HttpPost")); + Assert.That(cd.Methods[1].Identifier, Is.EqualTo("Post")); + Assert.That(cd.Methods[1].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[2].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[2].Annotations[0].Identifier, Is.EqualTo("HttpGet")); + Assert.That(cd.Methods[2].Identifier, Is.EqualTo("Get")); + Assert.That(cd.Methods[2].ReturnType.Identifier, Is.EqualTo("String")); + + Assert.That(cd.Methods[3].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[3].Annotations[0].Identifier, Is.EqualTo("HttpPatch")); + Assert.That(cd.Methods[3].Identifier, Is.EqualTo("Patch")); + Assert.That(cd.Methods[3].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[4].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[4].Annotations[0].Identifier, Is.EqualTo("HttpPut")); + Assert.That(cd.Methods[4].Identifier, Is.EqualTo("Put")); + Assert.That(cd.Methods[4].ReturnType.Identifier, Is.EqualTo("void")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassUnitTest.cls")] public void ClassUnitTestIsParsed() { var cd = Apex.ParseClass(ClassUnitTest); - Assert.AreEqual("ClassUnitTest", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(7, cd.Methods.Count); - Assert.AreEqual(1, cd.Annotations.Count); - Assert.AreEqual("IsTest", cd.Annotations[0].Identifier); - - Assert.AreEqual(1, cd.Methods[0].Annotations.Count); - Assert.AreEqual("TestSetup", cd.Methods[0].Annotations[0].Identifier); - Assert.AreEqual("Setup", cd.Methods[0].Identifier); - Assert.AreEqual("void", cd.Methods[0].ReturnType.Identifier); - - Assert.AreEqual(1, cd.Methods[1].Annotations.Count); - Assert.AreEqual("IsTest", cd.Methods[1].Annotations[0].Identifier); - Assert.AreEqual("AssertTrue", cd.Methods[1].Identifier); - Assert.AreEqual("void", cd.Methods[1].ReturnType.Identifier); - - Assert.AreEqual(1, cd.Methods[2].Annotations.Count); - Assert.AreEqual("IsTest", cd.Methods[2].Annotations[0].Identifier); - Assert.AreEqual("AssertEquals", cd.Methods[2].Identifier); - Assert.AreEqual("void", cd.Methods[2].ReturnType.Identifier); - - Assert.AreEqual(1, cd.Methods[3].Annotations.Count); - Assert.AreEqual("IsTest", cd.Methods[3].Annotations[0].Identifier); - Assert.AreEqual("AssertNotEquals", cd.Methods[3].Identifier); - Assert.AreEqual("void", cd.Methods[3].ReturnType.Identifier); - - Assert.False(cd.Methods[4].Annotations.Any()); - Assert.AreEqual(3, cd.Methods[4].Modifiers.Count); - Assert.AreEqual("testMethod", cd.Methods[4].Modifiers[0]); - Assert.AreEqual("public", cd.Methods[4].Modifiers[1]); - Assert.AreEqual("static", cd.Methods[4].Modifiers[2]); - Assert.AreEqual("AssertNew", cd.Methods[4].Identifier); - Assert.AreEqual("void", cd.Methods[4].ReturnType.Identifier); - - Assert.False(cd.Methods[5].Annotations.Any()); - Assert.AreEqual(3, cd.Methods[5].Modifiers.Count); - Assert.AreEqual("static", cd.Methods[5].Modifiers[0]); - Assert.AreEqual("testMethod", cd.Methods[5].Modifiers[1]); - Assert.AreEqual("public", cd.Methods[5].Modifiers[2]); - Assert.AreEqual("AssertEqualsNew", cd.Methods[5].Identifier); - Assert.AreEqual("void", cd.Methods[5].ReturnType.Identifier); - - Assert.False(cd.Methods[6].Annotations.Any()); - Assert.AreEqual(3, cd.Methods[6].Modifiers.Count); - Assert.AreEqual("static", cd.Methods[6].Modifiers[0]); - Assert.AreEqual("public", cd.Methods[6].Modifiers[1]); - Assert.AreEqual("testMethod", cd.Methods[6].Modifiers[2]); - Assert.AreEqual("AssertNotEqualsNew", cd.Methods[6].Identifier); - Assert.AreEqual("void", cd.Methods[6].ReturnType.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("ClassUnitTest")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Methods.Count, Is.EqualTo(7)); + Assert.That(cd.Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Annotations[0].Identifier, Is.EqualTo("IsTest")); + + Assert.That(cd.Methods[0].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[0].Annotations[0].Identifier, Is.EqualTo("TestSetup")); + Assert.That(cd.Methods[0].Identifier, Is.EqualTo("Setup")); + Assert.That(cd.Methods[0].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[1].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[1].Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(cd.Methods[1].Identifier, Is.EqualTo("AssertTrue")); + Assert.That(cd.Methods[1].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[2].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[2].Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(cd.Methods[2].Identifier, Is.EqualTo("AssertEquals")); + Assert.That(cd.Methods[2].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[3].Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[3].Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(cd.Methods[3].Identifier, Is.EqualTo("AssertNotEquals")); + Assert.That(cd.Methods[3].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[4].Annotations.Any(), Is.False); + Assert.That(cd.Methods[4].Modifiers.Count, Is.EqualTo(3)); + Assert.That(cd.Methods[4].Modifiers[0], Is.EqualTo("testMethod")); + Assert.That(cd.Methods[4].Modifiers[1], Is.EqualTo("public")); + Assert.That(cd.Methods[4].Modifiers[2], Is.EqualTo("static")); + Assert.That(cd.Methods[4].Identifier, Is.EqualTo("AssertNew")); + Assert.That(cd.Methods[4].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[5].Annotations.Any(), Is.False); + Assert.That(cd.Methods[5].Modifiers.Count, Is.EqualTo(3)); + Assert.That(cd.Methods[5].Modifiers[0], Is.EqualTo("static")); + Assert.That(cd.Methods[5].Modifiers[1], Is.EqualTo("testMethod")); + Assert.That(cd.Methods[5].Modifiers[2], Is.EqualTo("public")); + Assert.That(cd.Methods[5].Identifier, Is.EqualTo("AssertEqualsNew")); + Assert.That(cd.Methods[5].ReturnType.Identifier, Is.EqualTo("void")); + + Assert.That(cd.Methods[6].Annotations.Any(), Is.False); + Assert.That(cd.Methods[6].Modifiers.Count, Is.EqualTo(3)); + Assert.That(cd.Methods[6].Modifiers[0], Is.EqualTo("static")); + Assert.That(cd.Methods[6].Modifiers[1], Is.EqualTo("public")); + Assert.That(cd.Methods[6].Modifiers[2], Is.EqualTo("testMethod")); + Assert.That(cd.Methods[6].Identifier, Is.EqualTo("AssertNotEqualsNew")); + Assert.That(cd.Methods[6].ReturnType.Identifier, Is.EqualTo("void")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassUnitTestSeeAllData.cls")] public void ClassUnitTestSeeAllDataIsParsed() { var cd = Apex.ParseClass(ClassUnitTestSeeAllData); - Assert.AreEqual("ClassUnitTestSeeAllData", cd.Identifier); - Assert.AreEqual(1, cd.Annotations.Count); - Assert.AreEqual("IsTest", cd.Annotations[0].Identifier); - Assert.AreEqual("SeeAllData=true", cd.Annotations[0].Parameters); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); + Assert.That(cd.Identifier, Is.EqualTo("ClassUnitTestSeeAllData")); + Assert.That(cd.Annotations.Count, Is.EqualTo(1)); + Assert.That(cd.Annotations[0].Identifier, Is.EqualTo("IsTest")); + Assert.That(cd.Annotations[0].Parameters, Is.EqualTo("SeeAllData=true")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassVirtual.cls")] public void ClassVirtualIsParsed() { var cd = Apex.ParseClass(ClassVirtual); - Assert.AreEqual("ClassVirtual", cd.Identifier); - Assert.AreEqual(0, cd.Annotations.Count); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("virtual", cd.Modifiers[1]); + Assert.That(cd.Identifier, Is.EqualTo("ClassVirtual")); + Assert.That(cd.Annotations.Count, Is.EqualTo(0)); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("virtual")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassWithOutSharing.cls")] public void ClassWithOutSharingIsParsed() { var cd = Apex.ParseClass(ClassWithOutSharing); - Assert.AreEqual("ClassWithOutSharing", cd.Identifier); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("without sharing", cd.Modifiers[1]); + Assert.That(cd.Identifier, Is.EqualTo("ClassWithOutSharing")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("without sharing")); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassWithSharing.cls")] public void ClassWithSharingIsParsed() { var cd = Apex.ParseClass(ClassWithSharing); - Assert.AreEqual("ClassWithSharing", cd.Identifier); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual("with sharing", cd.Modifiers[1]); + Assert.That(cd.Identifier, Is.EqualTo("ClassWithSharing")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Modifiers[1], Is.EqualTo("with sharing")); } [Test(Description = @"SalesForceApexSharp\src\classes\ExceptionDemo.cls")] public void ExceptionDemoIsParsed() { var cd = Apex.ParseClass(ExceptionDemo); - Assert.AreEqual("ExceptionDemo", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(2, cd.Methods.Count); + Assert.That(cd.Identifier, Is.EqualTo("ExceptionDemo")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Methods.Count, Is.EqualTo(2)); var md = cd.Methods[0]; - Assert.NotNull(md.Body); - Assert.AreEqual(1, md.Body.Statements.Count); + Assert.That(md.Body, Is.Not.Null); + Assert.That(md.Body.Statements.Count, Is.EqualTo(1)); var ts = md.Body.Statements[0] as TryStatementSyntax; - Assert.NotNull(ts); - Assert.NotNull(ts.Block); - Assert.AreEqual(1, ts.Block.Statements.Count); - Assert.AreEqual(1, ts.Catches.Count); + Assert.That(ts, Is.Not.Null); + Assert.That(ts.Block, Is.Not.Null); + Assert.That(ts.Block.Statements.Count, Is.EqualTo(1)); + Assert.That(ts.Catches.Count, Is.EqualTo(1)); var cc = ts.Catches[0]; - Assert.AreEqual("MathException", cc.Type.Identifier); - Assert.AreEqual("e", cc.Identifier); - Assert.NotNull(cc.Block); - Assert.AreEqual(1, cc.Block.Statements.Count); + Assert.That(cc.Type.Identifier, Is.EqualTo("MathException")); + Assert.That(cc.Identifier, Is.EqualTo("e")); + Assert.That(cc.Block, Is.Not.Null); + Assert.That(cc.Block.Statements.Count, Is.EqualTo(1)); var fc = ts.Finally; - Assert.NotNull(fc); - Assert.NotNull(fc.Block); - Assert.AreEqual(1, fc.Block.Statements.Count); + Assert.That(fc, Is.Not.Null); + Assert.That(fc.Block, Is.Not.Null); + Assert.That(fc.Block.Statements.Count, Is.EqualTo(1)); } [Test(Description = @"SalesForceApexSharp\src\classes\ForIfWhile.cls")] public void ForIfWhile2AreParsed() { var cd = Apex.ParseClass(ForIfWhile2); - Assert.False(cd.Annotations.Any()); - Assert.AreEqual("ForIfWhile", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(7, cd.Methods.Count); - Assert.False(cd.Properties.Any()); + Assert.That(cd.Annotations.Any(), Is.False); + Assert.That(cd.Identifier, Is.EqualTo("ForIfWhile")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Methods.Count, Is.EqualTo(7)); + Assert.That(cd.Properties.Any(), Is.False); var md = cd.Methods[0]; - Assert.AreEqual("MethodIfClean", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Parameters.Count); - Assert.AreEqual("place", md.Parameters[0].Identifier); - Assert.AreEqual("Integer", md.Parameters[0].Type.Identifier); + Assert.That(md.Identifier, Is.EqualTo("MethodIfClean")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Count, Is.EqualTo(1)); + Assert.That(md.Parameters[0].Identifier, Is.EqualTo("place")); + Assert.That(md.Parameters[0].Type.Identifier, Is.EqualTo("Integer")); var block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); md = cd.Methods[1]; - Assert.AreEqual("MethodForTraditional", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodForTraditional")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); var forStmt = block.Statements[0] as ForStatementSyntax; - Assert.NotNull(forStmt); - Assert.NotNull(forStmt.Declaration); - Assert.AreEqual("Integer", forStmt.Declaration.Type.Identifier); - Assert.AreEqual(1, forStmt.Declaration.Variables.Count); - Assert.AreEqual("i", forStmt.Declaration.Variables[0].Identifier); - Assert.AreEqual("0", forStmt.Declaration.Variables[0].Expression.ExpressionString); - Assert.AreEqual("i < 10", forStmt.Condition.ExpressionString); - Assert.NotNull(forStmt.Incrementors); - Assert.AreEqual(1, forStmt.Incrementors.Count); - Assert.AreEqual("i++", forStmt.Incrementors[0].ExpressionString); + Assert.That(forStmt, Is.Not.Null); + Assert.That(forStmt.Declaration, Is.Not.Null); + Assert.That(forStmt.Declaration.Type.Identifier, Is.EqualTo("Integer")); + Assert.That(forStmt.Declaration.Variables.Count, Is.EqualTo(1)); + Assert.That(forStmt.Declaration.Variables[0].Identifier, Is.EqualTo("i")); + Assert.That(forStmt.Declaration.Variables[0].Expression.ExpressionString, Is.EqualTo("0")); + Assert.That(forStmt.Condition.ExpressionString, Is.EqualTo("i < 10")); + Assert.That(forStmt.Incrementors, Is.Not.Null); + Assert.That(forStmt.Incrementors.Count, Is.EqualTo(1)); + Assert.That(forStmt.Incrementors[0].ExpressionString, Is.EqualTo("i++")); block = forStmt.Statement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug (i + 1)", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug (i + 1)")); md = cd.Methods[2]; - Assert.AreEqual("MethodForIteration", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodForIteration")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); var forEachStmt = block.Statements[1] as ForEachStatementSyntax; - Assert.NotNull(forEachStmt); - Assert.AreEqual("Integer", forEachStmt.Type.Identifier); - Assert.AreEqual("myInt", forEachStmt.Identifier); - Assert.AreEqual("myInts", forEachStmt.Expression.ExpressionString); + Assert.That(forEachStmt, Is.Not.Null); + Assert.That(forEachStmt.Type.Identifier, Is.EqualTo("Integer")); + Assert.That(forEachStmt.Identifier, Is.EqualTo("myInt")); + Assert.That(forEachStmt.Expression.ExpressionString, Is.EqualTo("myInts")); block = forEachStmt.Statement as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); - Assert.AreEqual("System.debug (myInt)", block.Statements[0].Body); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); + Assert.That(block.Statements[0].Body, Is.EqualTo("System.debug (myInt)")); md = cd.Methods[3]; - Assert.AreEqual("MethodDo", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodDo")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); md = cd.Methods[4]; - Assert.AreEqual("MethodWhile", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("MethodWhile")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); md = cd.Methods[5]; - Assert.AreEqual("ForLoopTest", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); + Assert.That(md.Identifier, Is.EqualTo("ForLoopTest")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); md = cd.Methods[6]; - Assert.AreEqual("GetContact", md.Identifier); - Assert.AreEqual("String", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.AreEqual(1, md.Parameters.Count); + Assert.That(md.Identifier, Is.EqualTo("GetContact")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("String")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Count, Is.EqualTo(1)); block = md.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(1, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(1)); } [Test(Description = @"SalesForceApexSharp\src\classes\GetSetDemo.cls")] public void GetSetDemoIsParsed() { var cd = Apex.ParseClass(GetSetDemo); - Assert.AreEqual("GetSetDemo", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(0, cd.Methods.Count); - Assert.AreEqual(11, cd.Properties.Count); - Assert.AreEqual(3, cd.Fields.Count); + Assert.That(cd.Identifier, Is.EqualTo("GetSetDemo")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Methods.Count, Is.EqualTo(0)); + Assert.That(cd.Properties.Count, Is.EqualTo(11)); + Assert.That(cd.Fields.Count, Is.EqualTo(3)); } [Test(Description = @"SalesForceApexSharp\src\classes\IClassInterface.cls")] public void IClassInterfaceIsParsed() { var cd = Apex.ParseClass(IClassInterface) as InterfaceDeclarationSyntax; - Assert.IsNotNull(cd); - Assert.AreEqual("IClassInterface", cd.Identifier); - Assert.IsTrue(cd.IsInterface); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(1, cd.Methods.Count); - Assert.IsTrue(cd.Methods[0].IsAbstract); + Assert.That(cd, Is.Not.Null); + Assert.That(cd.Identifier, Is.EqualTo("IClassInterface")); + Assert.That(cd.IsInterface, Is.True); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[0].IsAbstract, Is.True); } [Test(Description = @"SalesForceApexSharp\src\classes\IClassInterfaceExt.cls")] public void IClassInterfaceExtIsParsed() { var cd = Apex.ParseClass(IClassInterfaceExt) as InterfaceDeclarationSyntax; - Assert.IsNotNull(cd); - Assert.AreEqual("IClassInterfaceExt", cd.Identifier); - Assert.IsTrue(cd.IsInterface); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(1, cd.Methods.Count); + Assert.That(cd, Is.Not.Null); + Assert.That(cd.Identifier, Is.EqualTo("IClassInterfaceExt")); + Assert.That(cd.IsInterface, Is.True); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); } [Test(Description = @"SalesForceApexSharp\src\classes\JsonExample.cls")] public void JsonExampleIsParsed() { var cd = Apex.ParseClass(JsonExample); - Assert.AreEqual("JsonExample", cd.Identifier); - Assert.IsFalse(cd.IsInterface); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(1, cd.Methods.Count); - Assert.AreEqual("JsonExampleMethod", cd.Methods[0].Identifier); - Assert.AreEqual(3, cd.Methods[0].Body.Statements.Count); + Assert.That(cd.Identifier, Is.EqualTo("JsonExample")); + Assert.That(cd.IsInterface, Is.False); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[0].Identifier, Is.EqualTo("JsonExampleMethod")); + Assert.That(cd.Methods[0].Body.Statements.Count, Is.EqualTo(3)); } [Test(Description = @"SalesForceApexSharp\src\classes\ListAndArrayDemo.cls")] //, Ignore("TODO: array and list initializers")] public void ListAndArrayDemoIsParsed() { var cd = Apex.ParseClass(ListAndArrayDemo); - Assert.AreEqual("ListAndArrayDemo", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(2, cd.Fields.Count); - Assert.AreEqual(1, cd.Methods.Count); - Assert.AreEqual("Method", cd.Methods[0].Identifier); - Assert.AreEqual(2, cd.Methods[0].Body.Statements.Count); + Assert.That(cd.Identifier, Is.EqualTo("ListAndArrayDemo")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Fields.Count, Is.EqualTo(2)); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[0].Identifier, Is.EqualTo("Method")); + Assert.That(cd.Methods[0].Body.Statements.Count, Is.EqualTo(2)); } [Test(Description = @"SalesForceApexSharp\src\classes\MethodAndConstructor.cls")] public void MethodAndConstructorIsParsed() { var cd = Apex.ParseClass(MethodAndConstructor); - Assert.AreEqual("MethodAndConstructor", cd.Identifier); - Assert.AreEqual(2, cd.Modifiers.Count); - Assert.AreEqual("global", cd.Modifiers[0]); - Assert.AreEqual("abstract", cd.Modifiers[1]); - Assert.AreEqual(2, cd.Constructors.Count); - Assert.AreEqual(17, cd.Methods.Count); + Assert.That(cd.Identifier, Is.EqualTo("MethodAndConstructor")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(2)); + Assert.That(cd.Modifiers[0], Is.EqualTo("global")); + Assert.That(cd.Modifiers[1], Is.EqualTo("abstract")); + Assert.That(cd.Constructors.Count, Is.EqualTo(2)); + Assert.That(cd.Methods.Count, Is.EqualTo(17)); } [Test(Description = @"SalesForceApexSharp\src\classes\PrimitiveTypes.cls")] public void PrimitiveTypesIsParsed() { var cd = Apex.ParseClass(PrimitiveTypes); - Assert.AreEqual("PrimitiveTypes", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(11, cd.Fields.Count); - Assert.AreEqual(1, cd.Methods.Count); - Assert.AreEqual("DemoMethod", cd.Methods[0].Identifier); - Assert.AreEqual(2, cd.Methods[0].Body.Statements.Count); + Assert.That(cd.Identifier, Is.EqualTo("PrimitiveTypes")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Fields.Count, Is.EqualTo(11)); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Methods[0].Identifier, Is.EqualTo("DemoMethod")); + Assert.That(cd.Methods[0].Body.Statements.Count, Is.EqualTo(2)); } [Test(Description = @"SalesForceApexSharp\src\classes\PropertyAndField.cls")] public void PropertyAndField2IsParsed() { var cd = Apex.ParseClass(PropertyAndField2); - Assert.AreEqual("PropertyAndField", cd.Identifier); - Assert.AreEqual(0, cd.LeadingComments.Count); - Assert.AreEqual(1, cd.Methods.Count); - Assert.AreEqual(3, cd.Properties.Count); - Assert.AreEqual(9, cd.Fields.Count); + Assert.That(cd.Identifier, Is.EqualTo("PropertyAndField")); + Assert.That(cd.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); + Assert.That(cd.Properties.Count, Is.EqualTo(3)); + Assert.That(cd.Fields.Count, Is.EqualTo(9)); var pd = cd.Properties[2]; - Assert.AreEqual("DateTimeGetSetArray", pd.Identifier); - Assert.AreEqual("Datetime", pd.Type.Identifier); - Assert.False(pd.Type.TypeParameters.Any()); - Assert.IsTrue(pd.Type.IsArray); - Assert.NotNull(pd.Getter); - Assert.NotNull(pd.Setter); + Assert.That(pd.Identifier, Is.EqualTo("DateTimeGetSetArray")); + Assert.That(pd.Type.Identifier, Is.EqualTo("Datetime")); + Assert.That(pd.Type.TypeParameters.Any(), Is.False); + Assert.That(pd.Type.IsArray, Is.True); + Assert.That(pd.Getter, Is.Not.Null); + Assert.That(pd.Setter, Is.Not.Null); var fd = cd.Fields[3]; - Assert.AreEqual("DateTimeList", fd.Fields[0].Identifier); - Assert.AreEqual("List", fd.Type.Identifier); - Assert.AreEqual(1, fd.Type.TypeParameters.Count); - Assert.AreEqual("Datetime", fd.Type.TypeParameters[0].Identifier); - Assert.IsFalse(fd.Type.IsArray); - Assert.AreEqual("new List()", fd.Fields[0].Expression.ExpressionString); + Assert.That(fd.Fields[0].Identifier, Is.EqualTo("DateTimeList")); + Assert.That(fd.Type.Identifier, Is.EqualTo("List")); + Assert.That(fd.Type.TypeParameters.Count, Is.EqualTo(1)); + Assert.That(fd.Type.TypeParameters[0].Identifier, Is.EqualTo("Datetime")); + Assert.That(fd.Type.IsArray, Is.False); + Assert.That(fd.Fields[0].Expression.ExpressionString, Is.EqualTo("new List()")); fd = cd.Fields[4]; - Assert.False(fd.Annotations.Any()); - Assert.AreEqual("DateTimeArray", fd.Fields[0].Identifier); - Assert.AreEqual("Datetime", fd.Type.Identifier); - Assert.False(fd.Type.TypeParameters.Any()); - Assert.IsTrue(fd.Type.IsArray); - Assert.AreEqual(1, fd.Modifiers.Count); - Assert.AreEqual("public", fd.Modifiers[0]); - Assert.AreEqual("new Datetime[5]", fd.Fields[0].Expression.ExpressionString); + Assert.That(fd.Annotations.Any(), Is.False); + Assert.That(fd.Fields[0].Identifier, Is.EqualTo("DateTimeArray")); + Assert.That(fd.Type.Identifier, Is.EqualTo("Datetime")); + Assert.That(fd.Type.TypeParameters.Any(), Is.False); + Assert.That(fd.Type.IsArray, Is.True); + Assert.That(fd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(fd.Modifiers[0], Is.EqualTo("public")); + Assert.That(fd.Fields[0].Expression.ExpressionString, Is.EqualTo("new Datetime[5]")); fd = cd.Fields[8]; - Assert.False(fd.Annotations.Any()); - Assert.AreEqual("NameStaticFinal", fd.Fields[0].Identifier); - Assert.AreEqual("String", fd.Type.Identifier); - Assert.False(fd.Type.TypeParameters.Any()); - Assert.False(fd.Type.IsArray); - Assert.AreEqual(3, fd.Modifiers.Count); - Assert.AreEqual("public", fd.Modifiers[0]); - Assert.AreEqual("static", fd.Modifiers[1]); - Assert.AreEqual("final", fd.Modifiers[2]); - Assert.AreEqual("'jay'", fd.Fields[0].Expression.ExpressionString); + Assert.That(fd.Annotations.Any(), Is.False); + Assert.That(fd.Fields[0].Identifier, Is.EqualTo("NameStaticFinal")); + Assert.That(fd.Type.Identifier, Is.EqualTo("String")); + Assert.That(fd.Type.TypeParameters.Any(), Is.False); + Assert.That(fd.Type.IsArray, Is.False); + Assert.That(fd.Modifiers.Count, Is.EqualTo(3)); + Assert.That(fd.Modifiers[0], Is.EqualTo("public")); + Assert.That(fd.Modifiers[1], Is.EqualTo("static")); + Assert.That(fd.Modifiers[2], Is.EqualTo("final")); + Assert.That(fd.Fields[0].Expression.ExpressionString, Is.EqualTo("'jay'")); var md = cd.Methods[0]; - Assert.AreEqual("MethodOne", md.Identifier); - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.False(md.Annotations.Any()); - Assert.False(md.Parameters.Any()); - Assert.AreEqual(1, md.Modifiers.Count); - Assert.AreEqual("public", md.Modifiers[0]); + Assert.That(md.Identifier, Is.EqualTo("MethodOne")); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Annotations.Any(), Is.False); + Assert.That(md.Parameters.Any(), Is.False); + Assert.That(md.Modifiers.Count, Is.EqualTo(1)); + Assert.That(md.Modifiers[0], Is.EqualTo("public")); var block = md.Body; - Assert.NotNull(block); - Assert.AreEqual(7, block.Statements.Count); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(7)); } [Test(Description = @"SalesForceApexSharp\src\classes\RunAll.cls")] public void RunAllIsParsed() { var cd = Apex.ParseClass(RunAll); - Assert.AreEqual("RunAll", cd.Identifier); - Assert.AreEqual(1, cd.Modifiers.Count); - Assert.AreEqual("public", cd.Modifiers[0]); - Assert.AreEqual(0, cd.Fields.Count); - Assert.AreEqual(1, cd.Constructors.Count); - Assert.AreEqual("RunAll", cd.Constructors[0].Identifier); - Assert.AreEqual(10, cd.Constructors[0].Body.Statements.Count); + Assert.That(cd.Identifier, Is.EqualTo("RunAll")); + Assert.That(cd.Modifiers.Count, Is.EqualTo(1)); + Assert.That(cd.Modifiers[0], Is.EqualTo("public")); + Assert.That(cd.Fields.Count, Is.EqualTo(0)); + Assert.That(cd.Constructors.Count, Is.EqualTo(1)); + Assert.That(cd.Constructors[0].Identifier, Is.EqualTo("RunAll")); + Assert.That(cd.Constructors[0].Body.Statements.Count, Is.EqualTo(10)); } [Test] public void CommentsFileIsParsed() { var cd = Apex.ParseClass(Comments); - Assert.AreEqual("Comments", cd.Identifier); - Assert.AreEqual(1, cd.LeadingComments.Count); + Assert.That(cd.Identifier, Is.EqualTo("Comments")); + Assert.That(cd.LeadingComments.Count, Is.EqualTo(1)); } [Test(Description = @"SalesForceApexSharp\src\classes\ClassUnitTestRunAs.cls")] public void ClassUnitTestRunAsIsParsed() { var cd = Apex.ParseClass(ClassUnitTestRunAs); - Assert.AreEqual("ClassUnitTestRunAs", cd.Identifier); - Assert.AreEqual(1, cd.Methods.Count); + Assert.That(cd.Identifier, Is.EqualTo("ClassUnitTestRunAs")); + Assert.That(cd.Methods.Count, Is.EqualTo(1)); var md = cd.Methods[0]; - Assert.AreEqual("void", md.ReturnType.Identifier); - Assert.AreEqual("RunAsExample", md.Identifier); - Assert.AreEqual(2, md.Modifiers.Count); - Assert.AreEqual("static", md.Modifiers[0]); - Assert.AreEqual("testMethod", md.Modifiers[1]); + Assert.That(md.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(md.Identifier, Is.EqualTo("RunAsExample")); + Assert.That(md.Modifiers.Count, Is.EqualTo(2)); + Assert.That(md.Modifiers[0], Is.EqualTo("static")); + Assert.That(md.Modifiers[1], Is.EqualTo("testMethod")); var block = md.Body; - Assert.AreEqual(2, block.Statements.Count); + Assert.That(block.Statements.Count, Is.EqualTo(2)); var runAs = block.Statements[1] as RunAsStatementSyntax; - Assert.NotNull(runAs); - Assert.AreEqual("newUser", runAs.Expression.ExpressionString); - Assert.NotNull(runAs.Statement as BlockSyntax); + Assert.That(runAs, Is.Not.Null); + Assert.That(runAs.Expression.ExpressionString, Is.EqualTo("newUser")); + Assert.That(runAs.Statement as BlockSyntax, Is.Not.Null); } [Test(Description = @"SalesForceApexSharp\src\classes\CommentFail.cls")] public void CommentsFailFileIsParsed() { var cd = Apex.ParseClass(CommentFail); - Assert.AreEqual("CommentFail", cd.Identifier); - Assert.AreEqual(0, cd.LeadingComments.Count); - Assert.AreEqual(1, cd.InnerComments.Count); - Assert.AreEqual(0, cd.TrailingComments.Count); + Assert.That(cd.Identifier, Is.EqualTo("CommentFail")); + Assert.That(cd.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(cd.InnerComments.Count, Is.EqualTo(1)); + Assert.That(cd.TrailingComments.Count, Is.EqualTo(0)); } [Test(Description = @"SalesForceApexSharp\src\classes\ForIfWhile.cls")] public void ForIfWhile3IsParsed() { var cd = Apex.ParseClass(ForIfWhile3); - Assert.AreEqual("ForIfWhile", cd.Identifier); - Assert.AreEqual(8, cd.Methods.Count); + Assert.That(cd.Identifier, Is.EqualTo("ForIfWhile")); + Assert.That(cd.Methods.Count, Is.EqualTo(8)); var md = cd.Methods[7]; - Assert.AreEqual("ForSoql", md.Identifier); - Assert.AreEqual(1, md.Body.Statements.Count); + Assert.That(md.Identifier, Is.EqualTo("ForSoql")); + Assert.That(md.Body.Statements.Count, Is.EqualTo(1)); var forEach = md.Body.Statements[0] as ForEachStatementSyntax; - Assert.AreEqual("Contact", forEach.Type.Identifier); - Assert.AreEqual("contactList", forEach.Identifier); - Assert.AreEqual("[SELECT Id, Name FROM Contact]", forEach.Expression.ExpressionString); - Assert.NotNull(forEach.Statement as BlockSyntax); + Assert.That(forEach.Type.Identifier, Is.EqualTo("Contact")); + Assert.That(forEach.Identifier, Is.EqualTo("contactList")); + Assert.That(forEach.Expression.ExpressionString, Is.EqualTo("[SELECT Id, Name FROM Contact]")); + Assert.That(forEach.Statement as BlockSyntax, Is.Not.Null); } [Test(Description = @"SalesForceApexSharp\src\classes\PropertyAndField.cls")] public void PropertyAndField3IsParsed() { var cd = Apex.ParseClass(PropertyAndField3); - Assert.AreEqual("PropertyAndField", cd.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("PropertyAndField")); - Assert.AreEqual(1, cd.Initializers.Count); - Assert.AreEqual(1, cd.Initializers[0].Body.Statements.Count); - Assert.AreEqual("shouldRedirect =false", cd.Initializers[0].Body.Statements[0].Body); + Assert.That(cd.Initializers.Count, Is.EqualTo(1)); + Assert.That(cd.Initializers[0].Body.Statements.Count, Is.EqualTo(1)); + Assert.That(cd.Initializers[0].Body.Statements[0].Body, Is.EqualTo("shouldRedirect =false")); } [Test(Description = @"Portions of https://raw.githubusercontent.com/financialforcedev/fflib-apex-common/master/fflib/src/classes/fflib_ApplicationTest.cls")] public void ApplicationTestIsParsed() { var cd = Apex.ParseClass(ApplicationTest); - Assert.AreEqual("ApplicationTest", cd.Identifier); + Assert.That(cd.Identifier, Is.EqualTo("ApplicationTest")); } } } diff --git a/ApexSharp.ApexParser.Tests/Parser/ApexSyntaxTests.cs b/ApexSharp.ApexParser.Tests/Parser/ApexSyntaxTests.cs index ee22c68..8504704 100644 --- a/ApexSharp.ApexParser.Tests/Parser/ApexSyntaxTests.cs +++ b/ApexSharp.ApexParser.Tests/Parser/ApexSyntaxTests.cs @@ -17,11 +17,11 @@ public void DescendantNodesAndSelfForClassEnumReturnsDescendantNodesAndSelf() { var syntax = ApexParser.ApexSharpParser.GetApexAst(ClassEnum); var nodes = syntax.DescendantNodesAndSelf().ToArray(); - Assert.AreEqual(4, nodes.Length); - Assert.IsInstanceOf(nodes[0]); - Assert.IsInstanceOf(nodes[1]); - Assert.IsInstanceOf(nodes[2]); - Assert.IsInstanceOf(nodes[3]); + Assert.That(nodes.Length, Is.EqualTo(4)); + Assert.That(nodes[0], Is.InstanceOf()); + Assert.That(nodes[1], Is.InstanceOf()); + Assert.That(nodes[2], Is.InstanceOf()); + Assert.That(nodes[3], Is.InstanceOf()); } [Test] @@ -29,10 +29,10 @@ public void DescendantNodesForClassEnumReturnsDescendantNodesWithoutSelf() { var syntax = ApexParser.ApexSharpParser.GetApexAst(ClassEnum); var nodes = syntax.DescendantNodes().ToArray(); - Assert.AreEqual(3, nodes.Length); - Assert.IsInstanceOf(nodes[0]); - Assert.IsInstanceOf(nodes[1]); - Assert.IsInstanceOf(nodes[2]); + Assert.That(nodes.Length, Is.EqualTo(3)); + Assert.That(nodes[0], Is.InstanceOf()); + Assert.That(nodes[1], Is.InstanceOf()); + Assert.That(nodes[2], Is.InstanceOf()); } [Test] @@ -40,19 +40,19 @@ public void DescendantNodesAndSelfForClassInterfaceReturnsDescendantNodesAndSelf { var syntax = ApexParser.ApexSharpParser.GetApexAst(ClassInterface); var nodes = syntax.DescendantNodesAndSelf().ToArray(); - Assert.AreEqual(12, nodes.Length); - Assert.IsInstanceOf(nodes[0]); - Assert.IsInstanceOf(nodes[1]); - Assert.IsInstanceOf(nodes[2]); - Assert.IsInstanceOf(nodes[3]); - Assert.IsInstanceOf(nodes[4]); - Assert.IsInstanceOf(nodes[5]); - Assert.IsInstanceOf(nodes[6]); - Assert.IsInstanceOf(nodes[7]); - Assert.IsInstanceOf(nodes[8]); - Assert.IsInstanceOf(nodes[9]); - Assert.IsInstanceOf(nodes[10]); - Assert.IsInstanceOf(nodes[11]); + Assert.That(nodes.Length, Is.EqualTo(12)); + Assert.That(nodes[0], Is.InstanceOf()); + Assert.That(nodes[1], Is.InstanceOf()); + Assert.That(nodes[2], Is.InstanceOf()); + Assert.That(nodes[3], Is.InstanceOf()); + Assert.That(nodes[4], Is.InstanceOf()); + Assert.That(nodes[5], Is.InstanceOf()); + Assert.That(nodes[6], Is.InstanceOf()); + Assert.That(nodes[7], Is.InstanceOf()); + Assert.That(nodes[8], Is.InstanceOf()); + Assert.That(nodes[9], Is.InstanceOf()); + Assert.That(nodes[10], Is.InstanceOf()); + Assert.That(nodes[11], Is.InstanceOf()); } [Test] @@ -60,18 +60,18 @@ public void DescendantNodesForClassInterfaceReturnsDescendantNodesWithoutSelf() { var syntax = ApexParser.ApexSharpParser.GetApexAst(ClassInterface); var nodes = syntax.DescendantNodes().ToArray(); - Assert.AreEqual(11, nodes.Length); - Assert.IsInstanceOf(nodes[0]); - Assert.IsInstanceOf(nodes[1]); - Assert.IsInstanceOf(nodes[2]); - Assert.IsInstanceOf(nodes[3]); - Assert.IsInstanceOf(nodes[4]); - Assert.IsInstanceOf(nodes[5]); - Assert.IsInstanceOf(nodes[6]); - Assert.IsInstanceOf(nodes[7]); - Assert.IsInstanceOf(nodes[8]); - Assert.IsInstanceOf(nodes[9]); - Assert.IsInstanceOf(nodes[10]); + Assert.That(nodes.Length, Is.EqualTo(11)); + Assert.That(nodes[0], Is.InstanceOf()); + Assert.That(nodes[1], Is.InstanceOf()); + Assert.That(nodes[2], Is.InstanceOf()); + Assert.That(nodes[3], Is.InstanceOf()); + Assert.That(nodes[4], Is.InstanceOf()); + Assert.That(nodes[5], Is.InstanceOf()); + Assert.That(nodes[6], Is.InstanceOf()); + Assert.That(nodes[7], Is.InstanceOf()); + Assert.That(nodes[8], Is.InstanceOf()); + Assert.That(nodes[9], Is.InstanceOf()); + Assert.That(nodes[10], Is.InstanceOf()); } [Test] @@ -79,15 +79,15 @@ public void DescendantNodesAndSelfForClassInterfaceWithFilterReturnsDescendantNo { var syntax = ApexParser.ApexSharpParser.GetApexAst(ClassInterface); var nodes = syntax.DescendantNodesAndSelf(x => !(x is BlockSyntax)).ToArray(); - Assert.AreEqual(8, nodes.Length); - Assert.IsInstanceOf(nodes[0]); - Assert.IsInstanceOf(nodes[1]); - Assert.IsInstanceOf(nodes[2]); - Assert.IsInstanceOf(nodes[3]); - Assert.IsInstanceOf(nodes[4]); - Assert.IsInstanceOf(nodes[5]); - Assert.IsInstanceOf(nodes[6]); - Assert.IsInstanceOf(nodes[7]); + Assert.That(nodes.Length, Is.EqualTo(8)); + Assert.That(nodes[0], Is.InstanceOf()); + Assert.That(nodes[1], Is.InstanceOf()); + Assert.That(nodes[2], Is.InstanceOf()); + Assert.That(nodes[3], Is.InstanceOf()); + Assert.That(nodes[4], Is.InstanceOf()); + Assert.That(nodes[5], Is.InstanceOf()); + Assert.That(nodes[6], Is.InstanceOf()); + Assert.That(nodes[7], Is.InstanceOf()); } [Test] @@ -95,17 +95,17 @@ public void DescendantNodesAndSelfForClassTwoReturnsDescendantNodesAndSelf() { var syntax = ApexParser.ApexSharpParser.GetApexAst(ClassTwo); var nodes = syntax.DescendantNodesAndSelf().ToArray(); - Assert.AreEqual(10, nodes.Length); - Assert.IsInstanceOf(nodes[0]); - Assert.IsInstanceOf(nodes[1]); - Assert.IsInstanceOf(nodes[2]); - Assert.IsInstanceOf(nodes[3]); - Assert.IsInstanceOf(nodes[4]); - Assert.IsInstanceOf(nodes[5]); - Assert.IsInstanceOf(nodes[6]); - Assert.IsInstanceOf(nodes[7]); - Assert.IsInstanceOf(nodes[8]); - Assert.IsInstanceOf(nodes[9]); + Assert.That(nodes.Length, Is.EqualTo(10)); + Assert.That(nodes[0], Is.InstanceOf()); + Assert.That(nodes[1], Is.InstanceOf()); + Assert.That(nodes[2], Is.InstanceOf()); + Assert.That(nodes[3], Is.InstanceOf()); + Assert.That(nodes[4], Is.InstanceOf()); + Assert.That(nodes[5], Is.InstanceOf()); + Assert.That(nodes[6], Is.InstanceOf()); + Assert.That(nodes[7], Is.InstanceOf()); + Assert.That(nodes[8], Is.InstanceOf()); + Assert.That(nodes[9], Is.InstanceOf()); } [Test] @@ -115,16 +115,16 @@ public void CanLocateSpecificNodesInSoqlDemo2SyntaxTree() var nodes = syntax.DescendantNodesAndSelf().ToArray(); var deleteWorked = nodes.OfType().FirstOrDefault(n => n.Body == "System.debug('Delete Worked')"); - Assert.NotNull(deleteWorked); - Assert.AreEqual(1, deleteWorked.DescendantNodesAndSelf().Count()); + Assert.That(deleteWorked, Is.Not.Null); + Assert.That(deleteWorked.DescendantNodesAndSelf().Count(), Is.EqualTo(1)); var forEachOverSoql = nodes.OfType().FirstOrDefault(n => n.Expression.ExpressionString.Contains("SELECT")); - Assert.NotNull(forEachOverSoql); - Assert.AreEqual(6, forEachOverSoql.DescendantNodesAndSelf().Count()); + Assert.That(forEachOverSoql, Is.Not.Null); + Assert.That(forEachOverSoql.DescendantNodesAndSelf().Count(), Is.EqualTo(6)); var runAsStatement = nodes.OfType().SingleOrDefault(); - Assert.NotNull(runAsStatement); - Assert.AreEqual(21, runAsStatement.DescendantNodesAndSelf().Count()); + Assert.That(runAsStatement, Is.Not.Null); + Assert.That(runAsStatement.DescendantNodesAndSelf().Count(), Is.EqualTo(21)); } } } diff --git a/ApexSharp.ApexParser.Tests/Parser/MethodTestData.cs b/ApexSharp.ApexParser.Tests/Parser/MethodTestData.cs index 8325c58..c66dced 100644 --- a/ApexSharp.ApexParser.Tests/Parser/MethodTestData.cs +++ b/ApexSharp.ApexParser.Tests/Parser/MethodTestData.cs @@ -29,21 +29,21 @@ public void MethodSigTestOne() var method = Apex.MethodDeclaration.Parse(methodSig); - Assert.AreEqual(2, method.Modifiers.Count); - Assert.AreEqual("public", method.Modifiers[0]); - Assert.AreEqual("static", method.Modifiers[1]); - Assert.AreEqual("void", method.ReturnType.Identifier); - Assert.AreEqual("GetNumber", method.Identifier); + Assert.That(method.Modifiers.Count, Is.EqualTo(2)); + Assert.That(method.Modifiers[0], Is.EqualTo("public")); + Assert.That(method.Modifiers[1], Is.EqualTo("static")); + Assert.That(method.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(method.Identifier, Is.EqualTo("GetNumber")); - Assert.AreEqual(1, method.Parameters.Count); - Assert.AreEqual("String", method.Parameters[0].Type.Identifier); - Assert.AreEqual("name", method.Parameters[0].Identifier); + Assert.That(method.Parameters.Count, Is.EqualTo(1)); + Assert.That(method.Parameters[0].Type.Identifier, Is.EqualTo("String")); + Assert.That(method.Parameters[0].Identifier, Is.EqualTo("name")); var block = method.Body as BlockSyntax; - Assert.NotNull(block); - Assert.False(block.Statements.Any()); - Assert.AreEqual(1, block.InnerComments.Count); - Assert.AreEqual(" Comment ", block.InnerComments[0]); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Any(), Is.False); + Assert.That(block.InnerComments.Count, Is.EqualTo(1)); + Assert.That(block.InnerComments[0], Is.EqualTo(" Comment ")); } [Test] @@ -57,19 +57,19 @@ public void MethodWithSomeDummyBody() var method = Apex.MethodDeclaration.Parse(methodSig); - Assert.AreEqual(2, method.Modifiers.Count); - Assert.AreEqual("public", method.Modifiers[0]); - Assert.AreEqual("testMethod", method.Modifiers[1]); - Assert.AreEqual("void", method.ReturnType.Identifier); - Assert.AreEqual("MethodWithSomeDummyBody", method.Identifier); + Assert.That(method.Modifiers.Count, Is.EqualTo(2)); + Assert.That(method.Modifiers[0], Is.EqualTo("public")); + Assert.That(method.Modifiers[1], Is.EqualTo("testMethod")); + Assert.That(method.ReturnType.Identifier, Is.EqualTo("void")); + Assert.That(method.Identifier, Is.EqualTo("MethodWithSomeDummyBody")); - Assert.False(method.Parameters.Any()); + Assert.That(method.Parameters.Any(), Is.False); var block = method.Body as BlockSyntax; - Assert.NotNull(block); - Assert.AreEqual(2, block.Statements.Count); - Assert.AreEqual("final string methodSig = 'Something'", block.Statements[0].Body); - Assert.AreEqual("new List()", (block.Statements[1] as ReturnStatementSyntax).Expression.ExpressionString); + Assert.That(block, Is.Not.Null); + Assert.That(block.Statements.Count, Is.EqualTo(2)); + Assert.That(block.Statements[0].Body, Is.EqualTo("final string methodSig = 'Something'")); + Assert.That((block.Statements[1] as ReturnStatementSyntax).Expression.ExpressionString, Is.EqualTo("new List()")); } } } diff --git a/ApexSharp.ApexParser.Tests/TestFixtureBase.cs b/ApexSharp.ApexParser.Tests/TestFixtureBase.cs index 425f770..a1a530e 100644 --- a/ApexSharp.ApexParser.Tests/TestFixtureBase.cs +++ b/ApexSharp.ApexParser.Tests/TestFixtureBase.cs @@ -19,12 +19,12 @@ protected void CompareLineByLine(string actual, string expected) for (int i = 0; i < Min(expectedList.Length, actualList.Length); i++) { - Assert.AreEqual(expectedList[i].Trim(), actualList[i].Trim()); + Assert.That(actualList[i].Trim(), Is.EqualTo(expectedList[i].Trim())); } if (Abs(expectedList.Length - actualList.Length) > 1) { - Assert.Fail("Too many difference in lines: expected {0}, actual {1}", expectedList.Length, actualList.Length); + Assert.Fail($"Too many difference in lines: expected {expectedList.Length}, actual {actualList.Length}"); } } } diff --git a/ApexSharp.ApexParser.Tests/Toolbox/ApiPlaygroundTests.cs b/ApexSharp.ApexParser.Tests/Toolbox/ApiPlaygroundTests.cs index 2376d52..c6becce 100644 --- a/ApexSharp.ApexParser.Tests/Toolbox/ApiPlaygroundTests.cs +++ b/ApexSharp.ApexParser.Tests/Toolbox/ApiPlaygroundTests.cs @@ -114,24 +114,24 @@ public void TestPolymorphicQueryApi() { // multiple results List list = Soql.Query("select * from Customer where email = :email and name = :name and age > :age", "jay@jayonsoftware.com", "jay", 20); - Assert.NotNull(list); - Assert.AreEqual(3, list.Count); + Assert.That(list, Is.Not.Null); + Assert.That(list.Count, Is.EqualTo(3)); // single result Customer customer = Soql.Query("select * from Customer where email = :email and name = :name and age > :age", "jay@jayonsoftware.com", "jay", 20); - Assert.NotNull(customer); - Assert.AreEqual("Jay", customer.Name); - Assert.AreEqual("jay@jayonsoftware.com", customer.Email); + Assert.That(customer, Is.Not.Null); + Assert.That(customer.Name, Is.EqualTo("Jay")); + Assert.That(customer.Email, Is.EqualTo("jay@jayonsoftware.com")); // query text string query = Soql.Query("select * from Customer where email = :email and name = :name and age > :age", "jay@jayonsoftware.com", "jay", 20); - Assert.NotNull(query); - Assert.AreEqual("select * from Customer where email = :email and name = :name and age > :age", query); + Assert.That(query, Is.Not.Null); + Assert.That(query, Is.EqualTo("select * from Customer where email = :email and name = :name and age > :age")); // Database.getQueryLocator(query) var result = Database.GetQueryLocator(Soql.Query("select * from Customer where email = :email and name = :name and age > :age", "jay@jayonsoftware.com", "jay", 20)); - Assert.NotNull(result); - Assert.AreEqual("select * from Customer where email = :email and name = :name and age > :age", result); + Assert.That(result, Is.Not.Null); + Assert.That(result, Is.EqualTo("select * from Customer where email = :email and name = :name and age > :age")); } } } diff --git a/ApexSharp.ApexParser.Tests/Toolbox/GenericExpressionHelperTests.cs b/ApexSharp.ApexParser.Tests/Toolbox/GenericExpressionHelperTests.cs index dc53527..688d7e5 100644 --- a/ApexSharp.ApexParser.Tests/Toolbox/GenericExpressionHelperTests.cs +++ b/ApexSharp.ApexParser.Tests/Toolbox/GenericExpressionHelperTests.cs @@ -17,21 +17,21 @@ public class GenericExpressionHelperTests private void Check(string expr, int count) { var parts = GenericExpressionHelper.Split(expr); - Assert.AreEqual(expr ?? string.Empty, string.Concat(parts)); - Assert.AreEqual(count, parts.Length); + Assert.That(string.Concat(parts), Is.EqualTo(expr ?? string.Empty)); + Assert.That(parts.Length, Is.EqualTo(count)); } private void Check(string expr, params string[] expectedParts) { var parts = GenericExpressionHelper.Split(expr); - Assert.AreEqual(expr, string.Concat(parts)); + Assert.That(string.Concat(parts), Is.EqualTo(expr)); if (!expectedParts.IsNullOrEmpty()) { - Assert.AreEqual(expectedParts.Length, parts.Length); + Assert.That(parts.Length, Is.EqualTo(expectedParts.Length)); foreach (var part in parts.Zip(expectedParts, (p, e) => new { p, e })) { - Assert.AreEqual(part.e, part.p); + Assert.That(part.p, Is.EqualTo(part.e)); } } } @@ -111,31 +111,31 @@ public void ApexCodeIsSplitAndAssembledBackWithoutErrors() => // CommentFails ha [Test] public void GetSoqlTableNameForInvalidInputDoesntThrowExpressions() { - Assert.DoesNotThrow(() => + Assert.That(() => { - Assert.True(string.IsNullOrEmpty(GetTableName(null))); - Assert.True(string.IsNullOrEmpty(GetTableName(string.Empty))); - Assert.True(string.IsNullOrEmpty(GetTableName("Hello World"))); - }); + Assert.That(string.IsNullOrEmpty(GetTableName(null)), Is.True); + Assert.That(string.IsNullOrEmpty(GetTableName(string.Empty)), Is.True); + Assert.That(string.IsNullOrEmpty(GetTableName("Hello World")), Is.True); + }, Throws.Nothing); } [Test] public void GetSoqlTableNameForValidSoqlQueriesReturnsTableNameSpecifiedAfterFromKeyword() => - Assert.AreEqual("Contact", GetTableName(@"SELECT Id, Email, Phone + Assert.That(GetTableName(@"SELECT Id, Email, Phone FROM - Contact WHERE Email = :email")); + Contact WHERE Email = :email"), Is.EqualTo("Contact")); private string[] GetParameters(string soqlQuery) => GenericExpressionHelper.GetSoqlParameters(soqlQuery); [Test] public void GetSoqlParametersForInvalidInputDoesntThrowExpressions() { - Assert.DoesNotThrow(() => + Assert.That(() => { - Assert.True(GetParameters(null).IsNullOrEmpty()); - Assert.True(GetParameters(string.Empty).IsNullOrEmpty()); - Assert.True(GetParameters("Hello World").IsNullOrEmpty()); - }); + Assert.That(GetParameters(null).IsNullOrEmpty(), Is.True); + Assert.That(GetParameters(string.Empty).IsNullOrEmpty(), Is.True); + Assert.That(GetParameters("Hello World").IsNullOrEmpty(), Is.True); + }, Throws.Nothing); } [Test] @@ -144,15 +144,15 @@ public void GetSoqlParametersForValidSoqlQueriesReturnsTableNameSpecifiedAfterFr var args = GetParameters(@"SELECT Id, Email, Phone FROM Contact WHERE Email = :email"); - Assert.NotNull(args); - Assert.AreEqual(1, args.Length); - Assert.AreEqual("email", args[0]); + Assert.That(args, Is.Not.Null); + Assert.That(args.Length, Is.EqualTo(1)); + Assert.That(args[0], Is.EqualTo("email")); args = GetParameters("SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id or Email = :email"); - Assert.NotNull(args); - Assert.AreEqual(2, args.Length); - Assert.AreEqual("contactNew.Id", args[0]); - Assert.AreEqual("email", args[1]); + Assert.That(args, Is.Not.Null); + Assert.That(args.Length, Is.EqualTo(2)); + Assert.That(args[0], Is.EqualTo("contactNew.Id")); + Assert.That(args[1], Is.EqualTo("email")); } private string[] GetFields(string soqlQuery) => GenericExpressionHelper.GetSoqlFields(soqlQuery); @@ -160,12 +160,12 @@ public void GetSoqlParametersForValidSoqlQueriesReturnsTableNameSpecifiedAfterFr [Test] public void GetSoqlFieldsForInvalidInputDoesntThrowExpressions() { - Assert.DoesNotThrow(() => + Assert.That(() => { - Assert.True(GetFields(null).IsNullOrEmpty()); - Assert.True(GetFields(string.Empty).IsNullOrEmpty()); - Assert.True(GetFields("Hello World").IsNullOrEmpty()); - }); + Assert.That(GetFields(null).IsNullOrEmpty(), Is.True); + Assert.That(GetFields(string.Empty).IsNullOrEmpty(), Is.True); + Assert.That(GetFields("Hello World").IsNullOrEmpty(), Is.True); + }, Throws.Nothing); } [Test] @@ -175,26 +175,26 @@ public void GetSoqlFieldsForValidSoqlQueriesReturnsArrayOfFieldNamesBetweenSelec Phone FROM Contact WHERE Email = :email"); - Assert.NotNull(fields); - Assert.AreEqual(3, fields.Length); - Assert.AreEqual("Id", fields[0]); - Assert.AreEqual("Email", fields[1]); - Assert.AreEqual("Phone", fields[2]); + Assert.That(fields, Is.Not.Null); + Assert.That(fields.Length, Is.EqualTo(3)); + Assert.That(fields[0], Is.EqualTo("Id")); + Assert.That(fields[1], Is.EqualTo("Email")); + Assert.That(fields[2], Is.EqualTo("Phone")); fields = GetFields("SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id or Email = :email"); - Assert.NotNull(fields); - Assert.AreEqual(2, fields.Length); - Assert.AreEqual("Id", fields[0]); - Assert.AreEqual("Email", fields[1]); + Assert.That(fields, Is.Not.Null); + Assert.That(fields.Length, Is.EqualTo(2)); + Assert.That(fields[0], Is.EqualTo("Id")); + Assert.That(fields[1], Is.EqualTo("Email")); fields = GetFields("SELECT A,b,something, 123, c from COntacts"); - Assert.NotNull(fields); - Assert.AreEqual(5, fields.Length); - Assert.AreEqual("A", fields[0]); - Assert.AreEqual("b", fields[1]); - Assert.AreEqual("something", fields[2]); - Assert.AreEqual("123", fields[3]); - Assert.AreEqual("c", fields[4]); + Assert.That(fields, Is.Not.Null); + Assert.That(fields.Length, Is.EqualTo(5)); + Assert.That(fields[0], Is.EqualTo("A")); + Assert.That(fields[1], Is.EqualTo("b")); + Assert.That(fields[2], Is.EqualTo("something")); + Assert.That(fields[3], Is.EqualTo("123")); + Assert.That(fields[4], Is.EqualTo("c")); } [Test] @@ -202,13 +202,13 @@ public void GetSoqlExpressionReturnsApexSoqlExpressionBody() { var text = "List contacts = Soql.Query(\"SELECT Id, Email, Phone FROM Contact\");"; var expr = GenericExpressionHelper.ExtractSoqlQueries(text); - Assert.AreEqual(1, expr.Length); - Assert.AreEqual("SELECT Id, Email, Phone FROM Contact", expr[0]); + Assert.That(expr.Length, Is.EqualTo(1)); + Assert.That(expr[0], Is.EqualTo("SELECT Id, Email, Phone FROM Contact")); text = "Soql.Query(\"SELECT Id, Email, Phone FROM Contact WHERE Email = :email\", email);"; expr = GenericExpressionHelper.ExtractSoqlQueries(text); - Assert.AreEqual(1, expr.Length); - Assert.AreEqual("SELECT Id, Email, Phone FROM Contact WHERE Email = :email", expr[0]); + Assert.That(expr.Length, Is.EqualTo(1)); + Assert.That(expr[0], Is.EqualTo("SELECT Id, Email, Phone FROM Contact WHERE Email = :email")); } [Test] @@ -216,11 +216,11 @@ public void ConvertSoqlExpressionReturnsConvertedApexSoqlExpression() { var text = "List contacts = Soql.Query(\"SELECT Id, Email, Phone FROM Contact\");"; var expr = GenericExpressionHelper.ConvertSoqlQueriesToApex(text); - Assert.AreEqual("List contacts = [SELECT Id, Email, Phone FROM Contact];", expr); + Assert.That(expr, Is.EqualTo("List contacts = [SELECT Id, Email, Phone FROM Contact];")); text = @"List contacts = Soql.Query(""SELECT Id, Email, Phone FROM Contact WHERE Email = :email"", email);"; expr = GenericExpressionHelper.ConvertSoqlQueriesToApex(text); - Assert.AreEqual("List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = :email];", expr); + Assert.That(expr, Is.EqualTo("List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = :email];")); } [Test] @@ -228,19 +228,19 @@ public void ConvertSoqlInserUpdateDeleteOperationsReturnsApexStatements() { var text = "Soql.Insert(contact);"; var apex = GenericExpressionHelper.ConvertSoqlStatementsToApex(text); - Assert.AreEqual("insert contact;", apex); + Assert.That(apex, Is.EqualTo("insert contact;")); text = "Soql.Update(contact);"; apex = GenericExpressionHelper.ConvertSoqlStatementsToApex(text); - Assert.AreEqual("update contact;", apex); + Assert.That(apex, Is.EqualTo("update contact;")); text = "Soql.Upsert(contact);"; apex = GenericExpressionHelper.ConvertSoqlStatementsToApex(text); - Assert.AreEqual("upsert contact;", apex); + Assert.That(apex, Is.EqualTo("upsert contact;")); text = "Soql.Delete(contact);"; apex = GenericExpressionHelper.ConvertSoqlStatementsToApex(text); - Assert.AreEqual("delete contact;", apex); + Assert.That(apex, Is.EqualTo("delete contact;")); } [Test] @@ -248,11 +248,11 @@ public void SomeDotClassIsConvertedToTypeofClass() { var text = "string.class"; var csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(string)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(string)")); text = "mock(MyLittleClass.class)"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("mock(typeof(MyLittleClass))", csharp); + Assert.That(csharp, Is.EqualTo("mock(typeof(MyLittleClass))")); } [Test] @@ -260,52 +260,52 @@ public void ComplexClassExpressionsAreConvertedToTypeof() { var text = "Map.class"; var csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(Map)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(Map)")); text = "string12.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(string12)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(string12)")); text = "Some.New.Stuff.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(Some.New.Stuff)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(Some.New.Stuff)")); text = "List.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(List)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(List)")); text = "List.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(List)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(List)")); text = "System.List.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(System.List)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(System.List)")); text = "System.Map.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(System.Map)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(System.Map)")); text = "Map, string>.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(Map, string>)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(Map, string>)")); text = "Map>.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(Map>)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(Map>)")); text = "Map, System.List>.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(Map, System.List>)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(Map, System.List>)")); text = "Map , System.List>.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("typeof(Map , System.List>)", csharp); + Assert.That(csharp, Is.EqualTo("typeof(Map , System.List>)")); // more than two levels deep — cannot be supported by regular expressions text = "Map>, System.List>.class"; csharp = GenericExpressionHelper.ConvertTypeofExpressionsToCSharp(text); - Assert.AreEqual("Map>, System.List>.class", csharp); + Assert.That(csharp, Is.EqualTo("Map>, System.List>.class")); } [Test] @@ -313,16 +313,16 @@ public void TypeofSomeIsConvertedToSomeDotClass() { var text = "typeof(string)"; var apex = GenericExpressionHelper.ConvertTypeofExpressionsToApex(text); - Assert.AreEqual("string.class", apex); + Assert.That(apex, Is.EqualTo("string.class")); text = "mock(typeof(MyLittleClass))"; apex = GenericExpressionHelper.ConvertTypeofExpressionsToApex(text); - Assert.AreEqual("mock(MyLittleClass.class)", apex); + Assert.That(apex, Is.EqualTo("mock(MyLittleClass.class)")); // backward conversion is supported text = "typeof(Map)"; apex = GenericExpressionHelper.ConvertTypeofExpressionsToApex(text); - Assert.AreEqual("Map.class", apex); + Assert.That(apex, Is.EqualTo("Map.class")); } [Test] @@ -330,20 +330,20 @@ public void StringValueofSomethingIsConvertedToSomethingToString() { var text = "string.valueOf(1)"; var csharp = GenericExpressionHelper.ConvertStringValueofToString(text); - Assert.AreEqual("1.ToString()", csharp); + Assert.That(csharp, Is.EqualTo("1.ToString()")); text = "string.valueOf(something)"; csharp = GenericExpressionHelper.ConvertStringValueofToString(text); - Assert.AreEqual("something.ToString()", csharp); + Assert.That(csharp, Is.EqualTo("something.ToString()")); text = "string.valueOf(something+1)"; csharp = GenericExpressionHelper.ConvertStringValueofToString(text); - Assert.AreEqual("(something+1).ToString()", csharp); + Assert.That(csharp, Is.EqualTo("(something+1).ToString()")); // not supported by regex-based expression helper text = "string.valueOf(method())"; csharp = GenericExpressionHelper.ConvertStringValueofToString(text); - Assert.AreEqual("string.valueOf(method())", csharp); + Assert.That(csharp, Is.EqualTo("string.valueOf(method())")); } [Test] @@ -351,19 +351,19 @@ public void DateTimeNowAndDateTodayAreConverted() { var text = "Datetime.now()"; var csharp = GenericExpressionHelper.ConvertApexDateTimeNowToCSharp(text); - Assert.AreEqual("DateTime.Now", csharp); + Assert.That(csharp, Is.EqualTo("DateTime.Now")); text = "Date.today()"; csharp = GenericExpressionHelper.ConvertApexDateTodayToCSharp(text); - Assert.AreEqual("DateTime.Today", csharp); + Assert.That(csharp, Is.EqualTo("DateTime.Today")); text = "DateTime.Now"; var apex = GenericExpressionHelper.ConvertCSharpDateTimeNowToApex(text); - Assert.AreEqual("Datetime.now()", apex); + Assert.That(apex, Is.EqualTo("Datetime.now()")); text = "DateTime.Today"; apex = GenericExpressionHelper.ConvertCSharpDateTimeTodayToApex(text); - Assert.AreEqual("Date.today()", apex); + Assert.That(apex, Is.EqualTo("Date.today()")); } [Test] @@ -374,19 +374,19 @@ string Convert(string x) => var text = "new Something(Property = 1)"; var csharp = Convert(text); - Assert.AreEqual("new Something { Property = 1 }", csharp); + Assert.That(csharp, Is.EqualTo("new Something { Property = 1 }")); text = @"new MyClass (Email = 'some\'@example.com', Name = 'Hello')"; csharp = Convert(text); - Assert.AreEqual(@"new MyClass { Email = 'some\'@example.com', Name = 'Hello' }", csharp); + Assert.That(csharp, Is.EqualTo(@"new MyClass { Email = 'some\'@example.com', Name = 'Hello' }")); text = @"int c = new Contact(ID = 'Hello', Date = Date.NewInstance(1,2,3), Name='y@e\mail.com') + 2"; csharp = Convert(text); - Assert.AreEqual(@"int c = new Contact { ID = 'Hello', Date = Date.NewInstance(1,2,3), Name='y@e\mail.com' } + 2", csharp); + Assert.That(csharp, Is.EqualTo(@"int c = new Contact { ID = 'Hello', Date = Date.NewInstance(1,2,3), Name='y@e\mail.com' } + 2")); text = @"int c = new Contact(ID = 'Hello', Stuff = [SELECT ID FROM DUAL]), int y = 10"; csharp = Convert(text); - Assert.AreEqual(@"int c = new Contact { ID = 'Hello', Stuff = [SELECT ID FROM DUAL] }, int y = 10", csharp); + Assert.That(csharp, Is.EqualTo(@"int c = new Contact { ID = 'Hello', Stuff = [SELECT ID FROM DUAL] }, int y = 10")); } [Test] @@ -397,19 +397,19 @@ string Convert(string x) => var text = "Property = 1"; var csharp = Convert(text); - Assert.AreEqual("Property = 1", csharp); + Assert.That(csharp, Is.EqualTo("Property = 1")); text = @"Email = 'some\'@example.com' Name = 'Hello'"; csharp = Convert(text); - Assert.AreEqual(@"Email = 'some\'@example.com', Name = 'Hello'", csharp); + Assert.That(csharp, Is.EqualTo(@"Email = 'some\'@example.com', Name = 'Hello'")); text = @"ID = 'Hello' Date = Date.NewInstance(1,2,3) Name='y@e\mail.com'"; csharp = Convert(text); - Assert.AreEqual(@"ID = 'Hello', Date = Date.NewInstance(1,2,3), Name='y@e\mail.com'", csharp); + Assert.That(csharp, Is.EqualTo(@"ID = 'Hello', Date = Date.NewInstance(1,2,3), Name='y@e\mail.com'")); text = @"ID='Hello'Date=Date.NewInstance(1,2,3)TestAll=true Value=10.12e+11Name='y@e\mail.com'"; csharp = Convert(text); - Assert.AreEqual(@"ID='Hello', Date=Date.NewInstance(1,2,3), TestAll=true, Value=10.12e+11, Name='y@e\mail.com'", csharp); + Assert.That(csharp, Is.EqualTo(@"ID='Hello', Date=Date.NewInstance(1,2,3), TestAll=true, Value=10.12e+11, Name='y@e\mail.com'")); } [Test] @@ -420,17 +420,17 @@ public void ApexInstanceOfConvertedToCSharpAndBackAgain() var text = "Property instanceof int"; var csharp = ToCSharp(text); - Assert.AreEqual("Property is int", csharp); + Assert.That(csharp, Is.EqualTo("Property is int")); var apex = ToApex(csharp); - Assert.AreEqual(text, apex); + Assert.That(apex, Is.EqualTo(text)); text = @"int a = Value instanceof Map ? 10 : 20"; csharp = ToCSharp(text); - Assert.AreEqual(@"int a = Value is Map ? 10 : 20", csharp); + Assert.That(csharp, Is.EqualTo(@"int a = Value is Map ? 10 : 20")); apex = ToApex(csharp); - Assert.AreEqual(text, apex); + Assert.That(apex, Is.EqualTo(text)); } [Test] @@ -439,17 +439,17 @@ public void ConvertTypeNames() string ToCSharp(string type) => GenericExpressionHelper.ConvertApexTypeToCSharp(type); string ToApex(string type) => GenericExpressionHelper.ConvertCSharpTypeToApex(type); - Assert.AreEqual("bool", ToCSharp(ApexKeywords.Boolean)); - Assert.AreEqual("bool", ToCSharp("boolean")); - Assert.AreEqual("bool", ToCSharp("BOOLEAN")); - Assert.AreEqual("string", ToCSharp(ApexKeywords.String)); - Assert.AreEqual("string", ToCSharp("string")); - Assert.AreEqual("int", ToCSharp(ApexKeywords.Integer)); - - Assert.AreEqual(ApexKeywords.Integer, ToApex("int")); - Assert.AreEqual(ApexKeywords.String, ToApex("string")); - Assert.AreEqual(ApexKeywords.Datetime, ToApex("Datetime")); // not sure if we convert System.DateTime to Apex.System.Datetime? - Assert.AreEqual(ApexKeywords.Time, ToApex("Time")); + Assert.That(ToCSharp(ApexKeywords.Boolean), Is.EqualTo("bool")); + Assert.That(ToCSharp("boolean"), Is.EqualTo("bool")); + Assert.That(ToCSharp("BOOLEAN"), Is.EqualTo("bool")); + Assert.That(ToCSharp(ApexKeywords.String), Is.EqualTo("string")); + Assert.That(ToCSharp("string"), Is.EqualTo("string")); + Assert.That(ToCSharp(ApexKeywords.Integer), Is.EqualTo("int")); + + Assert.That(ToApex("int"), Is.EqualTo(ApexKeywords.Integer)); + Assert.That(ToApex("string"), Is.EqualTo(ApexKeywords.String)); + Assert.That(ToApex("Datetime"), Is.EqualTo(ApexKeywords.Datetime)); + Assert.That(ToApex("Time"), Is.EqualTo(ApexKeywords.Time)); } [Test] @@ -458,8 +458,8 @@ public void ConvertTypesInExpressions() string ToCSharp(string expr) => GenericExpressionHelper.ConvertApexTypesToCSharp(expr); string ToApex(string expr) => GenericExpressionHelper.ConvertCSharpTypesToApex(expr); - Assert.AreEqual("Map", ToCSharp("Map")); - Assert.AreEqual("Map", ToApex("Map")); + Assert.That(ToCSharp("Map"), Is.EqualTo("Map")); + Assert.That(ToApex("Map"), Is.EqualTo("Map")); } [Test] @@ -468,11 +468,11 @@ public void ApexPritimiveTypesStaticMethodsAreNotConvertedToCSharp() string ToCSharp(string expr) => GenericExpressionHelper.ConvertApexTypesToCSharp(expr); string ToApex(string expr) => GenericExpressionHelper.ConvertCSharpTypesToApex(expr); - Assert.AreEqual("a = (int)b", ToCSharp("a = (Integer)b")); - Assert.AreEqual("a = Integer.valueOf(b)", ToCSharp("a = Integer.valueOf(b)")); + Assert.That(ToCSharp("a = (Integer)b"), Is.EqualTo("a = (int)b")); + Assert.That(ToCSharp("a = Integer.valueOf(b)"), Is.EqualTo("a = Integer.valueOf(b)")); - Assert.AreEqual("a = (Integer)b", ToApex("a = (int)b")); - Assert.AreEqual("a = Integer.valueOf(b)", ToApex("a = Integer.valueOf(b)")); + Assert.That(ToApex("a = (int)b"), Is.EqualTo("a = (Integer)b")); + Assert.That(ToApex("a = Integer.valueOf(b)"), Is.EqualTo("a = Integer.valueOf(b)")); } [Test] @@ -481,12 +481,12 @@ public void ApexMembersSpelledTheSameWayAsPrimitiveTypesAreNotConvertedToCSharp( string ToCSharp(string expr) => GenericExpressionHelper.ConvertApexTypesToCSharp(expr); string ToApex(string expr) => GenericExpressionHelper.ConvertCSharpTypesToApex(expr); - Assert.AreEqual("a = (Date)x", ToCSharp("a = (date)x")); - Assert.AreEqual("a = new Date(x)", ToCSharp("a = new date(x)")); - Assert.AreEqual("a = new Date(x).date()", ToCSharp("a = new Date(x).date()")); + Assert.That(ToCSharp("a = (date)x"), Is.EqualTo("a = (Date)x")); + Assert.That(ToCSharp("a = new date(x)"), Is.EqualTo("a = new Date(x)")); + Assert.That(ToCSharp("a = new Date(x).date()"), Is.EqualTo("a = new Date(x).date()")); - Assert.AreEqual("a = new Date(x)", ToApex("a = new Date(x)")); - Assert.AreEqual("a = new Date(x).date()", ToApex("a = new Date(x).date()")); + Assert.That(ToApex("a = new Date(x)"), Is.EqualTo("a = new Date(x)")); + Assert.That(ToApex("a = new Date(x).date()"), Is.EqualTo("a = new Date(x).date()")); } [Test] @@ -495,26 +495,26 @@ public void DoubleLiteralsAreConvertedToDecimalLiterals() string ToCSharp(string expr) => GenericExpressionHelper.ConvertApexDoubleLiteralsToDecimals(expr); string ToApex(string expr) => GenericExpressionHelper.ConvertCSharpDecimalLiteralsToDoubles(expr); - Assert.AreEqual("a = 123.45m", ToCSharp("a = 123.45")); - Assert.AreEqual("a = .45m", ToCSharp("a = .45")); - Assert.AreEqual("a = 1.0m", ToCSharp("a = 1.0")); - Assert.AreEqual("a123.45", ToCSharp("a123.45")); - Assert.AreEqual("a.", ToCSharp("a.")); - - Assert.AreEqual("a = 123.45", ToApex("a = 123.45m")); - Assert.AreEqual("a = .45", ToApex("a = .45M")); - Assert.AreEqual("a = 1.0", ToApex("a = 1.0m")); - Assert.AreEqual("a123.45m", ToApex("a123.45m")); - Assert.AreEqual("a.m", ToCSharp("a.m")); + Assert.That(ToCSharp("a = 123.45"), Is.EqualTo("a = 123.45m")); + Assert.That(ToCSharp("a = .45"), Is.EqualTo("a = .45m")); + Assert.That(ToCSharp("a = 1.0"), Is.EqualTo("a = 1.0m")); + Assert.That(ToCSharp("a123.45"), Is.EqualTo("a123.45")); + Assert.That(ToCSharp("a."), Is.EqualTo("a.")); + + Assert.That(ToApex("a = 123.45m"), Is.EqualTo("a = 123.45")); + Assert.That(ToApex("a = .45M"), Is.EqualTo("a = .45")); + Assert.That(ToApex("a = 1.0m"), Is.EqualTo("a = 1.0")); + Assert.That(ToApex("a123.45m"), Is.EqualTo("a123.45m")); + Assert.That(ToCSharp("a.m"), Is.EqualTo("a.m")); } [Test] public void ToCSharpStringLiteralTests() { - Assert.AreEqual(@"""hello""", @"hello".ToCSharpStringLiteral()); - Assert.AreEqual(@"""he\\llo""", @"he\llo".ToCSharpStringLiteral()); - Assert.AreEqual(@"""hel\""lo""", @"hel""lo".ToCSharpStringLiteral()); - Assert.AreEqual(@"""hel\n\r\t\vlo""", "hel\n\r\t\vlo".ToCSharpStringLiteral()); + Assert.That(@"hello".ToCSharpStringLiteral(), Is.EqualTo(@"""hello""")); + Assert.That(@"he\llo".ToCSharpStringLiteral(), Is.EqualTo(@"""he\\llo""")); + Assert.That(@"hel""lo".ToCSharpStringLiteral(), Is.EqualTo(@"""hel\""lo""")); + Assert.That("hel\n\r\t\vlo".ToCSharpStringLiteral(), Is.EqualTo(@"""hel\n\r\t\vlo""")); } } } diff --git a/ApexSharp.ApexParser.Tests/Toolbox/IEnumerableExtensionTests.cs b/ApexSharp.ApexParser.Tests/Toolbox/IEnumerableExtensionTests.cs index 1eaf00f..ffe6f9a 100644 --- a/ApexSharp.ApexParser.Tests/Toolbox/IEnumerableExtensionTests.cs +++ b/ApexSharp.ApexParser.Tests/Toolbox/IEnumerableExtensionTests.cs @@ -16,8 +16,8 @@ public void EmptyIfNullReturnsEmptyEnumerableInsteadOfNull() { int[] x = null; var enumerable = x.EmptyIfNull(); - Assert.NotNull(enumerable); - Assert.False(enumerable.Any()); + Assert.That(enumerable, Is.Not.Null); + Assert.That(enumerable.Any(), Is.False); } [Test] diff --git a/ApexSharp.ApexParser.Tests/Toolbox/ParseExtensionTests.cs b/ApexSharp.ApexParser.Tests/Toolbox/ParseExtensionTests.cs index 496c2df..9af77cb 100644 --- a/ApexSharp.ApexParser.Tests/Toolbox/ParseExtensionTests.cs +++ b/ApexSharp.ApexParser.Tests/Toolbox/ParseExtensionTests.cs @@ -28,8 +28,8 @@ public void ParseExProducesMoreDetailedExceptionMessage() { // check that the error message contains the complete invalid code line var exc = ex as ParseExceptionCustom; - Assert.NotNull(exc); - Assert.True(exc.Apexcode.Contains(errorLine)); + Assert.That(exc, Is.Not.Null); + Assert.That(exc.Apexcode.Contains(errorLine), Is.True); } } @@ -41,7 +41,7 @@ from id in Parse.Identifier(Parse.Letter, Parse.LetterOrDigit).Token(null).End() public void ForStaticParserTokenNullModifierWorksLikeOrdinaryToken() { var result = Identifier1.Parse(" \t hello123 \t\r\n "); - Assert.AreEqual("hello123", result); + Assert.That(result, Is.EqualTo("hello123")); } public IComment CommentParser { get; } = new CommentParser(); @@ -55,17 +55,17 @@ public void ForParserOwnedByICommentParserProviderTokenThisStripsOutComments() { // whitespace only var result = Identifier2.Parse(" \t hello123 \t\r\n "); - Assert.AreEqual("hello123", result); + Assert.That(result, Is.EqualTo("hello123")); // trailing comments result = Identifier2.End().Parse(" \t hello123 // what's that? "); - Assert.AreEqual("hello123", result); + Assert.That(result, Is.EqualTo("hello123")); // leading and trailing comments result = Identifier2.Parse(@" // leading comments! helloWorld // trailing comments! "); - Assert.AreEqual("helloWorld", result); + Assert.That(result, Is.EqualTo("helloWorld")); // multiple leading and trailing comments result = Identifier2.Parse(@" // leading comments! @@ -77,7 +77,7 @@ this is the second line */ // trailing comments! /* --==-- */"); - Assert.AreEqual("test321", result); + Assert.That(result, Is.EqualTo("test321")); } private Parser BreakStatement1 => @@ -90,21 +90,21 @@ public void TokenThisModifierDoesntSaveCommentsContentAutomatically() { // whitespace only var @break = BreakStatement1.Parse(" \t break; \t\r\n "); - Assert.AreEqual(0, @break.LeadingComments.Count); - Assert.AreEqual(0, @break.TrailingComments.Count); + Assert.That(@break.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(@break.TrailingComments.Count, Is.EqualTo(0)); // leading comments @break = BreakStatement1.Parse(@" // this is a break statement break;"); - Assert.AreEqual(0, @break.LeadingComments.Count); - Assert.AreEqual(0, @break.TrailingComments.Count); + Assert.That(@break.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(@break.TrailingComments.Count, Is.EqualTo(0)); // trailing comments @break = BreakStatement1.Parse(@" break /* a comment before the semicolon */; // this is ignored"); - Assert.AreEqual(0, @break.LeadingComments.Count); - Assert.AreEqual(0, @break.TrailingComments.Count); + Assert.That(@break.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(@break.TrailingComments.Count, Is.EqualTo(0)); } private Parser BreakStatement2 => @@ -121,8 +121,8 @@ public void CommentedThisModifierAllowsSavingCommentsAsNeeded() { // whitespace only var @break = BreakStatement2.Parse(" \t break; \t\r\n "); - Assert.AreEqual(0, @break.LeadingComments.Count); - Assert.AreEqual(0, @break.TrailingComments.Count); + Assert.That(@break.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(@break.TrailingComments.Count, Is.EqualTo(0)); // leading comments @break = BreakStatement2.Parse(@" @@ -130,27 +130,27 @@ public void CommentedThisModifierAllowsSavingCommentsAsNeeded() // this is a break statement break; "); - Assert.AreEqual(1, @break.LeadingComments.Count); - Assert.AreEqual("this is a break statement", @break.LeadingComments[0].Trim()); - Assert.AreEqual(0, @break.TrailingComments.Count); + Assert.That(@break.LeadingComments.Count, Is.EqualTo(1)); + Assert.That(@break.LeadingComments[0].Trim(), Is.EqualTo("this is a break statement")); + Assert.That(@break.TrailingComments.Count, Is.EqualTo(0)); // trailing comments @break = BreakStatement2.Parse(@" break /* this is ignored */; // a comment after the semicolon"); - Assert.AreEqual(0, @break.LeadingComments.Count); - Assert.AreEqual(1, @break.TrailingComments.Count); - Assert.AreEqual("a comment after the semicolon", @break.TrailingComments[0].Trim()); + Assert.That(@break.LeadingComments.Count, Is.EqualTo(0)); + Assert.That(@break.TrailingComments.Count, Is.EqualTo(1)); + Assert.That(@break.TrailingComments[0].Trim(), Is.EqualTo("a comment after the semicolon")); // both leading trailing comments @break = BreakStatement2.Parse(@" // leading1 /* leading2 */ break /* this is ignored */; // a comment after the semicolon"); - Assert.AreEqual(2, @break.LeadingComments.Count); - Assert.AreEqual("leading1", @break.LeadingComments[0].Trim()); - Assert.AreEqual("leading2", @break.LeadingComments[1].Trim()); - Assert.AreEqual(1, @break.TrailingComments.Count); - Assert.AreEqual("a comment after the semicolon", @break.TrailingComments[0].Trim()); + Assert.That(@break.LeadingComments.Count, Is.EqualTo(2)); + Assert.That(@break.LeadingComments[0].Trim(), Is.EqualTo("leading1")); + Assert.That(@break.LeadingComments[1].Trim(), Is.EqualTo("leading2")); + Assert.That(@break.TrailingComments.Count, Is.EqualTo(1)); + Assert.That(@break.TrailingComments[0].Trim(), Is.EqualTo("a comment after the semicolon")); } private Parser> IdentifierSpan => @@ -161,24 +161,24 @@ from id in Parse.Identifier(Parse.Letter, Parse.LetterOrDigit).Span().Token(this public void SourceSpanOfIdentifierReturnsProperValues() { var id = IdentifierSpan.Parse(" HelloThere "); - Assert.AreEqual(1, id.Start.Line); - Assert.AreEqual(3, id.Start.Column); - Assert.AreEqual(2, id.Start.Pos); - Assert.AreEqual(1, id.End.Line); - Assert.AreEqual(13, id.End.Column); - Assert.AreEqual(12, id.End.Pos); - Assert.AreEqual(10, id.Length); - Assert.AreEqual("HelloThere", id.Value); + Assert.That(id.Start.Line, Is.EqualTo(1)); + Assert.That(id.Start.Column, Is.EqualTo(3)); + Assert.That(id.Start.Pos, Is.EqualTo(2)); + Assert.That(id.End.Line, Is.EqualTo(1)); + Assert.That(id.End.Column, Is.EqualTo(13)); + Assert.That(id.End.Pos, Is.EqualTo(12)); + Assert.That(id.Length, Is.EqualTo(10)); + Assert.That(id.Value, Is.EqualTo("HelloThere")); id = IdentifierSpan.Parse(@" // comment /* another comment */ MyIdentifier // test"); - Assert.AreEqual(3, id.Start.Line); - Assert.AreEqual(13, id.Start.Column); - Assert.AreEqual(3, id.End.Line); - Assert.AreEqual(25, id.End.Column); - Assert.AreEqual(12, id.Length); - Assert.AreEqual("MyIdentifier", id.Value); + Assert.That(id.Start.Line, Is.EqualTo(3)); + Assert.That(id.Start.Column, Is.EqualTo(13)); + Assert.That(id.End.Line, Is.EqualTo(3)); + Assert.That(id.End.Column, Is.EqualTo(25)); + Assert.That(id.Length, Is.EqualTo(12)); + Assert.That(id.Value, Is.EqualTo("MyIdentifier")); } private Parser PreviewParserDemo => @@ -190,7 +190,7 @@ from testMethod in Parse.String("testMethod").Token().Text() public void PreviewVersionOfAParserDoesntConsumeAnyInput() { var testMethod = PreviewParserDemo.Parse(" testMethod "); - Assert.AreEqual("testMethod", testMethod); + Assert.That(testMethod, Is.EqualTo("testMethod")); } private Parser> Identifier4 => @@ -202,28 +202,28 @@ public void CommentedParserStripsOutLeadingCommentsAndSingleTrailingCommentThatS { // whitespace only var result = Identifier4.Parse(" \t hello123 \t\r\n "); - Assert.AreEqual("hello123", result.Value); - Assert.False(result.LeadingComments.Any()); - Assert.False(result.TrailingComments.Any()); + Assert.That(result.Value, Is.EqualTo("hello123")); + Assert.That(result.LeadingComments.Any(), Is.False); + Assert.That(result.TrailingComments.Any(), Is.False); // trailing comments result = Identifier4.End().Parse(" \t hello123 // what's that? "); - Assert.AreEqual("hello123", result.Value); - Assert.False(result.LeadingComments.Any()); - Assert.True(result.TrailingComments.Any()); - Assert.AreEqual("what's that?", result.TrailingComments.First().Trim()); + Assert.That(result.Value, Is.EqualTo("hello123")); + Assert.That(result.LeadingComments.Any(), Is.False); + Assert.That(result.TrailingComments.Any(), Is.True); + Assert.That(result.TrailingComments.First().Trim(), Is.EqualTo("what's that?")); // leading and trailing comments result = Identifier4.Parse(@" // leading comments! /* more leading comments! */ helloWorld // trailing comments! // more trailing comments! (that don't belong to the parsed value)"); - Assert.AreEqual("helloWorld", result.Value); - Assert.AreEqual(2, result.LeadingComments.Count()); - Assert.AreEqual("leading comments!", result.LeadingComments.First().Trim()); - Assert.AreEqual("more leading comments!", result.LeadingComments.Last().Trim()); - Assert.AreEqual(1, result.TrailingComments.Count()); - Assert.AreEqual("trailing comments!", result.TrailingComments.First().Trim()); + Assert.That(result.Value, Is.EqualTo("helloWorld")); + Assert.That(result.LeadingComments.Count(), Is.EqualTo(2)); + Assert.That(result.LeadingComments.First().Trim(), Is.EqualTo("leading comments!")); + Assert.That(result.LeadingComments.Last().Trim(), Is.EqualTo("more leading comments!")); + Assert.That(result.TrailingComments.Count(), Is.EqualTo(1)); + Assert.That(result.TrailingComments.First().Trim(), Is.EqualTo("trailing comments!")); // multiple leading and trailing comments result = Identifier4.Parse(@" // leading comments! @@ -235,12 +235,12 @@ this is the second line */ // trailing comments! /* --==-- */"); - Assert.AreEqual("test321", result.Value); - Assert.AreEqual(2, result.LeadingComments.Count()); - Assert.AreEqual("leading comments!", result.LeadingComments.First().Trim()); - Assert.True(result.LeadingComments.Last().Trim().StartsWith("multiline leading comments")); - Assert.True(result.LeadingComments.Last().Trim().EndsWith("this is the second line")); - Assert.False(result.TrailingComments.Any()); + Assert.That(result.Value, Is.EqualTo("test321")); + Assert.That(result.LeadingComments.Count(), Is.EqualTo(2)); + Assert.That(result.LeadingComments.First().Trim(), Is.EqualTo("leading comments!")); + Assert.That(result.LeadingComments.Last().Trim().StartsWith("multiline leading comments"), Is.True); + Assert.That(result.LeadingComments.Last().Trim().EndsWith("this is the second line"), Is.True); + Assert.That(result.TrailingComments.Any(), Is.False); } [Test] @@ -250,30 +250,30 @@ public void CommentedParserAcceptsMultipleTrailingCommentsAsLongAsTheyStartOnThe var result = Identifier4.Parse(" \t hello123 /* one */ /* two */ /* " + @" three */ // this is not a trailing comment // neither this"); - Assert.AreEqual("hello123", result.Value); - Assert.False(result.LeadingComments.Any()); - Assert.True(result.TrailingComments.Any()); + Assert.That(result.Value, Is.EqualTo("hello123")); + Assert.That(result.LeadingComments.Any(), Is.False); + Assert.That(result.TrailingComments.Any(), Is.True); var trailing = result.TrailingComments.ToArray(); - Assert.AreEqual(3, trailing.Length); - Assert.AreEqual("one", trailing[0].Trim()); - Assert.AreEqual("two", trailing[1].Trim()); - Assert.AreEqual("three", trailing[2].Trim()); + Assert.That(trailing.Length, Is.EqualTo(3)); + Assert.That(trailing[0].Trim(), Is.EqualTo("one")); + Assert.That(trailing[1].Trim(), Is.EqualTo("two")); + Assert.That(trailing[2].Trim(), Is.EqualTo("three")); // leading and trailing comments result = Identifier4.Parse(@" // leading comments! /* more leading comments! */ helloWorld /* one*/ // two! // more trailing comments! (that don't belong to the parsed value)"); - Assert.AreEqual("helloWorld", result.Value); - Assert.AreEqual(2, result.LeadingComments.Count()); - Assert.AreEqual("leading comments!", result.LeadingComments.First().Trim()); - Assert.AreEqual("more leading comments!", result.LeadingComments.Last().Trim()); + Assert.That(result.Value, Is.EqualTo("helloWorld")); + Assert.That(result.LeadingComments.Count(), Is.EqualTo(2)); + Assert.That(result.LeadingComments.First().Trim(), Is.EqualTo("leading comments!")); + Assert.That(result.LeadingComments.Last().Trim(), Is.EqualTo("more leading comments!")); trailing = result.TrailingComments.ToArray(); - Assert.AreEqual(2, trailing.Length); - Assert.AreEqual("one", trailing[0].Trim()); - Assert.AreEqual("two!", trailing[1].Trim()); + Assert.That(trailing.Length, Is.EqualTo(2)); + Assert.That(trailing[0].Trim(), Is.EqualTo("one")); + Assert.That(trailing[1].Trim(), Is.EqualTo("two!")); } private Parser OptionalTestParser => @@ -292,21 +292,21 @@ from method in Parse.String("method").Text() public void XOptionalParserFailsIfSomeInputIsConsumed() { var result = OptionalTestParser.Parse("testmethod"); - Assert.AreEqual("testmethod", result); + Assert.That(result, Is.EqualTo("testmethod")); XOptionalTestParser.Parse("testmethod"); - Assert.AreEqual("testmethod", result); + Assert.That(result, Is.EqualTo("testmethod")); result = OptionalTestParser.Parse("method"); - Assert.AreEqual("method", result); + Assert.That(result, Is.EqualTo("method")); result = XOptionalTestParser.Parse("method"); - Assert.AreEqual("method", result); + Assert.That(result, Is.EqualTo("method")); result = OptionalTestParser.Parse("tmethod"); - Assert.AreEqual("tmethod", result); + Assert.That(result, Is.EqualTo("tmethod")); - Assert.Throws(() => XOptionalTestParser.Parse("tmethod")); + Assert.That(() => XOptionalTestParser.Parse("tmethod"), Throws.TypeOf()); } private Parser DummyNewExpressionTestParser(bool failByDefault) => @@ -324,15 +324,15 @@ from n in DummyNewExpressionTestParser(true) public void PrevCharParserTests() { var result = DummyNewExpressionTestParserWithLeadingChar.Parse(".new Ex"); - Assert.AreEqual("new Ex", result); + Assert.That(result, Is.EqualTo("new Ex")); result = DummyNewExpressionTestParserWithLeadingChar.Parse("?new Ex "); - Assert.AreEqual("new Ex", result); + Assert.That(result, Is.EqualTo("new Ex")); - Assert.Throws(() => DummyNewExpressionTestParserWithLeadingChar.Parse("xnew Ex")); - Assert.Throws(() => DummyNewExpressionTestParserWithLeadingChar.Parse("1new Ex")); - Assert.Throws(() => DummyNewExpressionTestParser(true).Parse("new Ex")); - Assert.DoesNotThrow(() => DummyNewExpressionTestParser(false).Parse("new Ex")); + Assert.That(() => DummyNewExpressionTestParserWithLeadingChar.Parse("xnew Ex"), Throws.TypeOf()); + Assert.That(() => DummyNewExpressionTestParserWithLeadingChar.Parse("1new Ex"), Throws.TypeOf()); + Assert.That(() => DummyNewExpressionTestParser(true).Parse("new Ex"), Throws.TypeOf()); + Assert.That(() => DummyNewExpressionTestParser(false).Parse("new Ex"), Throws.Nothing); } } } diff --git a/ApexSharp.ApexParser.Tests/Toolbox/SmartEnumerableTests.cs b/ApexSharp.ApexParser.Tests/Toolbox/SmartEnumerableTests.cs index 0de9087..7f05085 100644 --- a/ApexSharp.ApexParser.Tests/Toolbox/SmartEnumerableTests.cs +++ b/ApexSharp.ApexParser.Tests/Toolbox/SmartEnumerableTests.cs @@ -15,91 +15,91 @@ public class SmartEnumerableTests public void SmartEnumerableForNullDoesntThrowExceptions() { var enumerable = default(string[]); - Assert.DoesNotThrow(() => + Assert.That(() => { var smart = enumerable.AsSmartEnumerable(); - Assert.NotNull(smart); - Assert.IsFalse(smart.Any()); + Assert.That(smart, Is.Not.Null); + Assert.That(smart.Any(), Is.False); smart = enumerable.AsSmart(); - Assert.NotNull(smart); - Assert.IsFalse(smart.Any()); - }); + Assert.That(smart, Is.Not.Null); + Assert.That(smart.Any(), Is.False); + }, Throws.Nothing); } [Test] public void SmartEnumerableWorksForEmptyCollection() { var enumerable = new string[0]; - Assert.DoesNotThrow(() => + Assert.That(() => { var smart = enumerable.AsSmartEnumerable(); - Assert.NotNull(smart); - Assert.IsFalse(smart.Any()); + Assert.That(smart, Is.Not.Null); + Assert.That(smart.Any(), Is.False); smart = enumerable.AsSmart(); - Assert.NotNull(smart); - Assert.IsFalse(smart.Any()); - }); + Assert.That(smart, Is.Not.Null); + Assert.That(smart.Any(), Is.False); + }, Throws.Nothing); } [Test] public void SmartEnumerableWorksForCollectionWithASingleElement() { var enumerable = new string[] { "Hello" }; - Assert.DoesNotThrow(() => + Assert.That(() => { var smart = enumerable.AsSmartEnumerable(); - Assert.NotNull(smart); - Assert.IsTrue(smart.Any()); - Assert.AreEqual(1, smart.Count()); + Assert.That(smart, Is.Not.Null); + Assert.That(smart.Any(), Is.True); + Assert.That(smart.Count(), Is.EqualTo(1)); foreach (var item in smart) { - Assert.IsTrue(item.IsFirst); - Assert.IsTrue(item.IsLast); - Assert.AreEqual(0, item.Index); - Assert.AreEqual("Hello", item.Value); + Assert.That(item.IsFirst, Is.True); + Assert.That(item.IsLast, Is.True); + Assert.That(item.Index, Is.EqualTo(0)); + Assert.That(item.Value, Is.EqualTo("Hello")); } - }); + }, Throws.Nothing); } [Test] public void SmartEnumerableWorksForCollectionWithMultipleElement() { var enumerable = new string[] { "Hello", "Cruel", "World" }; - Assert.DoesNotThrow(() => + Assert.That(() => { var smart = enumerable.AsSmartEnumerable(); - Assert.NotNull(smart); - Assert.IsTrue(smart.Any()); - Assert.AreEqual(3, smart.Count()); + Assert.That(smart, Is.Not.Null); + Assert.That(smart.Any(), Is.True); + Assert.That(smart.Count(), Is.EqualTo(3)); var items = smart.ToArray(); var enumerator = smart.GetEnumerator(); - Assert.IsTrue(enumerator.MoveNext()); + Assert.That(enumerator.MoveNext(), Is.True); var item = enumerator.Current; - Assert.AreEqual("Hello", item.Value); - Assert.AreEqual(0, item.Index); - Assert.IsTrue(item.IsFirst); - Assert.IsFalse(item.IsLast); - Assert.IsTrue(enumerator.MoveNext()); + Assert.That(item.Value, Is.EqualTo("Hello")); + Assert.That(item.Index, Is.EqualTo(0)); + Assert.That(item.IsFirst, Is.True); + Assert.That(item.IsLast, Is.False); + Assert.That(enumerator.MoveNext(), Is.True); item = enumerator.Current; - Assert.AreEqual("Cruel", item.Value); - Assert.AreEqual(1, item.Index); - Assert.IsFalse(item.IsFirst); - Assert.IsFalse(item.IsLast); - Assert.IsTrue(enumerator.MoveNext()); + Assert.That(item.Value, Is.EqualTo("Cruel")); + Assert.That(item.Index, Is.EqualTo(1)); + Assert.That(item.IsFirst, Is.False); + Assert.That(item.IsLast, Is.False); + Assert.That(enumerator.MoveNext(), Is.True); item = enumerator.Current; - Assert.AreEqual("World", item.Value); - Assert.AreEqual(2, item.Index); - Assert.IsFalse(item.IsFirst); - Assert.IsTrue(item.IsLast); - Assert.IsFalse(enumerator.MoveNext()); - }); + Assert.That(item.Value, Is.EqualTo("World")); + Assert.That(item.Index, Is.EqualTo(2)); + Assert.That(item.IsFirst, Is.False); + Assert.That(item.IsLast, Is.True); + Assert.That(enumerator.MoveNext(), Is.False); + }, Throws.Nothing); } } } diff --git a/ApexSharp.ApexParser.Tests/Visitors/ApexGeneratorTests.cs b/ApexSharp.ApexParser.Tests/Visitors/ApexGeneratorTests.cs index df9bf18..2520672 100644 --- a/ApexSharp.ApexParser.Tests/Visitors/ApexGeneratorTests.cs +++ b/ApexSharp.ApexParser.Tests/Visitors/ApexGeneratorTests.cs @@ -94,10 +94,10 @@ public void EnumDeclarationIsGenerated() public void ApexTypesAreSupported() { var apexVoid = new TypeSyntax(ApexKeywords.Void); - Assert.AreEqual("void", apexVoid.ToApex()); + Assert.That(apexVoid.ToApex(), Is.EqualTo("void")); var apexContact = new TypeSyntax("MyApp", "Dto", "Contact"); - Assert.AreEqual("MyApp.Dto.Contact", apexContact.ToApex()); + Assert.That(apexContact.ToApex(), Is.EqualTo("MyApp.Dto.Contact")); var apexList = new TypeSyntax("List") { @@ -107,10 +107,10 @@ public void ApexTypesAreSupported() }, }; - Assert.AreEqual("List", apexList.ToApex()); + Assert.That(apexList.ToApex(), Is.EqualTo("List")); var apexArray = new TypeSyntax("String") { IsArray = true }; - Assert.AreEqual("String[]", apexArray.ToApex()); + Assert.That(apexArray.ToApex(), Is.EqualTo("String[]")); } [Test] @@ -177,7 +177,7 @@ public Sample(int x, int y) public void UnknownGenericStatementIsEmittedAsIs() { var st = new StatementSyntax("UnknownGenericStatement()"); - Assert.AreEqual("UnknownGenericStatement();", st.ToApex().Trim()); + Assert.That(st.ToApex().Trim(), Is.EqualTo("UnknownGenericStatement();")); } [Test] @@ -1280,8 +1280,8 @@ void soql() { }"; var formatted = ApexSharpParser.IndentApex(apex); - Assert.IsFalse(formatted.Contains("trigger new")); - Assert.IsFalse(formatted.Contains("GROUPBY")); + Assert.That(formatted.Contains("trigger new"), Is.False); + Assert.That(formatted.Contains("GROUPBY"), Is.False); } } } diff --git a/ApexSharp.ApexParser.Tests/Visitors/ApexSyntaxBuilderTests.cs b/ApexSharp.ApexParser.Tests/Visitors/ApexSyntaxBuilderTests.cs index 32f3bf3..9582581 100644 --- a/ApexSharp.ApexParser.Tests/Visitors/ApexSyntaxBuilderTests.cs +++ b/ApexSharp.ApexParser.Tests/Visitors/ApexSyntaxBuilderTests.cs @@ -24,7 +24,7 @@ static string nows(string s) => NoWhitespaceRegex.Replace(s, string.Empty); var nodeToApex = node.ToApex(); - Assert.AreEqual(nows(expected), nows(nodeToApex)); + Assert.That(nows(nodeToApex), Is.EqualTo(nows(expected))); CompareLineByLine(nodeToApex, ApexSharpParser.IndentApex(expected)); } @@ -34,7 +34,7 @@ protected void Check(string csharpUnit, params string[] apexClasses) var apexNodes = ApexSyntaxBuilder.GetApexSyntaxNodes(csharpNode); Assert.Multiple(() => { - Assert.AreEqual(apexClasses.Length, apexNodes.Count); + Assert.That(apexNodes.Count, Is.EqualTo(apexClasses.Length)); foreach (var apexItem in apexNodes.Zip(apexClasses, (node, text) => new { node, text })) { Check(apexItem.node, apexItem.text); @@ -46,8 +46,8 @@ protected void Check(string csharpUnit, params string[] apexClasses) public void ApexBuilderForNullReturnsEmptyListOfApexSyntaxTrees() { var nodes = ApexSyntaxBuilder.GetApexSyntaxNodes(null); - Assert.IsNotNull(nodes); - Assert.IsFalse(nodes.Any()); + Assert.That(nodes, Is.Not.Null); + Assert.That(nodes.Any(), Is.False); } [Test] @@ -56,12 +56,12 @@ public void EmptyClassIsGenerated() var csharp = "class Test {}"; var cs = CSharpToApexHelpers.ParseText(csharp); var apex = ApexSyntaxBuilder.GetApexSyntaxNodes(cs); - Assert.NotNull(apex); - Assert.AreEqual(1, apex.Count); + Assert.That(apex, Is.Not.Null); + Assert.That(apex.Count, Is.EqualTo(1)); var cd = apex.OfType().FirstOrDefault(); - Assert.NotNull(cd); - Assert.AreEqual("Test", cd.Identifier); + Assert.That(cd, Is.Not.Null); + Assert.That(cd.Identifier, Is.EqualTo("Test")); Check(csharp, "class Test {}"); } @@ -396,8 +396,8 @@ public void CommentOutNoApexCode() { var builder = new ApexSyntaxBuilder(); var code = builder.CommentOutNoApexCode("int x;"); - Assert.AreEqual(1, code.Count); - Assert.AreEqual(":NoApex int x;", code[0]); + Assert.That(code.Count, Is.EqualTo(1)); + Assert.That(code[0], Is.EqualTo(":NoApex int x;")); code = builder.CommentOutNoApexCode(@"[Test] public void CommentOutNoApexCode() @@ -406,13 +406,13 @@ public void CommentOutNoApexCode() var code = builder.CommentOutNoApexCode(); }"); - Assert.AreEqual(6, code.Count); - Assert.AreEqual(":NoApex [Test]", code[0]); - Assert.AreEqual(":NoApex public void CommentOutNoApexCode()", code[1]); - Assert.AreEqual(":NoApex {", code[2]); - Assert.AreEqual(":NoApex var builder = new ApexSyntaxBuilder();", code[3]); - Assert.AreEqual(":NoApex var code = builder.CommentOutNoApexCode();", code[4]); - Assert.AreEqual(":NoApex }", code[5]); + Assert.That(code.Count, Is.EqualTo(6)); + Assert.That(code[0], Is.EqualTo(":NoApex [Test]")); + Assert.That(code[1], Is.EqualTo(":NoApex public void CommentOutNoApexCode()")); + Assert.That(code[2], Is.EqualTo(":NoApex {")); + Assert.That(code[3], Is.EqualTo(":NoApex var builder = new ApexSyntaxBuilder();")); + Assert.That(code[4], Is.EqualTo(":NoApex var code = builder.CommentOutNoApexCode();")); + Assert.That(code[5], Is.EqualTo(":NoApex }")); } [Test] @@ -483,7 +483,7 @@ public static void UpdateContacts(List contacts) }"; var apexClasses = CSharpToApexHelpers.ConvertToApex(csharpCode); - Assert.AreEqual(1, apexClasses.Length); + Assert.That(apexClasses.Length, Is.EqualTo(1)); CompareLineByLine(apexClasses[0], @"public class Demo { @@ -596,7 +596,7 @@ public static void UpdatePhoneTestNotValidEmail() }"; var apexClasses = CSharpToApexHelpers.ConvertToApex(csharpCode); - Assert.AreEqual(1, apexClasses.Length); + Assert.That(apexClasses.Length, Is.EqualTo(1)); CompareLineByLine(apexClasses[0], @"@IsTest public class DemoTest diff --git a/ApexSharp.ApexParser.Tests/Visitors/CSharpGeneratorTests.cs b/ApexSharp.ApexParser.Tests/Visitors/CSharpGeneratorTests.cs index f64e4a0..f27381f 100644 --- a/ApexSharp.ApexParser.Tests/Visitors/CSharpGeneratorTests.cs +++ b/ApexSharp.ApexParser.Tests/Visitors/CSharpGeneratorTests.cs @@ -206,10 +206,10 @@ class TestClass public void ApexTypesGetConvertedToCSharpTypes() { var apexVoid = new TypeSyntax(ApexKeywords.Void); - Assert.AreEqual("void", apexVoid.ToCSharp()); + Assert.That(apexVoid.ToCSharp(), Is.EqualTo("void")); var apexContact = new TypeSyntax("MyApp", "Dto", "Contact"); - Assert.AreEqual("MyApp.Dto.Contact", apexContact.ToCSharp()); + Assert.That(apexContact.ToCSharp(), Is.EqualTo("MyApp.Dto.Contact")); var apexList = new TypeSyntax("List") { @@ -219,10 +219,10 @@ public void ApexTypesGetConvertedToCSharpTypes() } }; - Assert.AreEqual("List", apexList.ToCSharp()); + Assert.That(apexList.ToCSharp(), Is.EqualTo("List")); var apexArray = new TypeSyntax("String") { IsArray = true }; - Assert.AreEqual("string[]", apexArray.ToCSharp()); + Assert.That(apexArray.ToCSharp(), Is.EqualTo("string[]")); } [Test] @@ -289,7 +289,7 @@ public Sample(int x, int y) public void UnknownGenericStatementIsEmittedAsIs() { var st = new StatementSyntax("UnknownGenericStatement()"); - Assert.AreEqual("UnknownGenericStatement();", st.ToCSharp().Trim()); + Assert.That(st.ToCSharp().Trim(), Is.EqualTo("UnknownGenericStatement();")); } [Test] @@ -638,10 +638,10 @@ public void ApexTestAnnotationsConvertedToNUnitAttributes() { var annotation = new AnnotationSyntax { Identifier = ApexKeywords.IsTest }; var attribute = CSharpCodeGenerator.ConvertUnitTestAnnotation(annotation, new ClassDeclarationSyntax()); - Assert.AreEqual("TestFixture", attribute.Identifier); + Assert.That(attribute.Identifier, Is.EqualTo("TestFixture")); attribute = CSharpCodeGenerator.ConvertUnitTestAnnotation(annotation, new MethodDeclarationSyntax()); - Assert.AreEqual("Test", attribute.Identifier); + Assert.That(attribute.Identifier, Is.EqualTo("Test")); } [Test] @@ -1027,8 +1027,8 @@ public void BuiltinApexTypesConvertedToCSharpTypes() string Normalize(string id) => new CSharpCodeGenerator().NormalizeTypeName(id); - Assert.AreEqual("string", Normalize(ApexKeywords.String)); - Assert.AreEqual("bool", Normalize(ApexKeywords.Boolean)); + Assert.That(Normalize(ApexKeywords.String), Is.EqualTo("string")); + Assert.That(Normalize(ApexKeywords.Boolean), Is.EqualTo("bool")); // not anymore: Apex.System.Datetime is used instead of System.DateTime //Assert.AreEqual(nameof(DateTime), Normalize(ApexKeywords.Datetime)); @@ -1486,10 +1486,10 @@ public void LocalizeSObjectsNamespaceIgnoresInvalidParameters() { Func, string, IEnumerable> loc = CSharpCodeGenerator.LocalizeSObjectNamespace; - Assert.AreEqual(new string[0], loc(null, null)); - Assert.AreEqual(new string[0], loc(new string[0], null)); - Assert.AreEqual(new[] { "Hello" }, loc(new[] { "Hello" }, null)); - Assert.AreEqual(new[] { "SObjects" }, loc(new[] { "SObjects" }, null)); + Assert.That(loc(null, null), Is.EqualTo(new string[0])); + Assert.That(loc(new string[0], null), Is.EqualTo(new string[0])); + Assert.That(loc(new[] { "Hello" }, null), Is.EqualTo(new[] { "Hello" })); + Assert.That(loc(new[] { "SObjects" }, null), Is.EqualTo(new[] { "SObjects" })); } [Test] @@ -1497,11 +1497,11 @@ public void LocalizeSObjectsNamespaceAppendsTheFirstPartOfTheNamespaceBeforeTheS { Func, string, IEnumerable> loc = CSharpCodeGenerator.LocalizeSObjectNamespace; - Assert.AreEqual(new string[0], loc(null, "Hello")); - Assert.AreEqual(new[] { "World" }, loc(new[] { "World" }, "Hello")); - Assert.AreEqual(new[] { "Hello.SObjects" }, loc(new[] { "SObjects" }, "Hello")); - Assert.AreEqual(new[] { "Something", "Hello.SObjects" }, loc(new[] { "Something", "SObjects" }, "Hello")); - Assert.AreEqual(new[] { "Something", "Hello.SObjects" }, loc(new[] { "Something", "SObjects" }, "Hello.There")); + Assert.That(loc(null, "Hello"), Is.EqualTo(new string[0])); + Assert.That(loc(new[] { "World" }, "Hello"), Is.EqualTo(new[] { "World" })); + Assert.That(loc(new[] { "SObjects" }, "Hello"), Is.EqualTo(new[] { "Hello.SObjects" })); + Assert.That(loc(new[] { "Something", "SObjects" }, "Hello"), Is.EqualTo(new[] { "Something", "Hello.SObjects" })); + Assert.That(loc(new[] { "Something", "SObjects" }, "Hello.There"), Is.EqualTo(new[] { "Something", "Hello.SObjects" })); } [Test] @@ -1574,25 +1574,25 @@ public void GetMissingConstructorsForExceptionClass() var gen = new CSharpCodeGenerator(); var cls = new ClassDeclarationSyntax { Identifier = "MyEx" }; var all = gen.GetExceptionConstructors(cls); - Assert.AreEqual(4, all.Count()); + Assert.That(all.Count(), Is.EqualTo(4)); var missing = gen.GetMissingConstructors(null, all); - Assert.AreEqual(4, missing.Count()); + Assert.That(missing.Count(), Is.EqualTo(4)); missing = gen.GetMissingConstructors(null, null); - Assert.AreEqual(0, missing.Count()); + Assert.That(missing.Count(), Is.EqualTo(0)); missing = gen.GetMissingConstructors(Enumerable.Empty(), all); - Assert.AreEqual(4, missing.Count()); + Assert.That(missing.Count(), Is.EqualTo(4)); missing = gen.GetMissingConstructors(all, all); - Assert.AreEqual(0, missing.Count()); + Assert.That(missing.Count(), Is.EqualTo(0)); missing = gen.GetMissingConstructors(all.Skip(1), all); - Assert.AreEqual(1, missing.Count()); + Assert.That(missing.Count(), Is.EqualTo(1)); missing = gen.GetMissingConstructors(all.Skip(2).Take(1), all); - Assert.AreEqual(3, missing.Count()); + Assert.That(missing.Count(), Is.EqualTo(3)); } [Test] @@ -1703,7 +1703,7 @@ static void testCSVReader1() ".Replace("`", "\"")); var csharp = apex.ToCSharp(); - Assert.NotNull(csharp); + Assert.That(csharp, Is.Not.Null); } } } diff --git a/ApexSharp.ApexParser.Tests/Visitors/SoqlExtractorTests.cs b/ApexSharp.ApexParser.Tests/Visitors/SoqlExtractorTests.cs index d64517c..71f68ed 100644 --- a/ApexSharp.ApexParser.Tests/Visitors/SoqlExtractorTests.cs +++ b/ApexSharp.ApexParser.Tests/Visitors/SoqlExtractorTests.cs @@ -16,7 +16,7 @@ public class SoqlExtractorTests public void SoqlExtractorExtractsAllSoqlDemo2Queries() { var queries = SoqlExtractor.ExtractAllQueries(SoqlDemo2); - Assert.AreEqual(23, queries.Length); + Assert.That(queries.Length, Is.EqualTo(23)); } } } diff --git a/ApexSharp.ApexParser/ApexSharp.ApexParser.csproj b/ApexSharp.ApexParser/ApexSharp.ApexParser.csproj index afaa691..5aa5ebb 100644 --- a/ApexSharp.ApexParser/ApexSharp.ApexParser.csproj +++ b/ApexSharp.ApexParser/ApexSharp.ApexParser.csproj @@ -1,7 +1,7 @@ - net5.0 + net10.0 diff --git a/ApexSharp.ApexToCSharp/ApexSharp.ApexToCSharp.csproj b/ApexSharp.ApexToCSharp/ApexSharp.ApexToCSharp.csproj index 4880755..c3780b9 100644 --- a/ApexSharp.ApexToCSharp/ApexSharp.ApexToCSharp.csproj +++ b/ApexSharp.ApexToCSharp/ApexSharp.ApexToCSharp.csproj @@ -1,7 +1,7 @@ - net5.0 + net10.0 diff --git a/ApexSharp.CSharpToApex/ApexSharp.CSharpToApex.csproj b/ApexSharp.CSharpToApex/ApexSharp.CSharpToApex.csproj index a44d8a6..5b36fe3 100644 --- a/ApexSharp.CSharpToApex/ApexSharp.CSharpToApex.csproj +++ b/ApexSharp.CSharpToApex/ApexSharp.CSharpToApex.csproj @@ -1,7 +1,7 @@ - net5.0 + net10.0