From fba0dbae8dd398ccb5ea248900f7653c9f69e488 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Sat, 2 Dec 2023 13:38:55 +0100 Subject: [PATCH] Migrate to NUnit 4 (#3132) * Migrate to NUnit 4 based on https://docs.nunit.org/articles/nunit/release-notes/Nunit4.0-MigrationGuide.html. Needed fix for https://github.com/nunit/nunit/issues/4564 * Test 4.1.0-adev.1 from NUnit MyGet feed (works locally in VS) * Update to bugfix version adev.2 (works on GH) * NUnit 4.0.1 final --- Directory.Packages.props | 3 +- .../CorrectnessTestRunner.cs | 4 +- ICSharpCode.Decompiler.Tests/DataFlowTest.cs | 8 +- .../DisassemblerPrettyTestRunner.cs | 2 +- .../Helpers/Tester.VB.cs | 2 +- .../Helpers/Tester.cs | 14 +- .../ICSharpCode.Decompiler.Tests.csproj | 2 +- .../ILPrettyTestRunner.cs | 4 +- .../Output/CSharpAmbienceTests.cs | 38 +- .../Output/InsertParenthesesVisitorTests.cs | 108 +- .../PdbGenerationTestRunner.cs | 10 +- .../PrettyTestRunner.cs | 2 +- .../ProjectDecompiler/TargetFrameworkTests.cs | 14 +- .../RoundtripAssembly.cs | 2 +- .../Semantics/ConversionTests.cs | 789 +++++----- .../Semantics/ExplicitConversionTest.cs | 358 ++--- .../Semantics/OverloadResolutionTests.cs | 106 +- .../TypeSystem/ReflectionHelperTests.cs | 73 +- .../TypeSystem/TypeSystemLoaderTests.cs | 1263 ++++++++--------- .../UglyTestRunner.cs | 2 +- .../Util/BitSetTests.cs | 28 +- .../Util/FileUtilityTests.cs | 154 +- .../Util/IntervalTests.cs | 62 +- .../Util/LongSetTests.cs | 70 +- .../Util/ResourceReaderWriterTests.cs | 40 +- .../VBPrettyTestRunner.cs | 4 +- ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs | 2 +- .../ILSpy.BamlDecompiler.Tests.csproj | 2 +- .../MemberImplementsInterfaceAnalyzerTests.cs | 22 +- .../Analyzers/MethodUsesAnalyzerTests.cs | 8 +- .../Analyzers/TypeUsedByAnalyzerTests.cs | 6 +- ILSpy.Tests/ILSpy.Tests.csproj | 2 +- NuGet.config | 2 +- 33 files changed, 1582 insertions(+), 1624 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6e84fea885..63d680b860 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,6 +9,7 @@ + @@ -29,7 +30,7 @@ - + diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index ed4a3f2bb2..5246e5d27b 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -46,7 +46,7 @@ public void AllFilesHaveTests() if (file.Extension == ".txt" || file.Extension == ".exe" || file.Extension == ".config") continue; var testName = Path.GetFileNameWithoutExtension(file.Name); - Assert.Contains(testName, testNames); + Assert.That(testNames, Has.Member(testName)); } } @@ -486,7 +486,7 @@ async Task RunIL(string testFileName, CompilerOptions options = CompilerOptions. bool optionsForce32Bit = options.HasFlag(CompilerOptions.Force32Bit); bool asmOptionsForce32Bit = asmOptions.HasFlag(AssemblerOptions.Force32Bit); - Assert.AreEqual(optionsForce32Bit, asmOptionsForce32Bit, "Inconsistent architecture."); + Assert.That(asmOptionsForce32Bit, Is.EqualTo(optionsForce32Bit), "Inconsistent architecture."); try { diff --git a/ICSharpCode.Decompiler.Tests/DataFlowTest.cs b/ICSharpCode.Decompiler.Tests/DataFlowTest.cs index cfe14be750..7a1c200fa9 100644 --- a/ICSharpCode.Decompiler.Tests/DataFlowTest.cs +++ b/ICSharpCode.Decompiler.Tests/DataFlowTest.cs @@ -45,11 +45,11 @@ public RDTest(ILFunction f, ILVariable v) : base(f, _ => true, CancellationToken protected internal override void VisitTryFinally(TryFinally inst) { - Assert.IsTrue(IsPotentiallyUninitialized(state, v)); + Assert.That(IsPotentiallyUninitialized(state, v)); base.VisitTryFinally(inst); - Assert.IsTrue(state.IsReachable); - Assert.AreEqual(1, GetStores(state, v).Count()); - Assert.IsFalse(IsPotentiallyUninitialized(state, v)); + Assert.That(state.IsReachable); + Assert.That(GetStores(state, v).Count(), Is.EqualTo(1)); + Assert.That(!IsPotentiallyUninitialized(state, v)); } } diff --git a/ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs index 9636facc1c..9fa9e7e855 100644 --- a/ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs @@ -47,7 +47,7 @@ public void AllFilesHaveTests() if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase)) { var testName = file.Name.Split('.')[0]; - Assert.Contains(testName, testNames); + Assert.That(testNames, Has.Member(testName)); } } } diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs index 2c84b6180e..6b8e403e37 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs @@ -133,7 +133,7 @@ public static async Task CompileVB(string sourceFileName, Compi { Console.WriteLine("errors:" + Environment.NewLine + result.StandardError); } - Assert.AreEqual(0, result.ExitCode, "vbc failed"); + Assert.That(result.ExitCode, Is.EqualTo(0), "vbc failed"); return results; } diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs index b8e4bdf82d..ecbcf5c1b7 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs @@ -198,7 +198,7 @@ public static async Task AssembleIL(string sourceFileName, AssemblerOpti { Console.WriteLine("errors:" + Environment.NewLine + result.StandardError); } - Assert.AreEqual(0, result.ExitCode, "ilasm failed"); + Assert.That(result.ExitCode, Is.EqualTo(0), "ilasm failed"); return outputFile; } @@ -251,7 +251,7 @@ public static async Task Disassemble(string sourceFileName, string outpu { Console.WriteLine("errors:" + Environment.NewLine + result.StandardError); } - Assert.AreEqual(0, result.ExitCode, "ildasm failed"); + Assert.That(result.ExitCode, Is.EqualTo(0), "ildasm failed"); // Unlike the .imagebase directive (which is a fixed value when compiling with /deterministic), // the image base comment still varies... ildasm putting a random number here? @@ -520,7 +520,7 @@ public static async Task CompileCSharp(string sourceFileName, C Console.WriteLine("errors:" + Environment.NewLine + result.StandardError); } - Assert.AreEqual(0, result.ExitCode, "csc failed"); + Assert.That(result.ExitCode, Is.EqualTo(0), "csc failed"); return results; } @@ -582,7 +582,7 @@ public static async Task CompileCSharp(string sourceFileName, C { Console.WriteLine("errors:" + Environment.NewLine + result.StandardError); } - Assert.AreEqual(0, result.ExitCode, "mcs failed"); + Assert.That(result.ExitCode, Is.EqualTo(0), "mcs failed"); return results; } @@ -764,8 +764,8 @@ public static async Task RunAndCompareOutput(string testFileName, string outputF (result2, output2, error2) = await Run(decompiledOutputFile).ConfigureAwait(false); } - Assert.AreEqual(0, result1, "Exit code != 0; did the test case crash?" + Environment.NewLine + error1); - Assert.AreEqual(0, result2, "Exit code != 0; did the decompiled code crash?" + Environment.NewLine + error2); + Assert.That(result1, Is.EqualTo(0), "Exit code != 0; did the test case crash?" + Environment.NewLine + error1); + Assert.That(result2, Is.EqualTo(0), "Exit code != 0; did the decompiled code crash?" + Environment.NewLine + error2); if (output1 != output2 || error1 != error2) { @@ -851,7 +851,7 @@ public static async Task SignAssembly(string assemblyPath, string keyFilePath) .WithValidation(CommandResultValidation.None); var result = await command.ExecuteBufferedAsync().ConfigureAwait(false); - Assert.AreEqual(0, result.ExitCode, "sn failed"); + Assert.That(result.ExitCode, Is.EqualTo(0), "sn failed"); if (!string.IsNullOrWhiteSpace(result.StandardOutput)) { diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index fe356566c2..1dfb43ed0d 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -54,7 +54,7 @@ - + diff --git a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs index 6a2cc4ed34..04c94d0898 100644 --- a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs @@ -45,8 +45,8 @@ public void AllFilesHaveTests() if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase)) { var testName = file.Name.Split('.')[0]; - Assert.Contains(testName, testNames); - Assert.IsTrue(File.Exists(Path.Combine(TestCasePath, testName + ".cs"))); + Assert.That(testNames, Has.Member(testName)); + Assert.That(File.Exists(Path.Combine(TestCasePath, testName + ".cs"))); } } } diff --git a/ICSharpCode.Decompiler.Tests/Output/CSharpAmbienceTests.cs b/ICSharpCode.Decompiler.Tests/Output/CSharpAmbienceTests.cs index f729215c4e..63eec4cd39 100644 --- a/ICSharpCode.Decompiler.Tests/Output/CSharpAmbienceTests.cs +++ b/ICSharpCode.Decompiler.Tests/Output/CSharpAmbienceTests.cs @@ -55,7 +55,7 @@ ITypeDefinition GetDefinition(Type type) } var foundType = compilation.FindType(type).GetDefinition(); - Assert.IsNotNull(foundType); + Assert.That(foundType, Is.Not.Null); return foundType; } @@ -76,7 +76,7 @@ public void GenericType(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(Dictionary<,>)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } [TestCase(None, "Object")] @@ -92,7 +92,7 @@ public void SimpleType(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(object)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } [TestCase(None, "IEnumerable")] @@ -104,7 +104,7 @@ public void GenericInterface(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(IEnumerable<>)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } [TestCase(None, "Enumerator")] @@ -121,7 +121,7 @@ public void GenericTypeWithNested(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(List<>.Enumerator)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } [TestCase(None, "StaticClass")] @@ -137,7 +137,7 @@ public void StaticClassTest(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(StaticClass)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } [TestCase(None, "SealedClass")] @@ -153,7 +153,7 @@ public void SealedClassTest(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(SealedClass)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } [TestCase(None, "RefStruct")] @@ -169,7 +169,7 @@ public void RefStructTest(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(RefStruct)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } [TestCase(None, "ReadonlyStruct")] @@ -185,7 +185,7 @@ public void ReadonlyStructTest(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(ReadonlyStruct)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } [TestCase(None, "ReadonlyRefStruct")] @@ -201,7 +201,7 @@ public void ReadonlyRefStructTest(ConversionFlags flags, string expectedOutput) { var typeDef = GetDefinition(typeof(ReadonlyRefStruct)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef)); + Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput)); } #endregion @@ -219,7 +219,7 @@ public void FuncDelegate(ConversionFlags flags, string expectedOutput) { var func = GetDefinition(typeof(Func<,>)); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(func)); + Assert.That(ambience.ConvertSymbol(func), Is.EqualTo(expectedOutput)); } #endregion @@ -232,7 +232,7 @@ public void SimpleField(ConversionFlags flags, string expectedOutput) var field = GetDefinition(typeof(CSharpAmbienceTests.Program)).GetFields(f => f.Name == "test").Single(); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(field)); + Assert.That(ambience.ConvertSymbol(field), Is.EqualTo(expectedOutput)); } [TestCase(All & ~PlaceReturnTypeAfterParameterList, "private const int ICSharpCode.Decompiler.Tests.Output.CSharpAmbienceTests.Program.TEST2;")] @@ -242,7 +242,7 @@ public void SimpleConstField(ConversionFlags flags, string expectedOutput) var field = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetFields(f => f.Name == "TEST2").Single(); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(field)); + Assert.That(ambience.ConvertSymbol(field), Is.EqualTo(expectedOutput)); } #endregion @@ -254,7 +254,7 @@ public void EventWithDeclaringType() ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType; string result = ambience.ConvertSymbol(ev); - Assert.AreEqual("public event EventHandler Program.ProgramChanged;", result); + Assert.That(result, Is.EqualTo("public event EventHandler Program.ProgramChanged;")); } [Test] @@ -264,7 +264,7 @@ public void CustomEvent() ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; string result = ambience.ConvertSymbol(ev); - Assert.AreEqual("public event EventHandler SomeEvent;", result); + Assert.That(result, Is.EqualTo("public event EventHandler SomeEvent;")); } #endregion @@ -276,7 +276,7 @@ public void AutomaticProperty(ConversionFlags flags, string expectedOutput) var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetProperties(p => p.Name == "Test").Single(); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(prop)); + Assert.That(ambience.ConvertSymbol(prop), Is.EqualTo(expectedOutput)); } [TestCase(StandardConversionFlags, "public int this[int index] { get; }")] @@ -286,7 +286,7 @@ public void Indexer(ConversionFlags flags, string expectedOutput) var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetProperties(p => p.IsIndexer).Single(); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(prop)); + Assert.That(ambience.ConvertSymbol(prop), Is.EqualTo(expectedOutput)); } #endregion @@ -298,7 +298,7 @@ public void ConstructorTests(ConversionFlags flags, string expectedOutput) var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetConstructors().Single(); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(prop)); + Assert.That(ambience.ConvertSymbol(prop), Is.EqualTo(expectedOutput)); } [TestCase(StandardConversionFlags, "~Program();")] @@ -309,7 +309,7 @@ public void DestructorTests(ConversionFlags flags, string expectedOutput) .GetMembers(m => m.SymbolKind == SymbolKind.Destructor, GetMemberOptions.IgnoreInheritedMembers).Single(); ambience.ConversionFlags = flags; - Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(dtor)); + Assert.That(ambience.ConvertSymbol(dtor), Is.EqualTo(expectedOutput)); } #endregion diff --git a/ICSharpCode.Decompiler.Tests/Output/InsertParenthesesVisitorTests.cs b/ICSharpCode.Decompiler.Tests/Output/InsertParenthesesVisitorTests.cs index f9bb5ddef0..0e7a3f3160 100644 --- a/ICSharpCode.Decompiler.Tests/Output/InsertParenthesesVisitorTests.cs +++ b/ICSharpCode.Decompiler.Tests/Output/InsertParenthesesVisitorTests.cs @@ -68,8 +68,8 @@ public void EqualityInAssignment() ) ); - Assert.AreEqual("cond = a == b", InsertRequired(expr)); - Assert.AreEqual("cond = a == b", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("cond = a == b")); + Assert.That(InsertReadable(expr), Is.EqualTo("cond = a == b")); } [Test] @@ -86,8 +86,8 @@ public void LambdaInAssignment() } ); - Assert.AreEqual("p = () => a + b", InsertRequired(expr)); - Assert.AreEqual("p = () => a + b", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("p = () => a + b")); + Assert.That(InsertReadable(expr), Is.EqualTo("p = () => a + b")); } [Test] @@ -105,8 +105,8 @@ public void LambdaInDelegateAdditionRHS() } }; - Assert.AreEqual("p + () => a + b", InsertRequired(expr)); - Assert.AreEqual("p + (() => a + b)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("p + () => a + b")); + Assert.That(InsertReadable(expr), Is.EqualTo("p + (() => a + b)")); } [Test] @@ -124,8 +124,8 @@ public void LambdaInDelegateAdditionLHS() Right = new IdentifierExpression("p"), }; - Assert.AreEqual("(() => a + b) + p", InsertRequired(expr)); - Assert.AreEqual("(() => a + b) + p", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(() => a + b) + p")); + Assert.That(InsertReadable(expr), Is.EqualTo("(() => a + b) + p")); } [Test] @@ -138,8 +138,8 @@ public void TrickyCast1() ) }; - Assert.AreEqual("(int)-a", InsertRequired(expr)); - Assert.AreEqual("(int)(-a)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(int)-a")); + Assert.That(InsertReadable(expr), Is.EqualTo("(int)(-a)")); } [Test] @@ -152,8 +152,8 @@ public void TrickyCast2() ) }; - Assert.AreEqual("(MyType)(-a)", InsertRequired(expr)); - Assert.AreEqual("(MyType)(-a)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(MyType)(-a)")); + Assert.That(InsertReadable(expr), Is.EqualTo("(MyType)(-a)")); } [Test] @@ -166,8 +166,8 @@ public void TrickyCast3() ) }; - Assert.AreEqual("(MyType)!a", InsertRequired(expr)); - Assert.AreEqual("(MyType)(!a)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(MyType)!a")); + Assert.That(InsertReadable(expr), Is.EqualTo("(MyType)(!a)")); } [Test] @@ -178,8 +178,8 @@ public void TrickyCast4() Expression = new PrimitiveExpression(int.MinValue), }; - Assert.AreEqual("(MyType)(-2147483648)", InsertRequired(expr)); - Assert.AreEqual("(MyType)(-2147483648)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(MyType)(-2147483648)")); + Assert.That(InsertReadable(expr), Is.EqualTo("(MyType)(-2147483648)")); } [Test] @@ -190,8 +190,8 @@ public void TrickyCast5() Expression = new PrimitiveExpression(-1.0), }; - Assert.AreEqual("(MyType)(-1.0)", InsertRequired(expr)); - Assert.AreEqual("(MyType)(-1.0)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(MyType)(-1.0)")); + Assert.That(InsertReadable(expr), Is.EqualTo("(MyType)(-1.0)")); } [Test] @@ -202,8 +202,8 @@ public void TrickyCast6() Expression = new PrimitiveExpression(int.MinValue), }; - Assert.AreEqual("(double)-2147483648", InsertRequired(expr)); - Assert.AreEqual("(double)(-2147483648)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(double)-2147483648")); + Assert.That(InsertReadable(expr), Is.EqualTo("(double)(-2147483648)")); } [Test] @@ -217,8 +217,8 @@ public void CastAndInvoke() MemberName = "Length" }; - Assert.AreEqual("((string)a).Length", InsertRequired(expr)); - Assert.AreEqual("((string)a).Length", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("((string)a).Length")); + Assert.That(InsertReadable(expr), Is.EqualTo("((string)a).Length")); } [Test] @@ -229,8 +229,8 @@ public void DoubleNegation() new UnaryOperatorExpression(UnaryOperatorType.Minus, new IdentifierExpression("a")) ); - Assert.AreEqual("- -a", InsertRequired(expr)); - Assert.AreEqual("-(-a)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("- -a")); + Assert.That(InsertReadable(expr), Is.EqualTo("-(-a)")); } [Test] @@ -250,8 +250,8 @@ public void AdditionWithConditional() } }; - Assert.AreEqual("a + (b == null ? c : d)", InsertRequired(expr)); - Assert.AreEqual("a + ((b == null) ? c : d)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("a + (b == null ? c : d)")); + Assert.That(InsertReadable(expr), Is.EqualTo("a + ((b == null) ? c : d)")); } [Test] @@ -269,16 +269,16 @@ public void TypeTestInConditional() FalseExpression = new IdentifierExpression("c") }; - Assert.AreEqual("a is int? ? b : c", InsertRequired(expr)); - Assert.AreEqual("(a is int?) ? b : c", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("a is int? ? b : c")); + Assert.That(InsertReadable(expr), Is.EqualTo("(a is int?) ? b : c")); policy.SpaceBeforeConditionalOperatorCondition = false; policy.SpaceAfterConditionalOperatorCondition = false; policy.SpaceBeforeConditionalOperatorSeparator = false; policy.SpaceAfterConditionalOperatorSeparator = false; - Assert.AreEqual("a is int? ?b:c", InsertRequired(expr)); - Assert.AreEqual("(a is int?)?b:c", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("a is int? ?b:c")); + Assert.That(InsertReadable(expr), Is.EqualTo("(a is int?)?b:c")); } [Test] @@ -302,8 +302,8 @@ public void MethodCallOnQueryExpression() MemberName = "ToArray" }); - Assert.AreEqual("(from a in b select a.c ()).ToArray ()", InsertRequired(expr)); - Assert.AreEqual("(from a in b select a.c ()).ToArray ()", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(from a in b select a.c ()).ToArray ()")); + Assert.That(InsertReadable(expr), Is.EqualTo("(from a in b select a.c ()).ToArray ()")); } [Test] @@ -326,10 +326,10 @@ public void SumOfQueries() query.Clone() ); - Assert.AreEqual("(from a in b select a) + " + - "from a in b select a", InsertRequired(expr)); - Assert.AreEqual("(from a in b select a) + " + - "(from a in b select a)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(from a in b select a) + " + + "from a in b select a")); + Assert.That(InsertReadable(expr), Is.EqualTo("(from a in b select a) + " + + "(from a in b select a)")); } [Test] @@ -350,8 +350,8 @@ public void QueryInTypeTest() Type = new PrimitiveType("int") }; - Assert.AreEqual("(from a in b select a) is int", InsertRequired(expr)); - Assert.AreEqual("(from a in b select a) is int", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(from a in b select a) is int")); + Assert.That(InsertReadable(expr), Is.EqualTo("(from a in b select a) is int")); } [Test] @@ -365,8 +365,8 @@ public void PrePost() ) ); - Assert.AreEqual("++a++", InsertRequired(expr)); - Assert.AreEqual("++(a++)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("++a++")); + Assert.That(InsertReadable(expr), Is.EqualTo("++(a++)")); } [Test] @@ -380,8 +380,8 @@ public void PostPre() ) ); - Assert.AreEqual("(++a)++", InsertRequired(expr)); - Assert.AreEqual("(++a)++", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(++a)++")); + Assert.That(InsertReadable(expr), Is.EqualTo("(++a)++")); } [Test] @@ -397,8 +397,8 @@ public void Logical1() new IdentifierExpression("c") ); - Assert.AreEqual("a && b && c", InsertRequired(expr)); - Assert.AreEqual("a && b && c", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("a && b && c")); + Assert.That(InsertReadable(expr), Is.EqualTo("a && b && c")); } [Test] @@ -414,8 +414,8 @@ public void Logical2() ) ); - Assert.AreEqual("a && (b && c)", InsertRequired(expr)); - Assert.AreEqual("a && (b && c)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("a && (b && c)")); + Assert.That(InsertReadable(expr), Is.EqualTo("a && (b && c)")); } [Test] @@ -431,8 +431,8 @@ public void Logical3() ) ); - Assert.AreEqual("a || b && c", InsertRequired(expr)); - Assert.AreEqual("a || (b && c)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("a || b && c")); + Assert.That(InsertReadable(expr), Is.EqualTo("a || (b && c)")); } [Test] @@ -448,8 +448,8 @@ public void Logical4() ) ); - Assert.AreEqual("a && (b || c)", InsertRequired(expr)); - Assert.AreEqual("a && (b || c)", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("a && (b || c)")); + Assert.That(InsertReadable(expr), Is.EqualTo("a && (b || c)")); } [Test] @@ -463,8 +463,8 @@ public void ArrayCreationInIndexer() Arguments = { new PrimitiveExpression(0) } }; - Assert.AreEqual("(new int[1]) [0]", InsertRequired(expr)); - Assert.AreEqual("(new int[1]) [0]", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("(new int[1]) [0]")); + Assert.That(InsertReadable(expr), Is.EqualTo("(new int[1]) [0]")); } [Test] @@ -481,8 +481,8 @@ public void ArrayCreationWithInitializerInIndexer() Arguments = { new PrimitiveExpression(0) } }; - Assert.AreEqual("new int[1] { 42 } [0]", InsertRequired(expr)); - Assert.AreEqual("(new int[1] { 42 }) [0]", InsertReadable(expr)); + Assert.That(InsertRequired(expr), Is.EqualTo("new int[1] { 42 } [0]")); + Assert.That(InsertReadable(expr), Is.EqualTo("(new int[1] { 42 }) [0]")); } } } diff --git a/ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs b/ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs index ed8488fa43..48dda98649 100644 --- a/ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs @@ -70,8 +70,8 @@ public void CustomPdbId() var metadataReader = MetadataReaderProvider.FromPortablePdbStream(pdbStream).GetMetadataReader(); var generatedPdbId = new BlobContentId(metadataReader.DebugMetadataHeader.Id); - Assert.AreEqual(expectedPdbId.Guid, generatedPdbId.Guid); - Assert.AreEqual(expectedPdbId.Stamp, generatedPdbId.Stamp); + Assert.That(generatedPdbId.Guid, Is.EqualTo(expectedPdbId.Guid)); + Assert.That(generatedPdbId.Stamp, Is.EqualTo(expectedPdbId.Stamp)); } } @@ -95,8 +95,8 @@ public void ProgressReporting() totalFiles = progress.TotalUnits; } - Assert.AreEqual(progress.TotalUnits, totalFiles); - Assert.AreEqual(progress.UnitsCompleted, lastFilesWritten + 1); + Assert.That(totalFiles, Is.EqualTo(progress.TotalUnits)); + Assert.That(lastFilesWritten + 1, Is.EqualTo(progress.UnitsCompleted)); lastFilesWritten = progress.UnitsCompleted; }; @@ -111,7 +111,7 @@ public void ProgressReporting() var generatedPdbId = new BlobContentId(metadataReader.DebugMetadataHeader.Id); } - Assert.AreEqual(totalFiles, lastFilesWritten); + Assert.That(lastFilesWritten, Is.EqualTo(totalFiles)); } private class TestProgressReporter : IProgress diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index c341835e0e..4fe48369dd 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -46,7 +46,7 @@ public void AllFilesHaveTests() || file.Extension.Equals(".cs", StringComparison.OrdinalIgnoreCase)) { var testName = file.Name.Split('.')[0]; - Assert.Contains(testName, testNames); + Assert.That(testNames, Has.Member(testName)); } } } diff --git a/ICSharpCode.Decompiler.Tests/ProjectDecompiler/TargetFrameworkTests.cs b/ICSharpCode.Decompiler.Tests/ProjectDecompiler/TargetFrameworkTests.cs index c92f49c574..df78e9bc1b 100644 --- a/ICSharpCode.Decompiler.Tests/ProjectDecompiler/TargetFrameworkTests.cs +++ b/ICSharpCode.Decompiler.Tests/ProjectDecompiler/TargetFrameworkTests.cs @@ -57,8 +57,8 @@ public void VerifyVersion(int version, string expectedVersion) var targetFramework = new TargetFramework(identifier: null, version, profile: null); // Assert - Assert.AreEqual(version, targetFramework.VersionNumber); - Assert.AreEqual(expectedVersion, targetFramework.VersionString); + Assert.That(targetFramework.VersionNumber, Is.EqualTo(version)); + Assert.That(targetFramework.VersionString, Is.EqualTo(expectedVersion)); } [Test] @@ -71,8 +71,8 @@ public void VerifyPortableLibrary() var targetFramework = new TargetFramework(identifier, 100, profile: null); // Assert - Assert.IsTrue(targetFramework.IsPortableClassLibrary); - Assert.AreEqual(identifier, targetFramework.Identifier); + Assert.That(targetFramework.IsPortableClassLibrary); + Assert.That(targetFramework.Identifier, Is.EqualTo(identifier)); } [Test] @@ -87,8 +87,8 @@ public void VerifyIdentifierAndProfile( var targetFramework = new TargetFramework(identifier, 100, profile); // Assert - Assert.AreEqual(identifier, targetFramework.Identifier); - Assert.AreEqual(profile, targetFramework.Profile); + Assert.That(targetFramework.Identifier, Is.EqualTo(identifier)); + Assert.That(targetFramework.Profile, Is.EqualTo(profile)); } [TestCase(null, 350, "net35")] @@ -117,7 +117,7 @@ public void VerifyMoniker(string identifier, int version, string expectedMoniker var targetFramework = new TargetFramework(identifier, version, profile: null); // Assert - Assert.AreEqual(expectedMoniker, targetFramework.Moniker); + Assert.That(targetFramework.Moniker, Is.EqualTo(expectedMoniker)); } } } diff --git a/ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs b/ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs index 3a378e2374..d65300b7c0 100644 --- a/ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs +++ b/ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs @@ -212,7 +212,7 @@ async Task RunInternal(string dir, string fileToRoundtrip, Action testAc File.Copy(file, Path.Combine(outputDir, relFile)); } } - Assert.IsNotNull(projectFile, $"Could not find {fileToRoundtrip}"); + Assert.That(projectFile, Is.Not.Null, $"Could not find {fileToRoundtrip}"); await Compile(projectFile, outputDir); testAction(outputDir); diff --git a/ICSharpCode.Decompiler.Tests/Semantics/ConversionTests.cs b/ICSharpCode.Decompiler.Tests/Semantics/ConversionTests.cs index a6687124c5..8484cd2665 100644 --- a/ICSharpCode.Decompiler.Tests/Semantics/ConversionTests.cs +++ b/ICSharpCode.Decompiler.Tests/Semantics/ConversionTests.cs @@ -70,34 +70,34 @@ Conversion ExplicitConversion(Type from, Type to) [Test] public void IdentityConversions() { - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(char), typeof(char))); - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(string), typeof(string))); - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(object), typeof(object))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(bool), typeof(char))); + Assert.That(ImplicitConversion(typeof(char), typeof(char)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ImplicitConversion(typeof(string), typeof(string)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ImplicitConversion(typeof(object), typeof(object)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ImplicitConversion(typeof(bool), typeof(char)), Is.EqualTo(C.None)); - Assert.AreEqual(C.IdentityConversion, conversions.ImplicitConversion(SpecialType.Dynamic, SpecialType.Dynamic)); - Assert.AreEqual(C.IdentityConversion, conversions.ImplicitConversion(SpecialType.UnknownType, SpecialType.UnknownType)); - Assert.AreEqual(C.IdentityConversion, conversions.ImplicitConversion(SpecialType.NullType, SpecialType.NullType)); + Assert.That(conversions.ImplicitConversion(SpecialType.Dynamic, SpecialType.Dynamic), Is.EqualTo(C.IdentityConversion)); + Assert.That(conversions.ImplicitConversion(SpecialType.UnknownType, SpecialType.UnknownType), Is.EqualTo(C.IdentityConversion)); + Assert.That(conversions.ImplicitConversion(SpecialType.NullType, SpecialType.NullType), Is.EqualTo(C.IdentityConversion)); } [Test] public void DynamicIdentityConversions() { - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(object), typeof(dynamic))); - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(dynamic), typeof(object))); + Assert.That(ImplicitConversion(typeof(object), typeof(dynamic)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ImplicitConversion(typeof(dynamic), typeof(object)), Is.EqualTo(C.IdentityConversion)); } [Test] public void ComplexDynamicIdentityConversions() { - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(List), typeof(List))); - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(List), typeof(List))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(List), typeof(List))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(List), typeof(List))); + Assert.That(ImplicitConversion(typeof(List), typeof(List)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ImplicitConversion(typeof(List), typeof(List)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ImplicitConversion(typeof(List), typeof(List)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(List), typeof(List)), Is.EqualTo(C.None)); - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(List[]>), typeof(List[]>))); - Assert.AreEqual(C.IdentityConversion, ImplicitConversion(typeof(List[]>), typeof(List[]>))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(List[,]>), typeof(List[]>))); + Assert.That(ImplicitConversion(typeof(List[]>), typeof(List[]>)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ImplicitConversion(typeof(List[]>), typeof(List[]>)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ImplicitConversion(typeof(List[,]>), typeof(List[]>)), Is.EqualTo(C.None)); } [Test] @@ -105,40 +105,38 @@ public void TupleIdentityConversions() { var intType = compilation.FindType(typeof(int)); var stringType = compilation.FindType(typeof(string)); - Assert.AreEqual(C.IdentityConversion, conversions.ImplicitConversion( + Assert.That(conversions.ImplicitConversion( new TupleType(compilation, ImmutableArray.Create(intType, stringType), ImmutableArray.Create("a", "b")), - new TupleType(compilation, ImmutableArray.Create(intType, stringType), ImmutableArray.Create("a", "c")))); + new TupleType(compilation, ImmutableArray.Create(intType, stringType), ImmutableArray.Create("a", "c"))), Is.EqualTo(C.IdentityConversion)); - Assert.AreEqual(C.None, conversions.ImplicitConversion( + Assert.That(conversions.ImplicitConversion( new TupleType(compilation, ImmutableArray.Create(intType, stringType), ImmutableArray.Create("a", "b")), - new TupleType(compilation, ImmutableArray.Create(stringType, intType), ImmutableArray.Create("a", "b")))); + new TupleType(compilation, ImmutableArray.Create(stringType, intType), ImmutableArray.Create("a", "b"))), Is.EqualTo(C.None)); } [Test] public void TupleConversions() { - Assert.AreEqual( - C.TupleConversion(ImmutableArray.Create(C.ImplicitNumericConversion, C.ImplicitReferenceConversion)), - ImplicitConversion(typeof((int, string)), typeof((long, object)))); + Assert.That( + ImplicitConversion(typeof((int, string)), typeof((long, object))), Is.EqualTo(C.TupleConversion(ImmutableArray.Create(C.ImplicitNumericConversion, C.ImplicitReferenceConversion)))); - Assert.AreEqual( - C.TupleConversion(ImmutableArray.Create(C.ImplicitNumericConversion)), - ImplicitConversion(typeof(ValueTuple), typeof(ValueTuple))); + Assert.That( + ImplicitConversion(typeof(ValueTuple), typeof(ValueTuple)), Is.EqualTo(C.TupleConversion(ImmutableArray.Create(C.ImplicitNumericConversion)))); } [Test] public void PrimitiveConversions() { - Assert.AreEqual(C.ImplicitNumericConversion, ImplicitConversion(typeof(char), typeof(ushort))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(byte), typeof(char))); - Assert.AreEqual(C.ImplicitNumericConversion, ImplicitConversion(typeof(int), typeof(long))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(long), typeof(int))); - Assert.AreEqual(C.ImplicitNumericConversion, ImplicitConversion(typeof(int), typeof(float))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(bool), typeof(float))); - Assert.AreEqual(C.ImplicitNumericConversion, ImplicitConversion(typeof(float), typeof(double))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(float), typeof(decimal))); - Assert.AreEqual(C.ImplicitNumericConversion, ImplicitConversion(typeof(char), typeof(long))); - Assert.AreEqual(C.ImplicitNumericConversion, ImplicitConversion(typeof(uint), typeof(long))); + Assert.That(ImplicitConversion(typeof(char), typeof(ushort)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ImplicitConversion(typeof(byte), typeof(char)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(int), typeof(long)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ImplicitConversion(typeof(long), typeof(int)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(int), typeof(float)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ImplicitConversion(typeof(bool), typeof(float)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(float), typeof(double)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ImplicitConversion(typeof(float), typeof(decimal)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(char), typeof(long)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ImplicitConversion(typeof(uint), typeof(long)), Is.EqualTo(C.ImplicitNumericConversion)); } [Test] @@ -147,64 +145,64 @@ public void EnumerationConversion() ResolveResult zero = new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 0); ResolveResult one = new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 1); C implicitEnumerationConversion = C.EnumerationConversion(true, false); - Assert.AreEqual(implicitEnumerationConversion, conversions.ImplicitConversion(zero, compilation.FindType(typeof(StringComparison)))); - Assert.AreEqual(C.None, conversions.ImplicitConversion(one, compilation.FindType(typeof(StringComparison)))); + Assert.That(conversions.ImplicitConversion(zero, compilation.FindType(typeof(StringComparison))), Is.EqualTo(implicitEnumerationConversion)); + Assert.That(conversions.ImplicitConversion(one, compilation.FindType(typeof(StringComparison))), Is.EqualTo(C.None)); } [Test] public void NullableConversions() { - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ImplicitConversion(typeof(char), typeof(ushort?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(byte), typeof(char?))); - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ImplicitConversion(typeof(int), typeof(long?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(long), typeof(int?))); - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ImplicitConversion(typeof(int), typeof(float?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(bool), typeof(float?))); - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ImplicitConversion(typeof(float), typeof(double?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(float), typeof(decimal?))); + Assert.That(ImplicitConversion(typeof(char), typeof(ushort?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ImplicitConversion(typeof(byte), typeof(char?)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(int), typeof(long?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ImplicitConversion(typeof(long), typeof(int?)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(int), typeof(float?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ImplicitConversion(typeof(bool), typeof(float?)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(float), typeof(double?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ImplicitConversion(typeof(float), typeof(decimal?)), Is.EqualTo(C.None)); } [Test] public void NullableConversions2() { - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ImplicitConversion(typeof(char?), typeof(ushort?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(byte?), typeof(char?))); - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ImplicitConversion(typeof(int?), typeof(long?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(long?), typeof(int?))); - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ImplicitConversion(typeof(int?), typeof(float?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(bool?), typeof(float?))); - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ImplicitConversion(typeof(float?), typeof(double?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(float?), typeof(decimal?))); + Assert.That(ImplicitConversion(typeof(char?), typeof(ushort?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ImplicitConversion(typeof(byte?), typeof(char?)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(int?), typeof(long?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ImplicitConversion(typeof(long?), typeof(int?)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(int?), typeof(float?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ImplicitConversion(typeof(bool?), typeof(float?)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(float?), typeof(double?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ImplicitConversion(typeof(float?), typeof(decimal?)), Is.EqualTo(C.None)); } [Test] public void NullLiteralConversions() { - Assert.AreEqual(C.NullLiteralConversion, ImplicitConversion(typeof(Null), typeof(int?))); - Assert.AreEqual(C.NullLiteralConversion, ImplicitConversion(typeof(Null), typeof(char?))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(Null), typeof(int))); - Assert.AreEqual(C.NullLiteralConversion, ImplicitConversion(typeof(Null), typeof(object))); - Assert.AreEqual(C.NullLiteralConversion, ImplicitConversion(typeof(Null), typeof(dynamic))); - Assert.AreEqual(C.NullLiteralConversion, ImplicitConversion(typeof(Null), typeof(string))); - Assert.AreEqual(C.NullLiteralConversion, ImplicitConversion(typeof(Null), typeof(int[]))); + Assert.That(ImplicitConversion(typeof(Null), typeof(int?)), Is.EqualTo(C.NullLiteralConversion)); + Assert.That(ImplicitConversion(typeof(Null), typeof(char?)), Is.EqualTo(C.NullLiteralConversion)); + Assert.That(ImplicitConversion(typeof(Null), typeof(int)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(Null), typeof(object)), Is.EqualTo(C.NullLiteralConversion)); + Assert.That(ImplicitConversion(typeof(Null), typeof(dynamic)), Is.EqualTo(C.NullLiteralConversion)); + Assert.That(ImplicitConversion(typeof(Null), typeof(string)), Is.EqualTo(C.NullLiteralConversion)); + Assert.That(ImplicitConversion(typeof(Null), typeof(int[])), Is.EqualTo(C.NullLiteralConversion)); } [Test] public void SimpleReferenceConversions() { - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(string), typeof(object))); - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(BitArray), typeof(ICollection))); - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(IList), typeof(IEnumerable))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(object), typeof(string))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(ICollection), typeof(BitArray))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(IEnumerable), typeof(IList))); + Assert.That(ImplicitConversion(typeof(string), typeof(object)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(BitArray), typeof(ICollection)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(IList), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(object), typeof(string)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(ICollection), typeof(BitArray)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(IEnumerable), typeof(IList)), Is.EqualTo(C.None)); } [Test] public void ConversionToDynamic() { - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(string), typeof(dynamic))); - Assert.AreEqual(C.BoxingConversion, ImplicitConversion(typeof(int), typeof(dynamic))); + Assert.That(ImplicitConversion(typeof(string), typeof(dynamic)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(int), typeof(dynamic)), Is.EqualTo(C.BoxingConversion)); } [Test] @@ -213,177 +211,164 @@ public void ConversionFromDynamic() // There is no conversion from the type 'dynamic' to other types (except the identity conversion to object). // Such conversions only exists from dynamic expression. // This is an important distinction for type inference (see TypeInferenceTests.IEnumerableCovarianceWithDynamic) - Assert.AreEqual(C.None, ImplicitConversion(typeof(dynamic), typeof(string))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(dynamic), typeof(int))); + Assert.That(ImplicitConversion(typeof(dynamic), typeof(string)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(dynamic), typeof(int)), Is.EqualTo(C.None)); var dynamicRR = new ResolveResult(SpecialType.Dynamic); - Assert.AreEqual(C.ImplicitDynamicConversion, conversions.ImplicitConversion(dynamicRR, compilation.FindType(typeof(string)))); - Assert.AreEqual(C.ImplicitDynamicConversion, conversions.ImplicitConversion(dynamicRR, compilation.FindType(typeof(int)))); + Assert.That(conversions.ImplicitConversion(dynamicRR, compilation.FindType(typeof(string))), Is.EqualTo(C.ImplicitDynamicConversion)); + Assert.That(conversions.ImplicitConversion(dynamicRR, compilation.FindType(typeof(int))), Is.EqualTo(C.ImplicitDynamicConversion)); } [Test] public void ParameterizedTypeConversions() { - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(List), typeof(ICollection))); - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(IList), typeof(ICollection))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(List), typeof(ICollection))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(IList), typeof(ICollection))); + Assert.That(ImplicitConversion(typeof(List), typeof(ICollection)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(IList), typeof(ICollection)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(List), typeof(ICollection)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(IList), typeof(ICollection)), Is.EqualTo(C.None)); } [Test] public void ArrayConversions() { - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(string[]), typeof(object[]))); - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(string[,]), typeof(object[,]))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(string[]), typeof(object[,]))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(object[]), typeof(string[]))); + Assert.That(ImplicitConversion(typeof(string[]), typeof(object[])), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(string[,]), typeof(object[,])), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(string[]), typeof(object[,])), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(object[]), typeof(string[])), Is.EqualTo(C.None)); - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(string[]), typeof(IList))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(string[,]), typeof(IList))); - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(string[]), typeof(IList))); + Assert.That(ImplicitConversion(typeof(string[]), typeof(IList)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(string[,]), typeof(IList)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(string[]), typeof(IList)), Is.EqualTo(C.ImplicitReferenceConversion)); - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(string[]), typeof(Array))); - Assert.AreEqual(C.ImplicitReferenceConversion, ImplicitConversion(typeof(string[]), typeof(ICloneable))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(Array), typeof(string[]))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(object), typeof(object[]))); + Assert.That(ImplicitConversion(typeof(string[]), typeof(Array)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(string[]), typeof(ICloneable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(Array), typeof(string[])), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(object), typeof(object[])), Is.EqualTo(C.None)); } [Test] public void VarianceConversions() { - Assert.AreEqual(C.ImplicitReferenceConversion, - ImplicitConversion(typeof(List), typeof(IEnumerable))); - Assert.AreEqual(C.None, - ImplicitConversion(typeof(List), typeof(IEnumerable))); - Assert.AreEqual(C.ImplicitReferenceConversion, - ImplicitConversion(typeof(IEnumerable), typeof(IEnumerable))); - Assert.AreEqual(C.None, - ImplicitConversion(typeof(ICollection), typeof(ICollection))); - - Assert.AreEqual(C.ImplicitReferenceConversion, - ImplicitConversion(typeof(Comparer), typeof(IComparer))); - Assert.AreEqual(C.ImplicitReferenceConversion, - ImplicitConversion(typeof(Comparer), typeof(IComparer))); - Assert.AreEqual(C.None, - ImplicitConversion(typeof(Comparer), typeof(Comparer))); - - Assert.AreEqual(C.None, - ImplicitConversion(typeof(List), typeof(IEnumerable))); - Assert.AreEqual(C.ImplicitReferenceConversion, - ImplicitConversion(typeof(IEnumerable), typeof(IEnumerable))); - - Assert.AreEqual(C.ImplicitReferenceConversion, - ImplicitConversion(typeof(Func), typeof(Func))); - Assert.AreEqual(C.ImplicitReferenceConversion, - ImplicitConversion(typeof(Func), typeof(Func))); - Assert.AreEqual(C.None, - ImplicitConversion(typeof(Func), typeof(Func))); - Assert.AreEqual(C.None, - ImplicitConversion(typeof(Func), typeof(Func))); + Assert.That(ImplicitConversion(typeof(List), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(List), typeof(IEnumerable)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(IEnumerable), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(ICollection), typeof(ICollection)), Is.EqualTo(C.None)); + + Assert.That(ImplicitConversion(typeof(Comparer), typeof(IComparer)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(Comparer), typeof(IComparer)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(Comparer), typeof(Comparer)), Is.EqualTo(C.None)); + + Assert.That(ImplicitConversion(typeof(List), typeof(IEnumerable)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(IEnumerable), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + + Assert.That(ImplicitConversion(typeof(Func), typeof(Func)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(Func), typeof(Func)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ImplicitConversion(typeof(Func), typeof(Func)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(Func), typeof(Func)), Is.EqualTo(C.None)); } [Test] public void ImplicitPointerConversion() { - Assert.AreEqual(C.ImplicitPointerConversion, ImplicitConversion(typeof(Null), typeof(int*))); - Assert.AreEqual(C.ImplicitPointerConversion, ImplicitConversion(typeof(int*), typeof(void*))); + Assert.That(ImplicitConversion(typeof(Null), typeof(int*)), Is.EqualTo(C.ImplicitPointerConversion)); + Assert.That(ImplicitConversion(typeof(int*), typeof(void*)), Is.EqualTo(C.ImplicitPointerConversion)); } [Test] public void NoConversionFromPointerTypeToObject() { - Assert.AreEqual(C.None, ImplicitConversion(typeof(int*), typeof(object))); - Assert.AreEqual(C.None, ImplicitConversion(typeof(int*), typeof(dynamic))); + Assert.That(ImplicitConversion(typeof(int*), typeof(object)), Is.EqualTo(C.None)); + Assert.That(ImplicitConversion(typeof(int*), typeof(dynamic)), Is.EqualTo(C.None)); } [Test] public void ConversionToNInt() { // Test based on the table in https://github.com/dotnet/csharplang/blob/master/proposals/native-integers.md - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(object), typeof(nint))); - Assert.AreEqual(C.ExplicitPointerConversion, ExplicitConversion(typeof(void*), typeof(nint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(sbyte), typeof(nint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(byte), typeof(nint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(short), typeof(nint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(ushort), typeof(nint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(int), typeof(nint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(uint), typeof(nint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(long), typeof(nint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(ulong), typeof(nint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(char), typeof(nint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(float), typeof(nint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(double), typeof(nint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(decimal), typeof(nint))); - Assert.AreEqual(C.IdentityConversion, ExplicitConversion(typeof(IntPtr), typeof(nint))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(UIntPtr), typeof(nint))); + Assert.That(ExplicitConversion(typeof(object), typeof(nint)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(void*), typeof(nint)), Is.EqualTo(C.ExplicitPointerConversion)); + Assert.That(ExplicitConversion(typeof(sbyte), typeof(nint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(byte), typeof(nint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(short), typeof(nint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(ushort), typeof(nint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(int), typeof(nint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(uint), typeof(nint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(long), typeof(nint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(ulong), typeof(nint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(char), typeof(nint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(float), typeof(nint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(double), typeof(nint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(decimal), typeof(nint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(IntPtr), typeof(nint)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ExplicitConversion(typeof(UIntPtr), typeof(nint)), Is.EqualTo(C.None)); } [Test] public void ConversionToNUInt() { // Test based on the table in https://github.com/dotnet/csharplang/blob/master/proposals/native-integers.md - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(object), typeof(nuint))); - Assert.AreEqual(C.ExplicitPointerConversion, ExplicitConversion(typeof(void*), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(sbyte), typeof(nuint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(byte), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(short), typeof(nuint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(ushort), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(int), typeof(nuint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(uint), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(long), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(ulong), typeof(nuint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(char), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(float), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(double), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(decimal), typeof(nuint))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(IntPtr), typeof(nuint))); - Assert.AreEqual(C.IdentityConversion, ExplicitConversion(typeof(UIntPtr), typeof(nuint))); + Assert.That(ExplicitConversion(typeof(object), typeof(nuint)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(void*), typeof(nuint)), Is.EqualTo(C.ExplicitPointerConversion)); + Assert.That(ExplicitConversion(typeof(sbyte), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(byte), typeof(nuint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(short), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(ushort), typeof(nuint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(int), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(uint), typeof(nuint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(long), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(ulong), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(char), typeof(nuint)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(float), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(double), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(decimal), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(IntPtr), typeof(nuint)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(UIntPtr), typeof(nuint)), Is.EqualTo(C.IdentityConversion)); } [Test] public void ConversionFromNInt() { // Test based on the table in https://github.com/dotnet/csharplang/blob/master/proposals/native-integers.md - Assert.AreEqual(C.BoxingConversion, ExplicitConversion(typeof(nint), typeof(object))); - Assert.AreEqual(C.ExplicitPointerConversion, ExplicitConversion(typeof(nint), typeof(void*))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(nuint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(sbyte))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(byte))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(short))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(ushort))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(int))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(uint))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(long))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(ulong))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(char))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(float))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(double))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(nint), typeof(decimal))); - Assert.AreEqual(C.IdentityConversion, ExplicitConversion(typeof(nint), typeof(IntPtr))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(nint), typeof(UIntPtr))); + Assert.That(ExplicitConversion(typeof(nint), typeof(object)), Is.EqualTo(C.BoxingConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(void*)), Is.EqualTo(C.ExplicitPointerConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(nuint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(sbyte)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(byte)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(short)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(ushort)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(int)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(uint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(long)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(ulong)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(char)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(float)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(double)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(decimal)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(IntPtr)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ExplicitConversion(typeof(nint), typeof(UIntPtr)), Is.EqualTo(C.None)); } [Test] public void ConversionFromNUInt() { // Test based on the table in https://github.com/dotnet/csharplang/blob/master/proposals/native-integers.md - Assert.AreEqual(C.BoxingConversion, ExplicitConversion(typeof(nuint), typeof(object))); - Assert.AreEqual(C.ExplicitPointerConversion, ExplicitConversion(typeof(nuint), typeof(void*))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(nint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(sbyte))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(byte))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(short))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(ushort))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(int))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(uint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(long))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(ulong))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(char))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(float))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(double))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(nuint), typeof(decimal))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(nuint), typeof(IntPtr))); - Assert.AreEqual(C.IdentityConversion, ExplicitConversion(typeof(nuint), typeof(UIntPtr))); + Assert.That(ExplicitConversion(typeof(nuint), typeof(object)), Is.EqualTo(C.BoxingConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(void*)), Is.EqualTo(C.ExplicitPointerConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(nint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(sbyte)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(byte)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(short)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(ushort)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(int)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(uint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(long)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(ulong)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(char)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(float)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(double)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(decimal)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(IntPtr)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(UIntPtr)), Is.EqualTo(C.IdentityConversion)); } @@ -391,29 +376,29 @@ public void ConversionFromNUInt() public void NIntEnumConversion() { var explicitEnumConversion = C.EnumerationConversion(isImplicit: false, isLifted: false); - Assert.AreEqual(explicitEnumConversion, ExplicitConversion(typeof(nint), typeof(StringComparison))); - Assert.AreEqual(explicitEnumConversion, ExplicitConversion(typeof(nuint), typeof(StringComparison))); - Assert.AreEqual(explicitEnumConversion, ExplicitConversion(typeof(StringComparison), typeof(nint))); - Assert.AreEqual(explicitEnumConversion, ExplicitConversion(typeof(StringComparison), typeof(nuint))); + Assert.That(ExplicitConversion(typeof(nint), typeof(StringComparison)), Is.EqualTo(explicitEnumConversion)); + Assert.That(ExplicitConversion(typeof(nuint), typeof(StringComparison)), Is.EqualTo(explicitEnumConversion)); + Assert.That(ExplicitConversion(typeof(StringComparison), typeof(nint)), Is.EqualTo(explicitEnumConversion)); + Assert.That(ExplicitConversion(typeof(StringComparison), typeof(nuint)), Is.EqualTo(explicitEnumConversion)); } [Test] public void IntegerLiteralToNIntConversions() { - Assert.IsTrue(IntegerLiteralConversion(0, typeof(nint))); - Assert.IsTrue(IntegerLiteralConversion(-1, typeof(nint))); - Assert.IsFalse(IntegerLiteralConversion(uint.MaxValue, typeof(nint))); - Assert.IsFalse(IntegerLiteralConversion(long.MaxValue, typeof(nint))); + Assert.That(IntegerLiteralConversion(0, typeof(nint))); + Assert.That(IntegerLiteralConversion(-1, typeof(nint))); + Assert.That(!IntegerLiteralConversion(uint.MaxValue, typeof(nint))); + Assert.That(!IntegerLiteralConversion(long.MaxValue, typeof(nint))); } [Test] public void IntegerLiteralToNUIntConversions() { - Assert.IsTrue(IntegerLiteralConversion(0, typeof(nuint))); - Assert.IsFalse(IntegerLiteralConversion(-1, typeof(nuint))); - Assert.IsTrue(IntegerLiteralConversion(uint.MaxValue, typeof(nuint))); - Assert.IsFalse(IntegerLiteralConversion(long.MaxValue, typeof(nuint))); + Assert.That(IntegerLiteralConversion(0, typeof(nuint))); + Assert.That(!IntegerLiteralConversion(-1, typeof(nuint))); + Assert.That(IntegerLiteralConversion(uint.MaxValue, typeof(nuint))); + Assert.That(!IntegerLiteralConversion(long.MaxValue, typeof(nuint))); } [Test] @@ -423,16 +408,16 @@ public void UnconstrainedTypeParameter() ITypeParameter t2 = new DefaultTypeParameter(compilation, SymbolKind.TypeDefinition, 1, "T2"); ITypeParameter tm = new DefaultTypeParameter(compilation, SymbolKind.Method, 0, "TM"); - Assert.AreEqual(C.None, conversions.ImplicitConversion(SpecialType.NullType, t)); - Assert.AreEqual(C.BoxingConversion, conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object))); - Assert.AreEqual(C.BoxingConversion, conversions.ImplicitConversion(t, SpecialType.Dynamic)); - Assert.AreEqual(C.None, conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType)))); + Assert.That(conversions.ImplicitConversion(SpecialType.NullType, t), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object)), Is.EqualTo(C.BoxingConversion)); + Assert.That(conversions.ImplicitConversion(t, SpecialType.Dynamic), Is.EqualTo(C.BoxingConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType))), Is.EqualTo(C.None)); - Assert.AreEqual(C.IdentityConversion, conversions.ImplicitConversion(t, t)); - Assert.AreEqual(C.None, conversions.ImplicitConversion(t2, t)); - Assert.AreEqual(C.None, conversions.ImplicitConversion(t, t2)); - Assert.AreEqual(C.None, conversions.ImplicitConversion(t, tm)); - Assert.AreEqual(C.None, conversions.ImplicitConversion(tm, t)); + Assert.That(conversions.ImplicitConversion(t, t), Is.EqualTo(C.IdentityConversion)); + Assert.That(conversions.ImplicitConversion(t2, t), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(t, t2), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(t, tm), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(tm, t), Is.EqualTo(C.None)); } [Test] @@ -440,10 +425,10 @@ public void TypeParameterWithReferenceTypeConstraint() { ITypeParameter t = new DefaultTypeParameter(compilation, SymbolKind.TypeDefinition, 0, "T", hasReferenceTypeConstraint: true); - Assert.AreEqual(C.NullLiteralConversion, conversions.ImplicitConversion(SpecialType.NullType, t)); - Assert.AreEqual(C.ImplicitReferenceConversion, conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object))); - Assert.AreEqual(C.ImplicitReferenceConversion, conversions.ImplicitConversion(t, SpecialType.Dynamic)); - Assert.AreEqual(C.None, conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType)))); + Assert.That(conversions.ImplicitConversion(SpecialType.NullType, t), Is.EqualTo(C.NullLiteralConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(conversions.ImplicitConversion(t, SpecialType.Dynamic), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType))), Is.EqualTo(C.None)); } [Test] @@ -451,10 +436,10 @@ public void TypeParameterWithValueTypeConstraint() { ITypeParameter t = new DefaultTypeParameter(compilation, SymbolKind.TypeDefinition, 0, "T", hasValueTypeConstraint: true); - Assert.AreEqual(C.None, conversions.ImplicitConversion(SpecialType.NullType, t)); - Assert.AreEqual(C.BoxingConversion, conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object))); - Assert.AreEqual(C.BoxingConversion, conversions.ImplicitConversion(t, SpecialType.Dynamic)); - Assert.AreEqual(C.BoxingConversion, conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType)))); + Assert.That(conversions.ImplicitConversion(SpecialType.NullType, t), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object)), Is.EqualTo(C.BoxingConversion)); + Assert.That(conversions.ImplicitConversion(t, SpecialType.Dynamic), Is.EqualTo(C.BoxingConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType))), Is.EqualTo(C.BoxingConversion)); } [Test] @@ -463,20 +448,14 @@ public void TypeParameterWithClassConstraint() ITypeParameter t = new DefaultTypeParameter(compilation, SymbolKind.TypeDefinition, 0, "T", constraints: new[] { compilation.FindType(typeof(StringComparer)) }); - Assert.AreEqual(C.NullLiteralConversion, - conversions.ImplicitConversion(SpecialType.NullType, t)); - Assert.AreEqual(C.ImplicitReferenceConversion, - conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object))); - Assert.AreEqual(C.ImplicitReferenceConversion, - conversions.ImplicitConversion(t, SpecialType.Dynamic)); - Assert.AreEqual(C.None, conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType)))); - Assert.AreEqual(C.ImplicitReferenceConversion, - conversions.ImplicitConversion(t, compilation.FindType(typeof(StringComparer)))); - Assert.AreEqual(C.ImplicitReferenceConversion, - conversions.ImplicitConversion(t, compilation.FindType(typeof(IComparer)))); - Assert.AreEqual(C.None, conversions.ImplicitConversion(t, compilation.FindType(typeof(IComparer)))); - Assert.AreEqual(C.ImplicitReferenceConversion, - conversions.ImplicitConversion(t, compilation.FindType(typeof(IComparer)))); + Assert.That(conversions.ImplicitConversion(SpecialType.NullType, t), Is.EqualTo(C.NullLiteralConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(conversions.ImplicitConversion(t, SpecialType.Dynamic), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType))), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(StringComparer))), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(IComparer))), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(IComparer))), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(IComparer))), Is.EqualTo(C.ImplicitReferenceConversion)); } [Test] @@ -485,26 +464,22 @@ public void TypeParameterWithInterfaceConstraint() ITypeParameter t = new DefaultTypeParameter(compilation, SymbolKind.TypeDefinition, 0, "T", constraints: new[] { compilation.FindType(typeof(IList)) }); - Assert.AreEqual(C.None, conversions.ImplicitConversion(SpecialType.NullType, t)); - Assert.AreEqual(C.BoxingConversion, - conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object))); - Assert.AreEqual(C.BoxingConversion, - conversions.ImplicitConversion(t, SpecialType.Dynamic)); - Assert.AreEqual(C.None, conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType)))); - Assert.AreEqual(C.BoxingConversion, - conversions.ImplicitConversion(t, compilation.FindType(typeof(IList)))); - Assert.AreEqual(C.BoxingConversion, - conversions.ImplicitConversion(t, compilation.FindType(typeof(IEnumerable)))); + Assert.That(conversions.ImplicitConversion(SpecialType.NullType, t), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(KnownTypeCode.Object)), Is.EqualTo(C.BoxingConversion)); + Assert.That(conversions.ImplicitConversion(t, SpecialType.Dynamic), Is.EqualTo(C.BoxingConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(ValueType))), Is.EqualTo(C.None)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(IList))), Is.EqualTo(C.BoxingConversion)); + Assert.That(conversions.ImplicitConversion(t, compilation.FindType(typeof(IEnumerable))), Is.EqualTo(C.BoxingConversion)); } [Test] public void UserDefinedImplicitConversion() { Conversion c = ImplicitConversion(typeof(DateTime), typeof(DateTimeOffset)); - Assert.IsTrue(c.IsImplicit && c.IsUserDefined); - Assert.AreEqual("System.DateTimeOffset.op_Implicit", c.Method.FullName); + Assert.That(c.IsImplicit && c.IsUserDefined); + Assert.That(c.Method.FullName, Is.EqualTo("System.DateTimeOffset.op_Implicit")); - Assert.AreEqual(C.None, ImplicitConversion(typeof(DateTimeOffset), typeof(DateTime))); + Assert.That(ImplicitConversion(typeof(DateTimeOffset), typeof(DateTime)), Is.EqualTo(C.None)); } [Test] @@ -512,14 +487,14 @@ public void UserDefinedImplicitNullableConversion() { // User-defined conversion followed by nullable conversion Conversion c = ImplicitConversion(typeof(DateTime), typeof(DateTimeOffset?)); - Assert.IsTrue(c.IsValid && c.IsUserDefined); - Assert.IsFalse(c.IsLifted); + Assert.That(c.IsValid && c.IsUserDefined); + Assert.That(!c.IsLifted); // Lifted user-defined conversion c = ImplicitConversion(typeof(DateTime?), typeof(DateTimeOffset?)); - Assert.IsTrue(c.IsValid && c.IsUserDefined && c.IsLifted); + Assert.That(c.IsValid && c.IsUserDefined && c.IsLifted); // User-defined conversion doesn't drop the nullability c = ImplicitConversion(typeof(DateTime?), typeof(DateTimeOffset)); - Assert.IsFalse(c.IsValid); + Assert.That(!c.IsValid); } bool IntegerLiteralConversion(object value, Type to) @@ -533,71 +508,71 @@ bool IntegerLiteralConversion(object value, Type to) [Test] public void IntegerLiteralToEnumConversions() { - Assert.IsTrue(IntegerLiteralConversion(0, typeof(LoaderOptimization))); - Assert.IsTrue(IntegerLiteralConversion(0L, typeof(LoaderOptimization))); - Assert.IsTrue(IntegerLiteralConversion(0, typeof(LoaderOptimization?))); - Assert.IsFalse(IntegerLiteralConversion(0, typeof(string))); - Assert.IsFalse(IntegerLiteralConversion(1, typeof(LoaderOptimization))); + Assert.That(IntegerLiteralConversion(0, typeof(LoaderOptimization))); + Assert.That(IntegerLiteralConversion(0L, typeof(LoaderOptimization))); + Assert.That(IntegerLiteralConversion(0, typeof(LoaderOptimization?))); + Assert.That(!IntegerLiteralConversion(0, typeof(string))); + Assert.That(!IntegerLiteralConversion(1, typeof(LoaderOptimization))); } [Test] public void ImplicitConstantExpressionConversion() { - Assert.IsTrue(IntegerLiteralConversion(0, typeof(int))); - Assert.IsTrue(IntegerLiteralConversion(0, typeof(ushort))); - Assert.IsTrue(IntegerLiteralConversion(0, typeof(sbyte))); + Assert.That(IntegerLiteralConversion(0, typeof(int))); + Assert.That(IntegerLiteralConversion(0, typeof(ushort))); + Assert.That(IntegerLiteralConversion(0, typeof(sbyte))); - Assert.IsTrue(IntegerLiteralConversion(-1, typeof(int))); - Assert.IsFalse(IntegerLiteralConversion(-1, typeof(ushort))); - Assert.IsTrue(IntegerLiteralConversion(-1, typeof(sbyte))); + Assert.That(IntegerLiteralConversion(-1, typeof(int))); + Assert.That(!IntegerLiteralConversion(-1, typeof(ushort))); + Assert.That(IntegerLiteralConversion(-1, typeof(sbyte))); - Assert.IsTrue(IntegerLiteralConversion(200, typeof(int))); - Assert.IsTrue(IntegerLiteralConversion(200, typeof(ushort))); - Assert.IsFalse(IntegerLiteralConversion(200, typeof(sbyte))); + Assert.That(IntegerLiteralConversion(200, typeof(int))); + Assert.That(IntegerLiteralConversion(200, typeof(ushort))); + Assert.That(!IntegerLiteralConversion(200, typeof(sbyte))); } [Test] public void ImplicitLongConstantExpressionConversion() { - Assert.IsFalse(IntegerLiteralConversion(0L, typeof(int))); - Assert.IsFalse(IntegerLiteralConversion(0L, typeof(short))); - Assert.IsTrue(IntegerLiteralConversion(0L, typeof(long))); - Assert.IsTrue(IntegerLiteralConversion(0L, typeof(ulong))); + Assert.That(!IntegerLiteralConversion(0L, typeof(int))); + Assert.That(!IntegerLiteralConversion(0L, typeof(short))); + Assert.That(IntegerLiteralConversion(0L, typeof(long))); + Assert.That(IntegerLiteralConversion(0L, typeof(ulong))); - Assert.IsTrue(IntegerLiteralConversion(-1L, typeof(long))); - Assert.IsFalse(IntegerLiteralConversion(-1L, typeof(ulong))); + Assert.That(IntegerLiteralConversion(-1L, typeof(long))); + Assert.That(!IntegerLiteralConversion(-1L, typeof(ulong))); } [Test] public void ImplicitConstantExpressionConversionToNullable() { - Assert.IsTrue(IntegerLiteralConversion(0, typeof(uint?))); - Assert.IsTrue(IntegerLiteralConversion(0, typeof(short?))); - Assert.IsTrue(IntegerLiteralConversion(0, typeof(byte?))); + Assert.That(IntegerLiteralConversion(0, typeof(uint?))); + Assert.That(IntegerLiteralConversion(0, typeof(short?))); + Assert.That(IntegerLiteralConversion(0, typeof(byte?))); - Assert.IsFalse(IntegerLiteralConversion(-1, typeof(uint?))); - Assert.IsTrue(IntegerLiteralConversion(-1, typeof(short?))); - Assert.IsFalse(IntegerLiteralConversion(-1, typeof(byte?))); + Assert.That(!IntegerLiteralConversion(-1, typeof(uint?))); + Assert.That(IntegerLiteralConversion(-1, typeof(short?))); + Assert.That(!IntegerLiteralConversion(-1, typeof(byte?))); - Assert.IsTrue(IntegerLiteralConversion(200, typeof(uint?))); - Assert.IsTrue(IntegerLiteralConversion(200, typeof(short?))); - Assert.IsTrue(IntegerLiteralConversion(200, typeof(byte?))); + Assert.That(IntegerLiteralConversion(200, typeof(uint?))); + Assert.That(IntegerLiteralConversion(200, typeof(short?))); + Assert.That(IntegerLiteralConversion(200, typeof(byte?))); - Assert.IsFalse(IntegerLiteralConversion(0L, typeof(uint?))); - Assert.IsTrue(IntegerLiteralConversion(0L, typeof(long?))); - Assert.IsTrue(IntegerLiteralConversion(0L, typeof(ulong?))); + Assert.That(!IntegerLiteralConversion(0L, typeof(uint?))); + Assert.That(IntegerLiteralConversion(0L, typeof(long?))); + Assert.That(IntegerLiteralConversion(0L, typeof(ulong?))); - Assert.IsTrue(IntegerLiteralConversion(-1L, typeof(long?))); - Assert.IsFalse(IntegerLiteralConversion(-1L, typeof(ulong?))); + Assert.That(IntegerLiteralConversion(-1L, typeof(long?))); + Assert.That(!IntegerLiteralConversion(-1L, typeof(ulong?))); } [Test] public void ImplicitConstantExpressionConversionNumberInterfaces() { - Assert.IsTrue(IntegerLiteralConversion(0, typeof(IFormattable))); - Assert.IsTrue(IntegerLiteralConversion(0, typeof(IComparable))); - Assert.IsFalse(IntegerLiteralConversion(0, typeof(IComparable))); - Assert.IsFalse(IntegerLiteralConversion(0, typeof(IComparable))); + Assert.That(IntegerLiteralConversion(0, typeof(IFormattable))); + Assert.That(IntegerLiteralConversion(0, typeof(IComparable))); + Assert.That(!IntegerLiteralConversion(0, typeof(IComparable))); + Assert.That(!IntegerLiteralConversion(0, typeof(IComparable))); } int BetterConversion(Type s, Type t1, Type t2) @@ -620,39 +595,39 @@ int BetterConversion(object value, Type t1, Type t2) [Test] public void BetterConversion() { - Assert.AreEqual(1, BetterConversion(typeof(string), typeof(string), typeof(object))); - Assert.AreEqual(2, BetterConversion(typeof(string), typeof(object), typeof(IComparable))); - Assert.AreEqual(0, BetterConversion(typeof(string), typeof(IEnumerable), typeof(IComparable))); + Assert.That(BetterConversion(typeof(string), typeof(string), typeof(object)), Is.EqualTo(1)); + Assert.That(BetterConversion(typeof(string), typeof(object), typeof(IComparable)), Is.EqualTo(2)); + Assert.That(BetterConversion(typeof(string), typeof(IEnumerable), typeof(IComparable)), Is.EqualTo(0)); } [Test] public void BetterPrimitiveConversion() { - Assert.AreEqual(1, BetterConversion(typeof(short), typeof(int), typeof(long))); - Assert.AreEqual(1, BetterConversion(typeof(short), typeof(int), typeof(uint))); - Assert.AreEqual(2, BetterConversion(typeof(ushort), typeof(uint), typeof(int))); - Assert.AreEqual(1, BetterConversion(typeof(char), typeof(short), typeof(int))); - Assert.AreEqual(1, BetterConversion(typeof(char), typeof(ushort), typeof(int))); - Assert.AreEqual(1, BetterConversion(typeof(sbyte), typeof(long), typeof(ulong))); - Assert.AreEqual(2, BetterConversion(typeof(byte), typeof(ushort), typeof(short))); + Assert.That(BetterConversion(typeof(short), typeof(int), typeof(long)), Is.EqualTo(1)); + Assert.That(BetterConversion(typeof(short), typeof(int), typeof(uint)), Is.EqualTo(1)); + Assert.That(BetterConversion(typeof(ushort), typeof(uint), typeof(int)), Is.EqualTo(2)); + Assert.That(BetterConversion(typeof(char), typeof(short), typeof(int)), Is.EqualTo(1)); + Assert.That(BetterConversion(typeof(char), typeof(ushort), typeof(int)), Is.EqualTo(1)); + Assert.That(BetterConversion(typeof(sbyte), typeof(long), typeof(ulong)), Is.EqualTo(1)); + Assert.That(BetterConversion(typeof(byte), typeof(ushort), typeof(short)), Is.EqualTo(2)); - Assert.AreEqual(1, BetterConversion(1, typeof(sbyte), typeof(byte))); - Assert.AreEqual(2, BetterConversion(1, typeof(ushort), typeof(sbyte))); + Assert.That(BetterConversion(1, typeof(sbyte), typeof(byte)), Is.EqualTo(1)); + Assert.That(BetterConversion(1, typeof(ushort), typeof(sbyte)), Is.EqualTo(2)); } [Test] public void BetterNullableConversion() { - Assert.AreEqual(0, BetterConversion(typeof(byte), typeof(int), typeof(uint?))); - Assert.AreEqual(0, BetterConversion(typeof(byte?), typeof(int?), typeof(uint?))); - Assert.AreEqual(1, BetterConversion(typeof(byte), typeof(ushort?), typeof(uint?))); - Assert.AreEqual(2, BetterConversion(typeof(byte?), typeof(ulong?), typeof(uint?))); - Assert.AreEqual(0, BetterConversion(typeof(byte), typeof(ushort?), typeof(uint))); - Assert.AreEqual(0, BetterConversion(typeof(byte), typeof(ushort?), typeof(int))); - Assert.AreEqual(2, BetterConversion(typeof(byte), typeof(ulong?), typeof(uint))); - Assert.AreEqual(0, BetterConversion(typeof(byte), typeof(ulong?), typeof(int))); - Assert.AreEqual(2, BetterConversion(typeof(ushort?), typeof(long?), typeof(int?))); - Assert.AreEqual(0, BetterConversion(typeof(sbyte), typeof(int?), typeof(uint?))); + Assert.That(BetterConversion(typeof(byte), typeof(int), typeof(uint?)), Is.EqualTo(0)); + Assert.That(BetterConversion(typeof(byte?), typeof(int?), typeof(uint?)), Is.EqualTo(0)); + Assert.That(BetterConversion(typeof(byte), typeof(ushort?), typeof(uint?)), Is.EqualTo(1)); + Assert.That(BetterConversion(typeof(byte?), typeof(ulong?), typeof(uint?)), Is.EqualTo(2)); + Assert.That(BetterConversion(typeof(byte), typeof(ushort?), typeof(uint)), Is.EqualTo(0)); + Assert.That(BetterConversion(typeof(byte), typeof(ushort?), typeof(int)), Is.EqualTo(0)); + Assert.That(BetterConversion(typeof(byte), typeof(ulong?), typeof(uint)), Is.EqualTo(2)); + Assert.That(BetterConversion(typeof(byte), typeof(ulong?), typeof(int)), Is.EqualTo(0)); + Assert.That(BetterConversion(typeof(ushort?), typeof(long?), typeof(int?)), Is.EqualTo(2)); + Assert.That(BetterConversion(typeof(sbyte), typeof(int?), typeof(uint?)), Is.EqualTo(0)); } /* TODO: we should probably revive these tests somehow @@ -678,7 +653,7 @@ public void ExpansiveInheritance() IType type1 = new ParameterizedType(resolvedB, new[] { compilation.FindType(KnownTypeCode.Double) }); IType type2 = new ParameterizedType(resolvedA, new[] { new ParameterizedType(resolvedB, new[] { compilation.FindType(KnownTypeCode.String) }) }); - Assert.IsFalse(conversions.ImplicitConversion(type1, type2).IsValid); + Assert.That(!conversions.ImplicitConversion(type1, type2).IsValid); } [Test] @@ -776,9 +751,9 @@ class Test { public static void M() {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); - Assert.IsFalse(c.DelegateCapturesFirstArgument); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); + Assert.That(!c.DelegateCapturesFirstArgument); Assert.IsNotNull(c.Method); } @@ -794,9 +769,9 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); - Assert.IsTrue(c.DelegateCapturesFirstArgument); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); + Assert.That(c.DelegateCapturesFirstArgument); Assert.IsNotNull(c.Method); } @@ -810,8 +785,8 @@ class Test { public static object M(int argument) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); } [Test] @@ -824,8 +799,8 @@ class Test { public static int M(int argument) {} }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(!c.IsValid); + Assert.That(c.IsMethodGroupConversion); } [Test] @@ -838,8 +813,8 @@ class Test { public static string M(int argument) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); } [Test] @@ -852,8 +827,8 @@ class Test { public static void M(ref object o) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); } [Test] @@ -866,8 +841,8 @@ class Test { public static void M(ref dynamic o) {} }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(!c.IsValid); + Assert.That(c.IsMethodGroupConversion); } [Test] @@ -880,7 +855,7 @@ class Test { public static void M(out object o) {} }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); + Assert.That(!c.IsValid); } [Test] @@ -893,7 +868,7 @@ class Test { public static void M(object o) {} }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); + Assert.That(!c.IsValid); } [Test] @@ -906,7 +881,7 @@ class Test { public static void M(out object o) {} }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); + Assert.That(!c.IsValid); } [Test] @@ -919,8 +894,8 @@ class Test { public static void M(object o) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); } [Test] @@ -933,8 +908,8 @@ class Test { public static void M(dynamic o) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); } [Test] @@ -947,8 +922,8 @@ class Test { public static void M(object o) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); } @@ -963,7 +938,7 @@ public static void M(dynamic o) {} }"; var c = GetConversion(program); //Assert.IsFrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsMethodGroupConversion); } [Test] @@ -977,8 +952,8 @@ static void M(object x) {} static void M(string x = null) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); Assert.AreEqual("System.String", c.Method.Parameters.Single().Type.FullName); } @@ -993,8 +968,8 @@ static void M(object x) {} static void M(string x, string y = null) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); Assert.AreEqual("System.Object", c.Method.Parameters.Single().Type.FullName); } @@ -1009,8 +984,8 @@ static void M(object x) {} static void M(params string[] x) {} }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); Assert.AreEqual("System.Object", c.Method.Parameters.Single().Type.FullName); } @@ -1029,9 +1004,9 @@ void F() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); - Assert.IsTrue(c.DelegateCapturesFirstArgument); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); + Assert.That(c.DelegateCapturesFirstArgument); } [Test] @@ -1048,9 +1023,9 @@ void F() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsMethodGroupConversion); - Assert.IsFalse(c.DelegateCapturesFirstArgument); + Assert.That(c.IsValid); + Assert.That(c.IsMethodGroupConversion); + Assert.That(!c.DelegateCapturesFirstArgument); } [Test] @@ -1064,7 +1039,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); + Assert.That(c.IsValid); } [Test] @@ -1079,7 +1054,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); + Assert.That(c.IsValid); } [Test] @@ -1093,7 +1068,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); + Assert.That(c.IsValid); } [Test] @@ -1107,7 +1082,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); + Assert.That(c.IsValid); } [Test] @@ -1122,7 +1097,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); + Assert.That(c.IsValid); } [Test] @@ -1136,7 +1111,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); + Assert.That(c.IsValid); } [Test] @@ -1152,8 +1127,8 @@ static void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); } [Test] @@ -1170,8 +1145,8 @@ static void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); } @@ -1189,9 +1164,9 @@ static void M(S? s) { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); - Assert.IsTrue(c.IsLifted); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); + Assert.That(c.IsLifted); } [Test] @@ -1208,8 +1183,8 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("i", c.Method.Parameters[0].Name); } @@ -1227,8 +1202,8 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("ui", c.Method.Parameters[0].Name); } @@ -1246,7 +1221,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); + Assert.That(!c.IsValid); } [Test] @@ -1263,8 +1238,8 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("i", c.Method.Parameters[0].Name); } @@ -1282,8 +1257,8 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("us", c.Method.Parameters[0].Name); } @@ -1301,7 +1276,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); + Assert.That(!c.IsValid); } [Test] @@ -1320,7 +1295,7 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); + Assert.That(!c.IsValid); } [Test] @@ -1337,9 +1312,9 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); - Assert.IsFalse(c.IsLifted); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); + Assert.That(!c.IsLifted); Assert.AreEqual("ni", c.Method.Parameters[0].Name); } @@ -1357,8 +1332,8 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("ui", c.Method.Parameters[0].Name); } @@ -1376,8 +1351,8 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("ui", c.Method.Parameters[0].Name); } @@ -1396,8 +1371,8 @@ public static void Main(string[] args) } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("System.Int16", c.Method.ReturnType.FullName); } @@ -1416,8 +1391,8 @@ public static void Main(string[] args) } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("System.Int16", c.Method.ReturnType.FullName); } @@ -1436,8 +1411,8 @@ public static void Main(string[] args) } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("s", c.Method.Parameters[0].Name); } @@ -1456,8 +1431,8 @@ static void Main() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("i", c.Method.Parameters[0].Name); } @@ -1476,8 +1451,8 @@ static void Main() { } }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(!c.IsValid); + Assert.That(c.IsUserDefined); } [Test] @@ -1494,8 +1469,8 @@ static void Main() { } }"; var c = GetConversion(program); - Assert.IsFalse(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(!c.IsValid); + Assert.That(c.IsUserDefined); } [Test] @@ -1513,8 +1488,8 @@ static void Main() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsUserDefined); + Assert.That(c.IsValid); + Assert.That(c.IsUserDefined); Assert.AreEqual("i", c.Method.Parameters[0].Name); } @@ -1537,7 +1512,7 @@ static void Main() { }"; var rr = Resolve(program); - Assert.IsFalse(rr.IsError); + Assert.That(!rr.IsError); Assert.AreEqual("str", rr.Member.Parameters[0].Name); } @@ -1566,8 +1541,8 @@ static void Main() { }"; var c = GetConversion(program); - Assert.IsTrue(c.IsUserDefined); - Assert.IsFalse(c.IsValid); + Assert.That(c.IsUserDefined); + Assert.That(!c.IsValid); } [Test] @@ -1584,11 +1559,11 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.ConversionBeforeUserDefinedOperator.IsImplicit); - Assert.IsTrue(c.ConversionBeforeUserDefinedOperator.IsNumericConversion); - Assert.IsTrue(c.ConversionBeforeUserDefinedOperator.IsValid); - Assert.IsTrue(c.ConversionAfterUserDefinedOperator.IsIdentityConversion); + Assert.That(c.IsValid); + Assert.That(c.ConversionBeforeUserDefinedOperator.IsImplicit); + Assert.That(c.ConversionBeforeUserDefinedOperator.IsNumericConversion); + Assert.That(c.ConversionBeforeUserDefinedOperator.IsValid); + Assert.That(c.ConversionAfterUserDefinedOperator.IsIdentityConversion); } [Test] @@ -1604,11 +1579,11 @@ public void M() { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.ConversionBeforeUserDefinedOperator.IsIdentityConversion); - Assert.IsTrue(c.ConversionAfterUserDefinedOperator.IsImplicit); - Assert.IsTrue(c.ConversionAfterUserDefinedOperator.IsNumericConversion); - Assert.IsTrue(c.ConversionAfterUserDefinedOperator.IsValid); + Assert.That(c.IsValid); + Assert.That(c.ConversionBeforeUserDefinedOperator.IsIdentityConversion); + Assert.That(c.ConversionAfterUserDefinedOperator.IsImplicit); + Assert.That(c.ConversionAfterUserDefinedOperator.IsNumericConversion); + Assert.That(c.ConversionAfterUserDefinedOperator.IsValid); } [Test] @@ -1627,9 +1602,9 @@ public static implicit operator JsNumber3(int d) { } }"; var c = GetConversion(program); - Assert.IsTrue(c.IsValid); - Assert.IsTrue(c.IsImplicit); - Assert.IsFalse(c.IsExplicit); + Assert.That(c.IsValid); + Assert.That(c.IsImplicit); + Assert.That(!c.IsExplicit); Assert.AreEqual(Conversion.IdentityConversion, c.ConversionBeforeUserDefinedOperator); Assert.AreEqual(Conversion.IdentityConversion, c.ConversionAfterUserDefinedOperator); } diff --git a/ICSharpCode.Decompiler.Tests/Semantics/ExplicitConversionTest.cs b/ICSharpCode.Decompiler.Tests/Semantics/ExplicitConversionTest.cs index f2bb2b4403..0abed50b61 100644 --- a/ICSharpCode.Decompiler.Tests/Semantics/ExplicitConversionTest.cs +++ b/ICSharpCode.Decompiler.Tests/Semantics/ExplicitConversionTest.cs @@ -58,11 +58,11 @@ Conversion ExplicitConversion(Type from, Type to) [Test] public void PointerConversion() { - Assert.AreEqual(C.ExplicitPointerConversion, ExplicitConversion(typeof(int*), typeof(short))); - Assert.AreEqual(C.ExplicitPointerConversion, ExplicitConversion(typeof(short), typeof(void*))); + Assert.That(ExplicitConversion(typeof(int*), typeof(short)), Is.EqualTo(C.ExplicitPointerConversion)); + Assert.That(ExplicitConversion(typeof(short), typeof(void*)), Is.EqualTo(C.ExplicitPointerConversion)); - Assert.AreEqual(C.ExplicitPointerConversion, ExplicitConversion(typeof(void*), typeof(int*))); - Assert.AreEqual(C.ExplicitPointerConversion, ExplicitConversion(typeof(long*), typeof(byte*))); + Assert.That(ExplicitConversion(typeof(void*), typeof(int*)), Is.EqualTo(C.ExplicitPointerConversion)); + Assert.That(ExplicitConversion(typeof(long*), typeof(byte*)), Is.EqualTo(C.ExplicitPointerConversion)); } [Test] @@ -70,60 +70,60 @@ public void ConversionFromDynamic() { // Explicit dynamic conversion is for resolve results only; // otherwise it's an explicit reference / unboxing conversion - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(dynamic), typeof(string))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(dynamic), typeof(int))); + Assert.That(ExplicitConversion(typeof(dynamic), typeof(string)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(dynamic), typeof(int)), Is.EqualTo(C.UnboxingConversion)); var dynamicRR = new ResolveResult(SpecialType.Dynamic); - Assert.AreEqual(C.ExplicitDynamicConversion, conversions.ExplicitConversion(dynamicRR, compilation.FindType(typeof(string)))); - Assert.AreEqual(C.ExplicitDynamicConversion, conversions.ExplicitConversion(dynamicRR, compilation.FindType(typeof(int)))); + Assert.That(conversions.ExplicitConversion(dynamicRR, compilation.FindType(typeof(string))), Is.EqualTo(C.ExplicitDynamicConversion)); + Assert.That(conversions.ExplicitConversion(dynamicRR, compilation.FindType(typeof(int))), Is.EqualTo(C.ExplicitDynamicConversion)); } [Test] public void NumericConversions() { - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(sbyte), typeof(uint))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(sbyte), typeof(char))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(byte), typeof(char))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(byte), typeof(sbyte))); + Assert.That(ExplicitConversion(typeof(sbyte), typeof(uint)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(sbyte), typeof(char)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(byte), typeof(char)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(byte), typeof(sbyte)), Is.EqualTo(C.ExplicitNumericConversion)); // if an implicit conversion exists, ExplicitConversion() should return that - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(byte), typeof(int))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(double), typeof(float))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(double), typeof(decimal))); - Assert.AreEqual(C.ExplicitNumericConversion, ExplicitConversion(typeof(decimal), typeof(double))); - Assert.AreEqual(C.ImplicitNumericConversion, ExplicitConversion(typeof(int), typeof(decimal))); + Assert.That(ExplicitConversion(typeof(byte), typeof(int)), Is.EqualTo(C.ImplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(double), typeof(float)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(double), typeof(decimal)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(decimal), typeof(double)), Is.EqualTo(C.ExplicitNumericConversion)); + Assert.That(ExplicitConversion(typeof(int), typeof(decimal)), Is.EqualTo(C.ImplicitNumericConversion)); - Assert.AreEqual(C.None, ExplicitConversion(typeof(bool), typeof(int))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(int), typeof(bool))); + Assert.That(ExplicitConversion(typeof(bool), typeof(int)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(int), typeof(bool)), Is.EqualTo(C.None)); } [Test] public void EnumerationConversions() { var explicitEnumerationConversion = C.EnumerationConversion(false, false); - Assert.AreEqual(explicitEnumerationConversion, ExplicitConversion(typeof(sbyte), typeof(StringComparison))); - Assert.AreEqual(explicitEnumerationConversion, ExplicitConversion(typeof(char), typeof(StringComparison))); - Assert.AreEqual(explicitEnumerationConversion, ExplicitConversion(typeof(int), typeof(StringComparison))); - Assert.AreEqual(explicitEnumerationConversion, ExplicitConversion(typeof(decimal), typeof(StringComparison))); - Assert.AreEqual(explicitEnumerationConversion, ExplicitConversion(typeof(StringComparison), typeof(char))); - Assert.AreEqual(explicitEnumerationConversion, ExplicitConversion(typeof(StringComparison), typeof(int))); - Assert.AreEqual(explicitEnumerationConversion, ExplicitConversion(typeof(StringComparison), typeof(decimal))); - Assert.AreEqual(explicitEnumerationConversion, ExplicitConversion(typeof(StringComparison), typeof(StringSplitOptions))); + Assert.That(ExplicitConversion(typeof(sbyte), typeof(StringComparison)), Is.EqualTo(explicitEnumerationConversion)); + Assert.That(ExplicitConversion(typeof(char), typeof(StringComparison)), Is.EqualTo(explicitEnumerationConversion)); + Assert.That(ExplicitConversion(typeof(int), typeof(StringComparison)), Is.EqualTo(explicitEnumerationConversion)); + Assert.That(ExplicitConversion(typeof(decimal), typeof(StringComparison)), Is.EqualTo(explicitEnumerationConversion)); + Assert.That(ExplicitConversion(typeof(StringComparison), typeof(char)), Is.EqualTo(explicitEnumerationConversion)); + Assert.That(ExplicitConversion(typeof(StringComparison), typeof(int)), Is.EqualTo(explicitEnumerationConversion)); + Assert.That(ExplicitConversion(typeof(StringComparison), typeof(decimal)), Is.EqualTo(explicitEnumerationConversion)); + Assert.That(ExplicitConversion(typeof(StringComparison), typeof(StringSplitOptions)), Is.EqualTo(explicitEnumerationConversion)); } [Test] public void NullableConversion_BasedOnIdentityConversion() { - Assert.AreEqual(C.IdentityConversion, ExplicitConversion(typeof(ArraySegment?), typeof(ArraySegment?))); - Assert.AreEqual(C.ImplicitNullableConversion, ExplicitConversion(typeof(ArraySegment), typeof(ArraySegment?))); - Assert.AreEqual(C.ExplicitNullableConversion, ExplicitConversion(typeof(ArraySegment?), typeof(ArraySegment))); + Assert.That(ExplicitConversion(typeof(ArraySegment?), typeof(ArraySegment?)), Is.EqualTo(C.IdentityConversion)); + Assert.That(ExplicitConversion(typeof(ArraySegment), typeof(ArraySegment?)), Is.EqualTo(C.ImplicitNullableConversion)); + Assert.That(ExplicitConversion(typeof(ArraySegment?), typeof(ArraySegment)), Is.EqualTo(C.ExplicitNullableConversion)); } [Test] public void NullableConversion_BasedOnImplicitNumericConversion() { - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ExplicitConversion(typeof(int?), typeof(long?))); - Assert.AreEqual(C.ImplicitLiftedNumericConversion, ExplicitConversion(typeof(int), typeof(long?))); - Assert.AreEqual(C.ExplicitLiftedNumericConversion, ExplicitConversion(typeof(int?), typeof(long))); + Assert.That(ExplicitConversion(typeof(int?), typeof(long?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ExplicitConversion(typeof(int), typeof(long?)), Is.EqualTo(C.ImplicitLiftedNumericConversion)); + Assert.That(ExplicitConversion(typeof(int?), typeof(long)), Is.EqualTo(C.ExplicitLiftedNumericConversion)); } [Test] @@ -131,160 +131,160 @@ public void NullableConversion_BasedOnImplicitEnumerationConversion() { ResolveResult zero = new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 0); ResolveResult one = new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 1); - Assert.AreEqual(C.EnumerationConversion(true, true), conversions.ExplicitConversion(zero, compilation.FindType(typeof(StringComparison?)))); - Assert.AreEqual(C.EnumerationConversion(false, true), conversions.ExplicitConversion(one, compilation.FindType(typeof(StringComparison?)))); + Assert.That(conversions.ExplicitConversion(zero, compilation.FindType(typeof(StringComparison?))), Is.EqualTo(C.EnumerationConversion(true, true))); + Assert.That(conversions.ExplicitConversion(one, compilation.FindType(typeof(StringComparison?))), Is.EqualTo(C.EnumerationConversion(false, true))); } [Test] public void NullableConversion_BasedOnExplicitNumericConversion() { - Assert.AreEqual(C.ExplicitLiftedNumericConversion, ExplicitConversion(typeof(int?), typeof(short?))); - Assert.AreEqual(C.ExplicitLiftedNumericConversion, ExplicitConversion(typeof(int), typeof(short?))); - Assert.AreEqual(C.ExplicitLiftedNumericConversion, ExplicitConversion(typeof(int?), typeof(short))); + Assert.That(ExplicitConversion(typeof(int?), typeof(short?)), Is.EqualTo(C.ExplicitLiftedNumericConversion)); + Assert.That(ExplicitConversion(typeof(int), typeof(short?)), Is.EqualTo(C.ExplicitLiftedNumericConversion)); + Assert.That(ExplicitConversion(typeof(int?), typeof(short)), Is.EqualTo(C.ExplicitLiftedNumericConversion)); } [Test] public void NullableConversion_BasedOnExplicitEnumerationConversion() { C c = C.EnumerationConversion(false, true); // c = explicit lifted enumeration conversion - Assert.AreEqual(c, ExplicitConversion(typeof(int?), typeof(StringComparison?))); - Assert.AreEqual(c, ExplicitConversion(typeof(int), typeof(StringComparison?))); - Assert.AreEqual(c, ExplicitConversion(typeof(int?), typeof(StringComparison))); + Assert.That(ExplicitConversion(typeof(int?), typeof(StringComparison?)), Is.EqualTo(c)); + Assert.That(ExplicitConversion(typeof(int), typeof(StringComparison?)), Is.EqualTo(c)); + Assert.That(ExplicitConversion(typeof(int?), typeof(StringComparison)), Is.EqualTo(c)); - Assert.AreEqual(c, ExplicitConversion(typeof(StringComparison?), typeof(int?))); - Assert.AreEqual(c, ExplicitConversion(typeof(StringComparison), typeof(int?))); - Assert.AreEqual(c, ExplicitConversion(typeof(StringComparison?), typeof(int))); + Assert.That(ExplicitConversion(typeof(StringComparison?), typeof(int?)), Is.EqualTo(c)); + Assert.That(ExplicitConversion(typeof(StringComparison), typeof(int?)), Is.EqualTo(c)); + Assert.That(ExplicitConversion(typeof(StringComparison?), typeof(int)), Is.EqualTo(c)); - Assert.AreEqual(c, ExplicitConversion(typeof(StringComparison?), typeof(StringSplitOptions?))); - Assert.AreEqual(c, ExplicitConversion(typeof(StringComparison), typeof(StringSplitOptions?))); - Assert.AreEqual(c, ExplicitConversion(typeof(StringComparison?), typeof(StringSplitOptions))); + Assert.That(ExplicitConversion(typeof(StringComparison?), typeof(StringSplitOptions?)), Is.EqualTo(c)); + Assert.That(ExplicitConversion(typeof(StringComparison), typeof(StringSplitOptions?)), Is.EqualTo(c)); + Assert.That(ExplicitConversion(typeof(StringComparison?), typeof(StringSplitOptions)), Is.EqualTo(c)); } [Test] public void ExplicitReferenceConversion_SealedClass() { - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(object), typeof(string))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(string))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(IEnumerable), typeof(string))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(IEnumerable), typeof(string))); - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(string), typeof(IEnumerable))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(string), typeof(IEnumerable))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(string), typeof(IEnumerable))); + Assert.That(ExplicitConversion(typeof(object), typeof(string)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(string)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(string)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(string)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(string), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(string), typeof(IEnumerable)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(string), typeof(IEnumerable)), Is.EqualTo(C.None)); } [Test] public void ExplicitReferenceConversion_NonSealedClass() { - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(object), typeof(List))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(List))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(List))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(List))); + Assert.That(ExplicitConversion(typeof(object), typeof(List)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(List)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(List)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(List)), Is.EqualTo(C.ExplicitReferenceConversion)); - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(List), typeof(IEnumerable))); - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(List), typeof(IEnumerable))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(List), typeof(IEnumerable))); + Assert.That(ExplicitConversion(typeof(List), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(List), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(List), typeof(IEnumerable)), Is.EqualTo(C.ExplicitReferenceConversion)); - Assert.AreEqual(C.None, ExplicitConversion(typeof(List), typeof(List))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(List), typeof(List))); + Assert.That(ExplicitConversion(typeof(List), typeof(List)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(List), typeof(List)), Is.EqualTo(C.None)); } [Test] public void ExplicitReferenceConversion_Interfaces() { - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(IEnumerable))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(IEnumerable))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(IEnumerable))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(IEnumerable))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(IConvertible))); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(IEnumerable)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(IEnumerable)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(IEnumerable)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(IConvertible)), Is.EqualTo(C.ExplicitReferenceConversion)); } [Test] public void ExplicitReferenceConversion_Arrays() { - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(object[]), typeof(string[]))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(dynamic[]), typeof(string[]))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(object[]), typeof(object[,]))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(object[]), typeof(int[]))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(short[]), typeof(int[]))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(Array), typeof(int[]))); + Assert.That(ExplicitConversion(typeof(object[]), typeof(string[])), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(dynamic[]), typeof(string[])), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(object[]), typeof(object[,])), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(object[]), typeof(int[])), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(short[]), typeof(int[])), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(Array), typeof(int[])), Is.EqualTo(C.ExplicitReferenceConversion)); } [Test] public void ExplicitReferenceConversion_InterfaceToArray() { - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(ICloneable), typeof(int[]))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(string[]))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(string[]))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(object[]))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(dynamic[]))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(IEnumerable), typeof(int[]))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(IEnumerable), typeof(object[,]))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(IEnumerable), typeof(object[]))); + Assert.That(ExplicitConversion(typeof(ICloneable), typeof(int[])), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(string[])), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(string[])), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(object[])), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(dynamic[])), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(int[])), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(object[,])), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(object[])), Is.EqualTo(C.None)); } [Test] public void ExplicitReferenceConversion_ArrayToInterface() { - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(int[]), typeof(ICloneable))); - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(string[]), typeof(IEnumerable))); - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(string[]), typeof(IEnumerable))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(object[]), typeof(IEnumerable))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(dynamic[]), typeof(IEnumerable))); - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(int[]), typeof(IEnumerable))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(object[,]), typeof(IEnumerable))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(object[]), typeof(IEnumerable))); + Assert.That(ExplicitConversion(typeof(int[]), typeof(ICloneable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(string[]), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(string[]), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(object[]), typeof(IEnumerable)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(dynamic[]), typeof(IEnumerable)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(int[]), typeof(IEnumerable)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(object[,]), typeof(IEnumerable)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(object[]), typeof(IEnumerable)), Is.EqualTo(C.None)); } [Test] public void ExplicitReferenceConversion_Delegates() { - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(MulticastDelegate), typeof(Action))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(Delegate), typeof(Action))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(ICloneable), typeof(Action))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(System.Threading.ThreadStart), typeof(Action))); + Assert.That(ExplicitConversion(typeof(MulticastDelegate), typeof(Action)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(Delegate), typeof(Action)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(ICloneable), typeof(Action)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(System.Threading.ThreadStart), typeof(Action)), Is.EqualTo(C.None)); } [Test] public void ExplicitReferenceConversion_GenericDelegates() { - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(Action), typeof(Action))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(Action), typeof(Action))); + Assert.That(ExplicitConversion(typeof(Action), typeof(Action)), Is.EqualTo(C.ImplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(Action), typeof(Action)), Is.EqualTo(C.ExplicitReferenceConversion)); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(Func), typeof(Func))); - Assert.AreEqual(C.ImplicitReferenceConversion, ExplicitConversion(typeof(Func), typeof(Func))); + Assert.That(ExplicitConversion(typeof(Func), typeof(Func)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(Func), typeof(Func)), Is.EqualTo(C.ImplicitReferenceConversion)); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(Action), typeof(Action))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(Action), typeof(Action))); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(Action), typeof(Action>))); + Assert.That(ExplicitConversion(typeof(Action), typeof(Action)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(Action), typeof(Action)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(Action), typeof(Action>)), Is.EqualTo(C.ExplicitReferenceConversion)); - Assert.AreEqual(C.ExplicitReferenceConversion, ExplicitConversion(typeof(Func), typeof(Func))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(Func), typeof(Func))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(Func), typeof(Func>))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(Func), typeof(Func>))); + Assert.That(ExplicitConversion(typeof(Func), typeof(Func)), Is.EqualTo(C.ExplicitReferenceConversion)); + Assert.That(ExplicitConversion(typeof(Func), typeof(Func)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(Func), typeof(Func>)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(Func), typeof(Func>)), Is.EqualTo(C.None)); } [Test] public void UnboxingConversion() { - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(object), typeof(int))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(object), typeof(decimal))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(ValueType), typeof(int))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(IFormattable), typeof(int))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(IEnumerable), typeof(int))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(Enum), typeof(StringComparison))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(Enum), typeof(int))); + Assert.That(ExplicitConversion(typeof(object), typeof(int)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(object), typeof(decimal)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(ValueType), typeof(int)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(IFormattable), typeof(int)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(int)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(Enum), typeof(StringComparison)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(Enum), typeof(int)), Is.EqualTo(C.None)); } [Test] public void LiftedUnboxingConversion() { - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(object), typeof(int?))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(object), typeof(decimal?))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(ValueType), typeof(int?))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(IFormattable), typeof(int?))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(IEnumerable), typeof(int?))); - Assert.AreEqual(C.UnboxingConversion, ExplicitConversion(typeof(Enum), typeof(StringComparison?))); - Assert.AreEqual(C.None, ExplicitConversion(typeof(Enum), typeof(int?))); + Assert.That(ExplicitConversion(typeof(object), typeof(int?)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(object), typeof(decimal?)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(ValueType), typeof(int?)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(IFormattable), typeof(int?)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(IEnumerable), typeof(int?)), Is.EqualTo(C.None)); + Assert.That(ExplicitConversion(typeof(Enum), typeof(StringComparison?)), Is.EqualTo(C.UnboxingConversion)); + Assert.That(ExplicitConversion(typeof(Enum), typeof(int?)), Is.EqualTo(C.None)); } /* TODO: we should probably revive these tests somehow @@ -477,8 +477,8 @@ public void M() { C1 c1 = $(C1)c2$; } }"); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("op_Explicit", rr.Conversion.Method.Name); } @@ -496,8 +496,8 @@ void Run(B b) { T t = $(T)b$; } }"); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("B", rr.Input.Type.Name); } @@ -513,10 +513,10 @@ void Run(T t) { int x = $(int)t$; } }"); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); // even though the user-defined conversion is implicit, the combined conversion is explicit - Assert.IsTrue(rr.Conversion.IsExplicit); + Assert.That(rr.Conversion.IsExplicit); } [Test] @@ -534,8 +534,8 @@ void Run(B b) { T t = $(T)b$; } }"); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("b", rr.Conversion.Method.Parameters.Single().Name); } @@ -553,8 +553,8 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("i", rr.Conversion.Method.Parameters[0].Name); } @@ -572,8 +572,8 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("ui", rr.Conversion.Method.Parameters[0].Name); } @@ -591,8 +591,8 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("i", rr.Conversion.Method.Parameters[0].Name); } @@ -610,7 +610,7 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsFalse(rr.Conversion.IsValid); + Assert.That(!rr.Conversion.IsValid); } [Test] @@ -627,8 +627,8 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("i", rr.Conversion.Method.Parameters[0].Name); } @@ -646,8 +646,8 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("us", rr.Conversion.Method.Parameters[0].Name); } @@ -665,8 +665,8 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("ui", rr.Conversion.Method.Parameters[0].Name); } @@ -684,7 +684,7 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsFalse(rr.Conversion.IsValid); + Assert.That(!rr.Conversion.IsValid); } [Test] @@ -703,7 +703,7 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsFalse(rr.Conversion.IsValid); + Assert.That(!rr.Conversion.IsValid); } [Test] @@ -719,9 +719,9 @@ public void M(int? i) { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); - Assert.IsTrue(rr.Conversion.IsLifted); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsLifted); } [Test] @@ -737,9 +737,9 @@ public void M(int i) { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); - Assert.IsFalse(rr.Conversion.IsLifted); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); + Assert.That(!rr.Conversion.IsLifted); } [Test] @@ -756,9 +756,9 @@ public void M(int? i) { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); - Assert.IsFalse(rr.Conversion.IsLifted); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); + Assert.That(!rr.Conversion.IsLifted); Assert.AreEqual("i", rr.Conversion.Method.Parameters[0].Name); } @@ -776,9 +776,9 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); - Assert.IsFalse(rr.Conversion.IsLifted); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); + Assert.That(!rr.Conversion.IsLifted); Assert.AreEqual("ni", rr.Conversion.Method.Parameters[0].Name); } @@ -796,8 +796,8 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("ui", rr.Conversion.Method.Parameters[0].Name); } @@ -815,8 +815,8 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("ui", rr.Conversion.Method.Parameters[0].Name); } @@ -833,10 +833,10 @@ public void M(int? i) { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); - Assert.IsTrue(rr.Conversion.IsLifted); - Assert.IsTrue(rr.Input is LocalResolveResult); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsLifted); + Assert.That(rr.Input is LocalResolveResult); } [Test] @@ -854,8 +854,8 @@ public static void Main(string[] args) } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("System.Int16", rr.Conversion.Method.ReturnType.FullName); } @@ -874,8 +874,8 @@ public static void Main(string[] args) } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("s", rr.Conversion.Method.Parameters[0].Name); } @@ -893,8 +893,8 @@ static void Main() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.IsUserDefined); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.IsUserDefined); Assert.AreEqual("ci", rr.Conversion.Method.Parameters[0].Name); } @@ -912,11 +912,11 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.ConversionBeforeUserDefinedOperator.IsValid); - Assert.IsTrue(rr.Conversion.ConversionBeforeUserDefinedOperator.IsExplicit); - Assert.IsTrue(rr.Conversion.ConversionBeforeUserDefinedOperator.IsNumericConversion); - Assert.IsTrue(rr.Conversion.ConversionAfterUserDefinedOperator.IsIdentityConversion); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.ConversionBeforeUserDefinedOperator.IsValid); + Assert.That(rr.Conversion.ConversionBeforeUserDefinedOperator.IsExplicit); + Assert.That(rr.Conversion.ConversionBeforeUserDefinedOperator.IsNumericConversion); + Assert.That(rr.Conversion.ConversionAfterUserDefinedOperator.IsIdentityConversion); } [Test] @@ -932,11 +932,11 @@ public void M() { } }"; var rr = Resolve(program); - Assert.IsTrue(rr.Conversion.IsValid); - Assert.IsTrue(rr.Conversion.ConversionBeforeUserDefinedOperator.IsIdentityConversion); - Assert.IsTrue(rr.Conversion.ConversionAfterUserDefinedOperator.IsValid); - Assert.IsTrue(rr.Conversion.ConversionAfterUserDefinedOperator.IsExplicit); - Assert.IsTrue(rr.Conversion.ConversionAfterUserDefinedOperator.IsNumericConversion); + Assert.That(rr.Conversion.IsValid); + Assert.That(rr.Conversion.ConversionBeforeUserDefinedOperator.IsIdentityConversion); + Assert.That(rr.Conversion.ConversionAfterUserDefinedOperator.IsValid); + Assert.That(rr.Conversion.ConversionAfterUserDefinedOperator.IsExplicit); + Assert.That(rr.Conversion.ConversionAfterUserDefinedOperator.IsNumericConversion); }*/ } } diff --git a/ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs b/ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs index 5a72ad5b2c..cabe83281b 100644 --- a/ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs +++ b/ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs @@ -86,10 +86,10 @@ public void PreferIntOverUInt() { OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList(typeof(ushort))); var c1 = MakeMethod(typeof(int)); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(c1)); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(uint)))); - Assert.IsFalse(r.IsAmbiguous); - Assert.AreSame(c1, r.BestCandidate); + Assert.That(r.AddCandidate(c1), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.AddCandidate(MakeMethod(typeof(uint))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(!r.IsAmbiguous); + Assert.That(r.BestCandidate, Is.SameAs(c1)); } [Test] @@ -98,66 +98,66 @@ public void PreferUIntOverLong_FromIntLiteral() ResolveResult[] args = { new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 1) }; OverloadResolution r = new OverloadResolution(compilation, args); var c1 = MakeMethod(typeof(uint)); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(c1)); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(long)))); - Assert.IsFalse(r.IsAmbiguous); - Assert.AreSame(c1, r.BestCandidate); + Assert.That(r.AddCandidate(c1), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.AddCandidate(MakeMethod(typeof(long))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(!r.IsAmbiguous); + Assert.That(r.BestCandidate, Is.SameAs(c1)); } [Test] public void NullableIntAndNullableUIntIsAmbiguous() { OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList(typeof(ushort?))); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(int?)))); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(uint?)))); - Assert.AreEqual(OverloadResolutionErrors.AmbiguousMatch, r.BestCandidateErrors); + Assert.That(r.AddCandidate(MakeMethod(typeof(int?))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.AddCandidate(MakeMethod(typeof(uint?))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.BestCandidateErrors, Is.EqualTo(OverloadResolutionErrors.AmbiguousMatch)); // then adding a matching overload solves the ambiguity: - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(ushort?)))); - Assert.AreEqual(OverloadResolutionErrors.None, r.BestCandidateErrors); - Assert.IsNull(r.BestCandidateAmbiguousWith); + Assert.That(r.AddCandidate(MakeMethod(typeof(ushort?))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.BestCandidateErrors, Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.BestCandidateAmbiguousWith, Is.Null); } [Test] public void ParamsMethodMatchesEmptyArgumentList() { OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList()); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeParamsMethod(typeof(int[])))); - Assert.IsTrue(r.BestCandidateIsExpandedForm); + Assert.That(r.AddCandidate(MakeParamsMethod(typeof(int[]))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.BestCandidateIsExpandedForm); } [Test] public void ParamsMethodMatchesOneArgumentInExpandedForm() { OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList(typeof(int))); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeParamsMethod(typeof(int[])))); - Assert.IsTrue(r.BestCandidateIsExpandedForm); + Assert.That(r.AddCandidate(MakeParamsMethod(typeof(int[]))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.BestCandidateIsExpandedForm); } [Test] public void ParamsMethodMatchesInUnexpandedForm() { OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList(typeof(int[]))); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeParamsMethod(typeof(int[])))); - Assert.IsFalse(r.BestCandidateIsExpandedForm); + Assert.That(r.AddCandidate(MakeParamsMethod(typeof(int[]))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(!r.BestCandidateIsExpandedForm); } [Test] public void LessArgumentsPassedToParamsIsBetter() { OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList(typeof(int), typeof(int), typeof(int))); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeParamsMethod(typeof(int[])))); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeParamsMethod(typeof(int), typeof(int[])))); - Assert.IsFalse(r.IsAmbiguous); - Assert.AreEqual(2, r.BestCandidate.Parameters.Count); + Assert.That(r.AddCandidate(MakeParamsMethod(typeof(int[]))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.AddCandidate(MakeParamsMethod(typeof(int), typeof(int[]))), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(!r.IsAmbiguous); + Assert.That(r.BestCandidate.Parameters.Count, Is.EqualTo(2)); } [Test] public void CallInvalidParamsDeclaration() { OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList(typeof(int[,]))); - Assert.AreEqual(OverloadResolutionErrors.ArgumentTypeMismatch, r.AddCandidate(MakeParamsMethod(typeof(int)))); - Assert.IsFalse(r.BestCandidateIsExpandedForm); + Assert.That(r.AddCandidate(MakeParamsMethod(typeof(int))), Is.EqualTo(OverloadResolutionErrors.ArgumentTypeMismatch)); + Assert.That(!r.BestCandidateIsExpandedForm); } [Test] @@ -167,10 +167,10 @@ public void PreferMethodWithoutOptionalParameters() var m2 = MakeMethod(1); OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList()); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m1)); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m2)); - Assert.IsFalse(r.IsAmbiguous); - Assert.AreSame(m1, r.BestCandidate); + Assert.That(r.AddCandidate(m1), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.AddCandidate(m2), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(!r.IsAmbiguous); + Assert.That(r.BestCandidate, Is.SameAs(m1)); } [Test] @@ -186,22 +186,22 @@ public void SkeetEvilOverloadResolution() // Call: Foo(); OverloadResolution o; o = new OverloadResolution(compilation, new ResolveResult[0], typeArguments: new[] { compilation.FindType(typeof(int)) }); - Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(resolvedM1)); - Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(resolvedM2)); - Assert.AreSame(resolvedM1, o.BestCandidate); + Assert.That(o.AddCandidate(resolvedM1), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(o.AddCandidate(resolvedM2), Is.EqualTo(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint)); + Assert.That(o.BestCandidate, Is.SameAs(resolvedM1)); // Call: Foo(); o = new OverloadResolution(compilation, new ResolveResult[0], typeArguments: new[] { compilation.FindType(typeof(string)) }); - Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(resolvedM1)); - Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(resolvedM2)); - Assert.AreSame(resolvedM2, o.BestCandidate); + Assert.That(o.AddCandidate(resolvedM1), Is.EqualTo(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint)); + Assert.That(o.AddCandidate(resolvedM2), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(o.BestCandidate, Is.SameAs(resolvedM2)); // Call: Foo(); o = new OverloadResolution(compilation, new ResolveResult[0], typeArguments: new[] { compilation.FindType(typeof(int?)) }); - Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(resolvedM1)); - Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(resolvedM2)); - Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(resolvedM3)); - Assert.AreSame(resolvedM3, o.BestCandidate); + Assert.That(o.AddCandidate(resolvedM1), Is.EqualTo(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint)); + Assert.That(o.AddCandidate(resolvedM2), Is.EqualTo(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint)); + Assert.That(o.AddCandidate(resolvedM3), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(o.BestCandidate, Is.SameAs(resolvedM3)); } class SkeetEvilOverloadResolutionTestCase @@ -276,10 +276,10 @@ public void BetterConversionByLambdaReturnValue() }; OverloadResolution r = new OverloadResolution(compilation, args); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m1)); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m2)); - Assert.AreSame(m2, r.BestCandidate); - Assert.AreEqual(OverloadResolutionErrors.None, r.BestCandidateErrors); + Assert.That(r.AddCandidate(m1), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.AddCandidate(m2), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.BestCandidate, Is.SameAs(m2)); + Assert.That(r.BestCandidateErrors, Is.EqualTo(OverloadResolutionErrors.None)); } [Test] @@ -294,10 +294,10 @@ public void BetterConversionByLambdaReturnValue_ExpressionTree() }; OverloadResolution r = new OverloadResolution(compilation, args); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m1)); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m2)); - Assert.AreSame(m2, r.BestCandidate); - Assert.AreEqual(OverloadResolutionErrors.None, r.BestCandidateErrors); + Assert.That(r.AddCandidate(m1), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.AddCandidate(m2), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.BestCandidate, Is.SameAs(m2)); + Assert.That(r.BestCandidateErrors, Is.EqualTo(OverloadResolutionErrors.None)); } [Test] @@ -312,9 +312,9 @@ public void Lambda_DelegateAndExpressionTreeOverloadsAreAmbiguous() }; OverloadResolution r = new OverloadResolution(compilation, args); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m1)); - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m2)); - Assert.AreEqual(OverloadResolutionErrors.AmbiguousMatch, r.BestCandidateErrors); + Assert.That(r.AddCandidate(m1), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.AddCandidate(m2), Is.EqualTo(OverloadResolutionErrors.None)); + Assert.That(r.BestCandidateErrors, Is.EqualTo(OverloadResolutionErrors.AmbiguousMatch)); } [Test, Ignore("Overload Resolution bug")] @@ -329,10 +329,10 @@ public void BetterFunctionMemberIsNotTransitive() OverloadResolution r = new OverloadResolution(compilation, args); foreach (var method in container.GetMethods(m => m.Name == "Method")) { - Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(method)); + Assert.That(r.AddCandidate(method), Is.EqualTo(OverloadResolutionErrors.None)); } - Assert.AreEqual(container.GetMethods(m => m.Name == "Method").Last(), r.BestCandidate); + Assert.That(r.BestCandidate, Is.EqualTo(container.GetMethods(m => m.Name == "Method").Last())); } class BetterFunctionMemberIsNotTransitiveTestCase diff --git a/ICSharpCode.Decompiler.Tests/TypeSystem/ReflectionHelperTests.cs b/ICSharpCode.Decompiler.Tests/TypeSystem/ReflectionHelperTests.cs index 3686dbfcf4..75e6959642 100644 --- a/ICSharpCode.Decompiler.Tests/TypeSystem/ReflectionHelperTests.cs +++ b/ICSharpCode.Decompiler.Tests/TypeSystem/ReflectionHelperTests.cs @@ -36,8 +36,8 @@ public unsafe class ReflectionHelperTests void TestFindType(Type type) { IType t = compilation.FindType(type); - Assert.IsNotNull(t, type.FullName); - Assert.AreEqual(type.FullName, t.ReflectionName); + Assert.That(t, Is.Not.Null, type.FullName); + Assert.That(t.ReflectionName, Is.EqualTo(type.FullName)); } [Test] @@ -73,83 +73,70 @@ public void TestGetInnerClassInGenericClass2() [Test] public void TestToTypeReferenceInnerClass() { - Assert.AreEqual("System.Environment+SpecialFolder", - compilation.FindType(typeof(Environment.SpecialFolder)).ReflectionName); + Assert.That(compilation.FindType(typeof(Environment.SpecialFolder)).ReflectionName, Is.EqualTo("System.Environment+SpecialFolder")); } [Test] public void TestToTypeReferenceUnboundGenericClass() { - Assert.AreEqual("System.Action`1", - compilation.FindType(typeof(Action<>)).ReflectionName); - Assert.AreEqual("System.Action`2", - compilation.FindType(typeof(Action<,>)).ReflectionName); + Assert.That(compilation.FindType(typeof(Action<>)).ReflectionName, Is.EqualTo("System.Action`1")); + Assert.That(compilation.FindType(typeof(Action<,>)).ReflectionName, Is.EqualTo("System.Action`2")); } [Test] public void TestToTypeReferenceBoundGenericClass() { - Assert.AreEqual("System.Action`1[[System.String]]", - compilation.FindType(typeof(Action)).ReflectionName); - Assert.AreEqual("System.Action`2[[System.Int32],[System.Int16]]", - compilation.FindType(typeof(Action)).ReflectionName); + Assert.That(compilation.FindType(typeof(Action)).ReflectionName, Is.EqualTo("System.Action`1[[System.String]]")); + Assert.That(compilation.FindType(typeof(Action)).ReflectionName, Is.EqualTo("System.Action`2[[System.Int32],[System.Int16]]")); } [Test] public void TestToTypeReferenceNullableType() { - Assert.AreEqual("System.Nullable`1[[System.Int32]]", - compilation.FindType(typeof(int?)).ReflectionName); + Assert.That(compilation.FindType(typeof(int?)).ReflectionName, Is.EqualTo("System.Nullable`1[[System.Int32]]")); } [Test] public void TestToTypeReferenceInnerClassInUnboundGenericType() { - Assert.AreEqual("System.Collections.Generic.Dictionary`2+ValueCollection", - compilation.FindType(typeof(Dictionary<,>.ValueCollection)).ReflectionName); + Assert.That(compilation.FindType(typeof(Dictionary<,>.ValueCollection)).ReflectionName, Is.EqualTo("System.Collections.Generic.Dictionary`2+ValueCollection")); } [Test] public void TestToTypeReferenceInnerClassInBoundGenericType() { - Assert.AreEqual("System.Collections.Generic.Dictionary`2+KeyCollection[[System.String],[System.Int32]]", - compilation.FindType(typeof(Dictionary.KeyCollection)).ReflectionName); + Assert.That(compilation.FindType(typeof(Dictionary.KeyCollection)).ReflectionName, Is.EqualTo("System.Collections.Generic.Dictionary`2+KeyCollection[[System.String],[System.Int32]]")); } [Test] public void TestToTypeReferenceArrayType() { - Assert.AreEqual(typeof(int[]).FullName, - compilation.FindType(typeof(int[])).ReflectionName); + Assert.That(compilation.FindType(typeof(int[])).ReflectionName, Is.EqualTo(typeof(int[]).FullName)); } [Test] public void TestToTypeReferenceMultidimensionalArrayType() { - Assert.AreEqual(typeof(int[,]).FullName, - compilation.FindType(typeof(int[,])).ReflectionName); + Assert.That(compilation.FindType(typeof(int[,])).ReflectionName, Is.EqualTo(typeof(int[,]).FullName)); } [Test] public void TestToTypeReferenceJaggedMultidimensionalArrayType() { - Assert.AreEqual(typeof(int[,][,,]).FullName, - compilation.FindType(typeof(int[,][,,])).ReflectionName); + Assert.That(compilation.FindType(typeof(int[,][,,])).ReflectionName, Is.EqualTo(typeof(int[,][,,]).FullName)); } [Test] public void TestToTypeReferencePointerType() { - Assert.AreEqual(typeof(int*).FullName, - compilation.FindType(typeof(int*)).ReflectionName); + Assert.That(compilation.FindType(typeof(int*)).ReflectionName, Is.EqualTo(typeof(int*).FullName)); } [Test] public void TestToTypeReferenceByReferenceType() { - Assert.AreEqual(typeof(int).MakeByRefType().FullName, - compilation.FindType(typeof(int).MakeByRefType()).ReflectionName); + Assert.That(compilation.FindType(typeof(int).MakeByRefType()).ReflectionName, Is.EqualTo(typeof(int).MakeByRefType().FullName)); } [Test] @@ -159,43 +146,43 @@ public void TestToTypeReferenceGenericType() ITypeReference parameterType = convertAllInfo.GetParameters()[0].ParameterType.ToTypeReference(); // Converter[[`0],[``0]] // cannot resolve generic types without knowing the parent entity: IType resolvedWithoutEntity = parameterType.Resolve(new SimpleTypeResolveContext(compilation)); - Assert.AreEqual("System.Converter`2[[`0],[``0]]", resolvedWithoutEntity.ReflectionName); - Assert.IsNull(((ITypeParameter)((ParameterizedType)resolvedWithoutEntity).GetTypeArgument(0)).Owner); + Assert.That(resolvedWithoutEntity.ReflectionName, Is.EqualTo("System.Converter`2[[`0],[``0]]")); + Assert.That(((ITypeParameter)((ParameterizedType)resolvedWithoutEntity).GetTypeArgument(0)).Owner, Is.Null); // now try with parent entity: IMethod convertAll = compilation.FindType(typeof(List<>)).GetMethods(m => m.Name == "ConvertAll").Single(); IType resolvedWithEntity = parameterType.Resolve(new SimpleTypeResolveContext(convertAll)); - Assert.AreEqual("System.Converter`2[[`0],[``0]]", resolvedWithEntity.ReflectionName); - Assert.AreSame(convertAll.DeclaringTypeDefinition, ((ITypeParameter)((ParameterizedType)resolvedWithEntity).GetTypeArgument(0)).Owner); + Assert.That(resolvedWithEntity.ReflectionName, Is.EqualTo("System.Converter`2[[`0],[``0]]")); + Assert.That(((ITypeParameter)((ParameterizedType)resolvedWithEntity).GetTypeArgument(0)).Owner, Is.SameAs(convertAll.DeclaringTypeDefinition)); } [Test] public void ParseReflectionName() { var context = new SimpleTypeResolveContext(compilation.MainModule); - Assert.AreEqual("System.Int32", ReflectionHelper.ParseReflectionName("System.Int32").Resolve(context).ReflectionName); - Assert.AreEqual("System.Int32&", ReflectionHelper.ParseReflectionName("System.Int32&").Resolve(context).ReflectionName); - Assert.AreEqual("System.Int32*&", ReflectionHelper.ParseReflectionName("System.Int32*&").Resolve(context).ReflectionName); - Assert.AreEqual("System.Int32", ReflectionHelper.ParseReflectionName(typeof(int).AssemblyQualifiedName).Resolve(context).ReflectionName); - Assert.AreEqual("System.Action`1[[System.String]]", ReflectionHelper.ParseReflectionName("System.Action`1[[System.String]]").Resolve(context).ReflectionName); - Assert.AreEqual("System.Action`1[[System.String]]", ReflectionHelper.ParseReflectionName("System.Action`1[[System.String, mscorlib]]").Resolve(context).ReflectionName); - Assert.AreEqual("System.Int32[,,][,]", ReflectionHelper.ParseReflectionName(typeof(int[,][,,]).AssemblyQualifiedName).Resolve(context).ReflectionName); - Assert.AreEqual("System.Environment+SpecialFolder", ReflectionHelper.ParseReflectionName("System.Environment+SpecialFolder").Resolve(context).ReflectionName); + Assert.That(ReflectionHelper.ParseReflectionName("System.Int32").Resolve(context).ReflectionName, Is.EqualTo("System.Int32")); + Assert.That(ReflectionHelper.ParseReflectionName("System.Int32&").Resolve(context).ReflectionName, Is.EqualTo("System.Int32&")); + Assert.That(ReflectionHelper.ParseReflectionName("System.Int32*&").Resolve(context).ReflectionName, Is.EqualTo("System.Int32*&")); + Assert.That(ReflectionHelper.ParseReflectionName(typeof(int).AssemblyQualifiedName).Resolve(context).ReflectionName, Is.EqualTo("System.Int32")); + Assert.That(ReflectionHelper.ParseReflectionName("System.Action`1[[System.String]]").Resolve(context).ReflectionName, Is.EqualTo("System.Action`1[[System.String]]")); + Assert.That(ReflectionHelper.ParseReflectionName("System.Action`1[[System.String, mscorlib]]").Resolve(context).ReflectionName, Is.EqualTo("System.Action`1[[System.String]]")); + Assert.That(ReflectionHelper.ParseReflectionName(typeof(int[,][,,]).AssemblyQualifiedName).Resolve(context).ReflectionName, Is.EqualTo("System.Int32[,,][,]")); + Assert.That(ReflectionHelper.ParseReflectionName("System.Environment+SpecialFolder").Resolve(context).ReflectionName, Is.EqualTo("System.Environment+SpecialFolder")); } [Test] public void ParseOpenGenericReflectionName() { ITypeReference typeRef = ReflectionHelper.ParseReflectionName("System.Converter`2[[`0],[``0]]"); - Assert.AreEqual("System.Converter`2[[`0],[``0]]", typeRef.Resolve(new SimpleTypeResolveContext(compilation.MainModule)).ReflectionName); + Assert.That(typeRef.Resolve(new SimpleTypeResolveContext(compilation.MainModule)).ReflectionName, Is.EqualTo("System.Converter`2[[`0],[``0]]")); IMethod convertAll = compilation.FindType(typeof(List<>)).GetMethods(m => m.Name == "ConvertAll").Single(); - Assert.AreEqual("System.Converter`2[[`0],[``0]]", typeRef.Resolve(new SimpleTypeResolveContext(convertAll)).ReflectionName); + Assert.That(typeRef.Resolve(new SimpleTypeResolveContext(convertAll)).ReflectionName, Is.EqualTo("System.Converter`2[[`0],[``0]]")); } [Test] public void ArrayOfTypeParameter() { var context = new SimpleTypeResolveContext(compilation.MainModule); - Assert.AreEqual("`0[,]", ReflectionHelper.ParseReflectionName("`0[,]").Resolve(context).ReflectionName); + Assert.That(ReflectionHelper.ParseReflectionName("`0[,]").Resolve(context).ReflectionName, Is.EqualTo("`0[,]")); } [Test] diff --git a/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs b/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs index b6346f0fde..b27a1ecc5c 100644 --- a/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs +++ b/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs @@ -29,6 +29,7 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem.Implementation; +using ICSharpCode.Decompiler.Util; using NUnit.Framework; @@ -81,16 +82,16 @@ protected ITypeDefinition GetTypeDefinition(Type type) public void SimplePublicClassTest() { ITypeDefinition c = GetTypeDefinition(typeof(SimplePublicClass)); - Assert.AreEqual(typeof(SimplePublicClass).Name, c.Name); - Assert.AreEqual(typeof(SimplePublicClass).FullName, c.FullName); - Assert.AreEqual(typeof(SimplePublicClass).Namespace, c.Namespace); - Assert.AreEqual(typeof(SimplePublicClass).FullName, c.ReflectionName); + Assert.That(c.Name, Is.EqualTo(typeof(SimplePublicClass).Name)); + Assert.That(c.FullName, Is.EqualTo(typeof(SimplePublicClass).FullName)); + Assert.That(c.Namespace, Is.EqualTo(typeof(SimplePublicClass).Namespace)); + Assert.That(c.ReflectionName, Is.EqualTo(typeof(SimplePublicClass).FullName)); - Assert.AreEqual(Accessibility.Public, c.Accessibility); - Assert.IsFalse(c.IsAbstract); - Assert.IsFalse(c.IsSealed); - Assert.IsFalse(c.IsStatic); - Assert.IsFalse(c.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(c.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(!c.IsAbstract); + Assert.That(!c.IsSealed); + Assert.That(!c.IsStatic); + Assert.That(!c.HasAttribute(KnownAttribute.SpecialName)); } [Test] @@ -99,17 +100,17 @@ public void SimplePublicClassMethodTest() ITypeDefinition c = GetTypeDefinition(typeof(SimplePublicClass)); IMethod method = c.Methods.Single(m => m.Name == "Method"); - Assert.AreEqual(typeof(SimplePublicClass).FullName + ".Method", method.FullName); - Assert.AreSame(c, method.DeclaringType); - Assert.AreEqual(Accessibility.Public, method.Accessibility); - Assert.AreEqual(SymbolKind.Method, method.SymbolKind); - Assert.IsFalse(method.IsVirtual); - Assert.IsFalse(method.IsStatic); - Assert.AreEqual(0, method.Parameters.Count); - Assert.AreEqual(0, method.GetAttributes().Count()); - Assert.IsTrue(method.HasBody); - Assert.IsNull(method.AccessorOwner); - Assert.IsFalse(method.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(method.FullName, Is.EqualTo(typeof(SimplePublicClass).FullName + ".Method")); + Assert.That(method.DeclaringType, Is.SameAs(c)); + Assert.That(method.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(method.SymbolKind, Is.EqualTo(SymbolKind.Method)); + Assert.That(!method.IsVirtual); + Assert.That(!method.IsStatic); + Assert.That(method.Parameters.Count, Is.EqualTo(0)); + Assert.That(method.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(method.HasBody); + Assert.That(method.AccessorOwner, Is.Null); + Assert.That(!method.HasAttribute(KnownAttribute.SpecialName)); } [Test] @@ -118,17 +119,17 @@ public void SimplePublicClassCtorTest() ITypeDefinition c = GetTypeDefinition(typeof(SimplePublicClass)); IMethod method = c.Methods.Single(m => m.IsConstructor); - Assert.AreEqual(typeof(SimplePublicClass).FullName + "..ctor", method.FullName); - Assert.AreSame(c, method.DeclaringType); - Assert.AreEqual(Accessibility.Public, method.Accessibility); - Assert.AreEqual(SymbolKind.Constructor, method.SymbolKind); - Assert.IsFalse(method.IsVirtual); - Assert.IsFalse(method.IsStatic); - Assert.AreEqual(0, method.Parameters.Count); - Assert.AreEqual(0, method.GetAttributes().Count()); - Assert.IsTrue(method.HasBody); - Assert.IsNull(method.AccessorOwner); - Assert.IsFalse(method.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(method.FullName, Is.EqualTo(typeof(SimplePublicClass).FullName + "..ctor")); + Assert.That(method.DeclaringType, Is.SameAs(c)); + Assert.That(method.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(method.SymbolKind, Is.EqualTo(SymbolKind.Constructor)); + Assert.That(!method.IsVirtual); + Assert.That(!method.IsStatic); + Assert.That(method.Parameters.Count, Is.EqualTo(0)); + Assert.That(method.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(method.HasBody); + Assert.That(method.AccessorOwner, Is.Null); + Assert.That(!method.HasAttribute(KnownAttribute.SpecialName)); } [Test] @@ -137,26 +138,26 @@ public void SimplePublicClassDtorTest() ITypeDefinition c = GetTypeDefinition(typeof(SimplePublicClass)); IMethod method = c.Methods.Single(m => m.IsDestructor); - Assert.AreEqual(typeof(SimplePublicClass).FullName + ".Finalize", method.FullName); - Assert.AreSame(c, method.DeclaringType); - Assert.AreEqual(Accessibility.Protected, method.Accessibility); - Assert.AreEqual(SymbolKind.Destructor, method.SymbolKind); - Assert.IsFalse(method.IsVirtual); - Assert.IsFalse(method.IsStatic); - Assert.AreEqual(0, method.Parameters.Count); - Assert.AreEqual(1, method.GetAttributes().Count()); - Assert.IsTrue(method.HasBody); - Assert.IsNull(method.AccessorOwner); - Assert.IsFalse(method.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(method.FullName, Is.EqualTo(typeof(SimplePublicClass).FullName + ".Finalize")); + Assert.That(method.DeclaringType, Is.SameAs(c)); + Assert.That(method.Accessibility, Is.EqualTo(Accessibility.Protected)); + Assert.That(method.SymbolKind, Is.EqualTo(SymbolKind.Destructor)); + Assert.That(!method.IsVirtual); + Assert.That(!method.IsStatic); + Assert.That(method.Parameters.Count, Is.EqualTo(0)); + Assert.That(method.GetAttributes().Count(), Is.EqualTo(1)); + Assert.That(method.HasBody); + Assert.That(method.AccessorOwner, Is.Null); + Assert.That(!method.HasAttribute(KnownAttribute.SpecialName)); } [Test] public void DynamicType() { ITypeDefinition testClass = GetTypeDefinition(typeof(DynamicTest)); - Assert.AreEqual(SpecialType.Dynamic, testClass.Fields.Single(f => f.Name == "DynamicField").ReturnType); - Assert.AreEqual(SpecialType.Dynamic, testClass.Properties.Single().ReturnType); - Assert.AreEqual(0, testClass.Properties.Single().GetAttributes().Count()); + Assert.That(testClass.Fields.Single(f => f.Name == "DynamicField").ReturnType, Is.EqualTo(SpecialType.Dynamic)); + Assert.That(testClass.Properties.Single().ReturnType, Is.EqualTo(SpecialType.Dynamic)); + Assert.That(testClass.Properties.Single().GetAttributes().Count(), Is.EqualTo(0)); } [Test] @@ -165,26 +166,26 @@ public void DynamicTypeInGenerics() ITypeDefinition testClass = GetTypeDefinition(typeof(DynamicTest)); IMethod m1 = testClass.Methods.Single(me => me.Name == "DynamicGenerics1"); - Assert.AreEqual("System.Collections.Generic.List`1[[dynamic]]", m1.ReturnType.ReflectionName); - Assert.AreEqual("System.Action`3[[System.Object],[dynamic[]],[System.Object]]", m1.Parameters[0].Type.ReflectionName); + Assert.That(m1.ReturnType.ReflectionName, Is.EqualTo("System.Collections.Generic.List`1[[dynamic]]")); + Assert.That(m1.Parameters[0].Type.ReflectionName, Is.EqualTo("System.Action`3[[System.Object],[dynamic[]],[System.Object]]")); IMethod m2 = testClass.Methods.Single(me => me.Name == "DynamicGenerics2"); - Assert.AreEqual("System.Action`3[[System.Object],[dynamic],[System.Object]]", m2.Parameters[0].Type.ReflectionName); + Assert.That(m2.Parameters[0].Type.ReflectionName, Is.EqualTo("System.Action`3[[System.Object],[dynamic],[System.Object]]")); IMethod m3 = testClass.Methods.Single(me => me.Name == "DynamicGenerics3"); - Assert.AreEqual("System.Action`3[[System.Int32],[dynamic],[System.Object]]", m3.Parameters[0].Type.ReflectionName); + Assert.That(m3.Parameters[0].Type.ReflectionName, Is.EqualTo("System.Action`3[[System.Int32],[dynamic],[System.Object]]")); IMethod m4 = testClass.Methods.Single(me => me.Name == "DynamicGenerics4"); - Assert.AreEqual("System.Action`3[[System.Int32[]],[dynamic],[System.Object]]", m4.Parameters[0].Type.ReflectionName); + Assert.That(m4.Parameters[0].Type.ReflectionName, Is.EqualTo("System.Action`3[[System.Int32[]],[dynamic],[System.Object]]")); IMethod m5 = testClass.Methods.Single(me => me.Name == "DynamicGenerics5"); - Assert.AreEqual("System.Action`3[[System.Int32*[]],[dynamic],[System.Object]]", m5.Parameters[0].Type.ReflectionName); + Assert.That(m5.Parameters[0].Type.ReflectionName, Is.EqualTo("System.Action`3[[System.Int32*[]],[dynamic],[System.Object]]")); IMethod m6 = testClass.Methods.Single(me => me.Name == "DynamicGenerics6"); - Assert.AreEqual("System.Action`3[[System.Object],[dynamic],[System.Object]]&", m6.Parameters[0].Type.ReflectionName); + Assert.That(m6.Parameters[0].Type.ReflectionName, Is.EqualTo("System.Action`3[[System.Object],[dynamic],[System.Object]]&")); IMethod m7 = testClass.Methods.Single(me => me.Name == "DynamicGenerics7"); - Assert.AreEqual("System.Action`3[[System.Int32[][,]],[dynamic],[System.Object]]", m7.Parameters[0].Type.ReflectionName); + Assert.That(m7.Parameters[0].Type.ReflectionName, Is.EqualTo("System.Action`3[[System.Int32[][,]],[dynamic],[System.Object]]")); } [Test] @@ -192,7 +193,7 @@ public void DynamicParameterHasNoAttributes() { ITypeDefinition testClass = GetTypeDefinition(typeof(DynamicTest)); IMethod m1 = testClass.Methods.Single(me => me.Name == "DynamicGenerics1"); - Assert.AreEqual(0, m1.Parameters[0].GetAttributes().Count()); + Assert.That(m1.Parameters[0].GetAttributes().Count(), Is.EqualTo(0)); } [Test] @@ -200,23 +201,23 @@ public void AssemblyAttribute() { var attributes = compilation.MainModule.GetAssemblyAttributes().ToList(); var typeTest = attributes.Single(a => a.AttributeType.FullName == typeof(TypeTestAttribute).FullName); - Assert.AreEqual(3, typeTest.FixedArguments.Length); + Assert.That(typeTest.FixedArguments.Length, Is.EqualTo(3)); // first argument is (int)42 - Assert.AreEqual(42, (int)typeTest.FixedArguments[0].Value); + Assert.That((int)typeTest.FixedArguments[0].Value, Is.EqualTo(42)); // second argument is typeof(System.Action<>) var ty = (IType)typeTest.FixedArguments[1].Value; - Assert.IsFalse(ty is ParameterizedType); // rt must not be constructed - it's just an unbound type - Assert.AreEqual("System.Action", ty.FullName); - Assert.AreEqual(1, ty.TypeParameterCount); + Assert.That(ty is ParameterizedType, Is.False); // rt must not be constructed - it's just an unbound type + Assert.That(ty.FullName, Is.EqualTo("System.Action")); + Assert.That(ty.TypeParameterCount, Is.EqualTo(1)); // third argument is typeof(IDictionary>) var crt = (ParameterizedType)typeTest.FixedArguments[2].Value; - Assert.AreEqual("System.Collections.Generic.IDictionary", crt.FullName); - Assert.AreEqual("System.String", crt.TypeArguments[0].FullName); + Assert.That(crt.FullName, Is.EqualTo("System.Collections.Generic.IDictionary")); + Assert.That(crt.TypeArguments[0].FullName, Is.EqualTo("System.String")); // we know the name for TestAttribute, but not necessarily the namespace, as NUnit is not in the compilation - Assert.AreEqual("System.Collections.Generic.IList", crt.TypeArguments[1].FullName); + Assert.That(crt.TypeArguments[1].FullName, Is.EqualTo("System.Collections.Generic.IList")); var testAttributeType = ((ParameterizedType)crt.TypeArguments[1]).TypeArguments.Single(); - Assert.AreEqual("TestAttribute", testAttributeType.Name); - Assert.AreEqual(TypeKind.Unknown, testAttributeType.Kind); + Assert.That(testAttributeType.Name, Is.EqualTo("TestAttribute")); + Assert.That(testAttributeType.Kind, Is.EqualTo(TypeKind.Unknown)); // (more accurately, we know the namespace and reflection name if the type was loaded by cecil, // but not if we parsed it from C#) } @@ -226,18 +227,18 @@ public void TypeForwardedTo_Attribute() { var attributes = compilation.MainModule.GetAssemblyAttributes().ToList(); var forwardAttribute = attributes.Single(a => a.AttributeType.FullName == typeof(TypeForwardedToAttribute).FullName); - Assert.AreEqual(1, forwardAttribute.FixedArguments.Length); + Assert.That(forwardAttribute.FixedArguments.Length, Is.EqualTo(1)); var rt = (IType)forwardAttribute.FixedArguments[0].Value; - Assert.AreEqual("System.Func`2", rt.ReflectionName); + Assert.That(rt.ReflectionName, Is.EqualTo("System.Func`2")); } [Test] public void TestClassTypeParameters() { var testClass = GetTypeDefinition(typeof(GenericClass<,>)); - Assert.AreEqual(SymbolKind.TypeDefinition, testClass.TypeParameters[0].OwnerType); - Assert.AreEqual(SymbolKind.TypeDefinition, testClass.TypeParameters[1].OwnerType); - Assert.AreSame(testClass.TypeParameters[1], testClass.TypeParameters[0].DirectBaseTypes.First()); + Assert.That(testClass.TypeParameters[0].OwnerType, Is.EqualTo(SymbolKind.TypeDefinition)); + Assert.That(testClass.TypeParameters[1].OwnerType, Is.EqualTo(SymbolKind.TypeDefinition)); + Assert.That(testClass.TypeParameters[0].DirectBaseTypes.First(), Is.SameAs(testClass.TypeParameters[1])); } [Test] @@ -246,13 +247,13 @@ public void TestMethod() var testClass = GetTypeDefinition(typeof(GenericClass<,>)); IMethod m = testClass.Methods.Single(me => me.Name == "TestMethod"); - Assert.AreEqual("K", m.TypeParameters[0].Name); - Assert.AreEqual("V", m.TypeParameters[1].Name); - Assert.AreEqual(SymbolKind.Method, m.TypeParameters[0].OwnerType); - Assert.AreEqual(SymbolKind.Method, m.TypeParameters[1].OwnerType); + Assert.That(m.TypeParameters[0].Name, Is.EqualTo("K")); + Assert.That(m.TypeParameters[1].Name, Is.EqualTo("V")); + Assert.That(m.TypeParameters[0].OwnerType, Is.EqualTo(SymbolKind.Method)); + Assert.That(m.TypeParameters[1].OwnerType, Is.EqualTo(SymbolKind.Method)); - Assert.AreEqual("System.IComparable`1[[``1]]", m.TypeParameters[0].DirectBaseTypes.First().ReflectionName); - Assert.AreSame(m.TypeParameters[0], m.TypeParameters[1].DirectBaseTypes.First()); + Assert.That(m.TypeParameters[0].DirectBaseTypes.First().ReflectionName, Is.EqualTo("System.IComparable`1[[``1]]")); + Assert.That(m.TypeParameters[1].DirectBaseTypes.First(), Is.SameAs(m.TypeParameters[0])); } [Test] @@ -261,16 +262,16 @@ public void GetIndex() var testClass = GetTypeDefinition(typeof(GenericClass<,>)); IMethod m = testClass.Methods.Single(me => me.Name == "GetIndex"); - Assert.AreEqual("T", m.TypeParameters[0].Name); - Assert.AreEqual(SymbolKind.Method, m.TypeParameters[0].OwnerType); - Assert.AreSame(m, m.TypeParameters[0].Owner); + Assert.That(m.TypeParameters[0].Name, Is.EqualTo("T")); + Assert.That(m.TypeParameters[0].OwnerType, Is.EqualTo(SymbolKind.Method)); + Assert.That(m.TypeParameters[0].Owner, Is.SameAs(m)); ParameterizedType constraint = (ParameterizedType)m.TypeParameters[0].DirectBaseTypes.First(); - Assert.AreEqual("IEquatable", constraint.Name); - Assert.AreEqual(1, constraint.TypeParameterCount); - Assert.AreEqual(1, constraint.TypeArguments.Count); - Assert.AreSame(m.TypeParameters[0], constraint.TypeArguments[0]); - Assert.AreSame(m.TypeParameters[0], m.Parameters[0].Type); + Assert.That(constraint.Name, Is.EqualTo("IEquatable")); + Assert.That(constraint.TypeParameterCount, Is.EqualTo(1)); + Assert.That(constraint.TypeArguments.Count, Is.EqualTo(1)); + Assert.That(constraint.TypeArguments[0], Is.SameAs(m.TypeParameters[0])); + Assert.That(m.Parameters[0].Type, Is.SameAs(m.TypeParameters[0])); } [Test] @@ -283,16 +284,16 @@ public void GetIndexSpecializedTypeParameter() null )); - Assert.AreEqual("T", m.TypeParameters[0].Name); - Assert.AreEqual(SymbolKind.Method, m.TypeParameters[0].OwnerType); - Assert.AreSame(m, m.TypeParameters[0].Owner); + Assert.That(m.TypeParameters[0].Name, Is.EqualTo("T")); + Assert.That(m.TypeParameters[0].OwnerType, Is.EqualTo(SymbolKind.Method)); + Assert.That(m.TypeParameters[0].Owner, Is.SameAs(m)); ParameterizedType constraint = (ParameterizedType)m.TypeParameters[0].DirectBaseTypes.First(); - Assert.AreEqual("IEquatable", constraint.Name); - Assert.AreEqual(1, constraint.TypeParameterCount); - Assert.AreEqual(1, constraint.TypeArguments.Count); - Assert.AreSame(m.TypeParameters[0], constraint.TypeArguments[0]); - Assert.AreSame(m.TypeParameters[0], m.Parameters[0].Type); + Assert.That(constraint.Name, Is.EqualTo("IEquatable")); + Assert.That(constraint.TypeParameterCount, Is.EqualTo(1)); + Assert.That(constraint.TypeArguments.Count, Is.EqualTo(1)); + Assert.That(constraint.TypeArguments[0], Is.SameAs(m.TypeParameters[0])); + Assert.That(m.Parameters[0].Type, Is.SameAs(m.TypeParameters[0])); } [Test] @@ -318,7 +319,7 @@ public void GetIndexDoubleSpecialization() new[] { compilation.FindType(KnownTypeCode.String), compilation.FindType(KnownTypeCode.Int32) }, new[] { compilation.FindType(KnownTypeCode.Int32) } )); - Assert.AreEqual(m12, m2); + Assert.That(m2, Is.EqualTo(m12)); } [Test] @@ -326,18 +327,18 @@ public void SpecializedMethod_AccessorOwner() { // NRefactory bug #143 - Accessor Owner throws null reference exception in some cases now var method = compilation.FindType(typeof(GenericClass)).GetMethods(m => m.Name == "GetIndex").Single(); - Assert.IsNull(method.AccessorOwner); + Assert.That(method.AccessorOwner, Is.Null); } [Test] public void Specialized_GetIndex_ToMemberReference() { var method = compilation.FindType(typeof(GenericClass)).GetMethods(m => m.Name == "GetIndex").Single(); - Assert.AreSame(method.TypeParameters[0], method.Parameters[0].Type); - Assert.AreSame(method, method.TypeParameters[0].Owner); - Assert.IsInstanceOf(method); - //Assert.IsFalse(method.IsParameterized); // the method itself is not specialized - Assert.AreEqual(method.TypeParameters, method.TypeArguments); + Assert.That(method.Parameters[0].Type, Is.SameAs(method.TypeParameters[0])); + Assert.That(method.TypeParameters[0].Owner, Is.SameAs(method)); + Assert.That(method, Is.InstanceOf()); + //Assert.That(!method.IsParameterized); // the method itself is not specialized + Assert.That(method.TypeArguments, Is.EqualTo(method.TypeParameters)); } [Test] @@ -347,23 +348,23 @@ public void Specialized_GetIndex_SpecializeWithIdentityHasNoEffect() IType[] methodTypeArguments = { DummyTypeParameter.GetMethodTypeParameter(0) }; var method = genericClass.GetMethods(methodTypeArguments, m => m.Name == "GetIndex").Single(); // GenericClass.GetIndex() - Assert.AreSame(method, method.TypeParameters[0].Owner); - Assert.AreNotEqual(method.TypeParameters[0], method.TypeArguments[0]); - Assert.IsNull(((ITypeParameter)method.TypeArguments[0]).Owner); + Assert.That(method.TypeParameters[0].Owner, Is.SameAs(method)); + Assert.That(method.TypeArguments[0], Is.Not.EqualTo(method.TypeParameters[0])); + Assert.That(((ITypeParameter)method.TypeArguments[0]).Owner, Is.Null); // Now apply identity substitution: var method2 = method.Specialize(TypeParameterSubstitution.Identity); - Assert.AreSame(method2, method2.TypeParameters[0].Owner); - Assert.AreNotEqual(method2.TypeParameters[0], method2.TypeArguments[0]); - Assert.IsNull(((ITypeParameter)method2.TypeArguments[0]).Owner); + Assert.That(method2.TypeParameters[0].Owner, Is.SameAs(method2)); + Assert.That(method2.TypeArguments[0], Is.Not.EqualTo(method2.TypeParameters[0])); + Assert.That(((ITypeParameter)method2.TypeArguments[0]).Owner, Is.Null); - Assert.AreEqual(method, method2); + Assert.That(method2, Is.EqualTo(method)); } [Test] public void GenericEnum() { var testClass = GetTypeDefinition(typeof(GenericClass<,>.NestedEnum)); - Assert.AreEqual(2, testClass.TypeParameterCount); + Assert.That(testClass.TypeParameterCount, Is.EqualTo(2)); } [Test] @@ -372,7 +373,7 @@ public void FieldInGenericClassWithNestedEnumType() var testClass = GetTypeDefinition(typeof(GenericClass<,>)); var enumClass = GetTypeDefinition(typeof(GenericClass<,>.NestedEnum)); var field = testClass.Fields.Single(f => f.Name == "EnumField"); - Assert.AreEqual(new ParameterizedType(enumClass, testClass.TypeParameters), field.ReturnType); + Assert.That(field.ReturnType, Is.EqualTo(new ParameterizedType(enumClass, testClass.TypeParameters))); } [Test] @@ -380,7 +381,7 @@ public void GenericEnumMemberReturnType() { var enumClass = GetTypeDefinition(typeof(GenericClass<,>.NestedEnum)); var field = enumClass.Fields.Single(f => f.Name == "EnumMember"); - Assert.AreEqual(new ParameterizedType(enumClass, enumClass.TypeParameters), field.ReturnType); + Assert.That(field.ReturnType, Is.EqualTo(new ParameterizedType(enumClass, enumClass.TypeParameters))); } [Test] @@ -388,11 +389,11 @@ public void PropertyWithProtectedSetter() { var testClass = GetTypeDefinition(typeof(PropertyTest)); IProperty p = testClass.Properties.Single(pr => pr.Name == "PropertyWithProtectedSetter"); - Assert.IsTrue(p.CanGet); - Assert.IsTrue(p.CanSet); - Assert.AreEqual(Accessibility.Public, p.Accessibility); - Assert.AreEqual(Accessibility.Public, p.Getter.Accessibility); - Assert.AreEqual(Accessibility.Protected, p.Setter.Accessibility); + Assert.That(p.CanGet); + Assert.That(p.CanSet); + Assert.That(p.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Setter.Accessibility, Is.EqualTo(Accessibility.Protected)); } [Test] @@ -400,15 +401,15 @@ public void PropertyWithPrivateSetter() { var testClass = GetTypeDefinition(typeof(PropertyTest)); IProperty p = testClass.Properties.Single(pr => pr.Name == "PropertyWithPrivateSetter"); - Assert.IsTrue(p.CanGet); - Assert.IsTrue(p.CanSet); - Assert.AreEqual(Accessibility.Public, p.Accessibility); - Assert.AreEqual(Accessibility.Public, p.Getter.Accessibility); - Assert.AreEqual(Accessibility.Private, p.Setter.Accessibility); - Assert.IsTrue(p.Getter.HasBody); - Assert.IsFalse(p.HasAttribute(KnownAttribute.SpecialName)); - Assert.IsFalse(p.Getter.HasAttribute(KnownAttribute.SpecialName)); - Assert.IsFalse(p.Setter.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(p.CanGet); + Assert.That(p.CanSet); + Assert.That(p.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Setter.Accessibility, Is.EqualTo(Accessibility.Private)); + Assert.That(p.Getter.HasBody); + Assert.That(!p.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(!p.Getter.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(!p.Setter.HasAttribute(KnownAttribute.SpecialName)); } [Test] @@ -416,12 +417,12 @@ public void PropertyWithPrivateGetter() { var testClass = GetTypeDefinition(typeof(PropertyTest)); IProperty p = testClass.Properties.Single(pr => pr.Name == "PropertyWithPrivateGetter"); - Assert.IsTrue(p.CanGet); - Assert.IsTrue(p.CanSet); - Assert.AreEqual(Accessibility.Public, p.Accessibility); - Assert.AreEqual(Accessibility.Private, p.Getter.Accessibility); - Assert.AreEqual(Accessibility.Public, p.Setter.Accessibility); - Assert.IsTrue(p.Getter.HasBody); + Assert.That(p.CanGet); + Assert.That(p.CanSet); + Assert.That(p.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.Accessibility, Is.EqualTo(Accessibility.Private)); + Assert.That(p.Setter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.HasBody); } [Test] @@ -429,11 +430,11 @@ public void PropertyWithoutSetter() { var testClass = GetTypeDefinition(typeof(PropertyTest)); IProperty p = testClass.Properties.Single(pr => pr.Name == "PropertyWithoutSetter"); - Assert.IsTrue(p.CanGet); - Assert.IsFalse(p.CanSet); - Assert.AreEqual(Accessibility.Public, p.Accessibility); - Assert.AreEqual(Accessibility.Public, p.Getter.Accessibility); - Assert.IsNull(p.Setter); + Assert.That(p.CanGet); + Assert.That(!p.CanSet); + Assert.That(p.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Setter, Is.Null); } [Test] @@ -441,8 +442,8 @@ public void Indexer() { var testClass = GetTypeDefinition(typeof(PropertyTest)); IProperty p = testClass.Properties.Single(pr => pr.IsIndexer); - Assert.AreEqual("Item", p.Name); - Assert.AreEqual(new[] { "index" }, p.Parameters.Select(x => x.Name).ToArray()); + Assert.That(p.Name, Is.EqualTo("Item")); + Assert.That(p.Parameters.Select(x => x.Name).ToArray(), Is.EqualTo(new[] { "index" })); } [Test] @@ -450,13 +451,13 @@ public void IndexerGetter() { var testClass = GetTypeDefinition(typeof(PropertyTest)); IProperty p = testClass.Properties.Single(pr => pr.IsIndexer); - Assert.IsTrue(p.CanGet); - Assert.AreEqual(SymbolKind.Accessor, p.Getter.SymbolKind); - Assert.AreEqual("get_Item", p.Getter.Name); - Assert.AreEqual(Accessibility.Public, p.Getter.Accessibility); - Assert.AreEqual(new[] { "index" }, p.Getter.Parameters.Select(x => x.Name).ToArray()); - Assert.AreEqual("System.String", p.Getter.ReturnType.ReflectionName); - Assert.AreEqual(p, p.Getter.AccessorOwner); + Assert.That(p.CanGet); + Assert.That(p.Getter.SymbolKind, Is.EqualTo(SymbolKind.Accessor)); + Assert.That(p.Getter.Name, Is.EqualTo("get_Item")); + Assert.That(p.Getter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.Parameters.Select(x => x.Name).ToArray(), Is.EqualTo(new[] { "index" })); + Assert.That(p.Getter.ReturnType.ReflectionName, Is.EqualTo("System.String")); + Assert.That(p.Getter.AccessorOwner, Is.EqualTo(p)); } [Test] @@ -464,12 +465,12 @@ public void IndexerSetter() { var testClass = GetTypeDefinition(typeof(PropertyTest)); IProperty p = testClass.Properties.Single(pr => pr.IsIndexer); - Assert.IsTrue(p.CanSet); - Assert.AreEqual(SymbolKind.Accessor, p.Setter.SymbolKind); - Assert.AreEqual("set_Item", p.Setter.Name); - Assert.AreEqual(Accessibility.Public, p.Setter.Accessibility); - Assert.AreEqual(new[] { "index", "value" }, p.Setter.Parameters.Select(x => x.Name).ToArray()); - Assert.AreEqual(TypeKind.Void, p.Setter.ReturnType.Kind); + Assert.That(p.CanSet); + Assert.That(p.Setter.SymbolKind, Is.EqualTo(SymbolKind.Accessor)); + Assert.That(p.Setter.Name, Is.EqualTo("set_Item")); + Assert.That(p.Setter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Setter.Parameters.Select(x => x.Name).ToArray(), Is.EqualTo(new[] { "index", "value" })); + Assert.That(p.Setter.ReturnType.Kind, Is.EqualTo(TypeKind.Void)); } [Test] @@ -477,19 +478,19 @@ public void GenericPropertyGetter() { var type = compilation.FindType(typeof(GenericClass)); var prop = type.GetProperties(p => p.Name == "Property").Single(); - Assert.AreEqual("System.String", prop.Getter.ReturnType.ReflectionName); - Assert.IsTrue(prop.Getter.IsAccessor); - Assert.AreEqual(prop, prop.Getter.AccessorOwner); + Assert.That(prop.Getter.ReturnType.ReflectionName, Is.EqualTo("System.String")); + Assert.That(prop.Getter.IsAccessor); + Assert.That(prop.Getter.AccessorOwner, Is.EqualTo(prop)); } [Test] public void EnumTest() { var e = GetTypeDefinition(typeof(MyEnum)); - Assert.AreEqual(TypeKind.Enum, e.Kind); - Assert.AreEqual(false, e.IsReferenceType); - Assert.AreEqual("System.Int16", e.EnumUnderlyingType.ReflectionName); - Assert.AreEqual(new[] { "System.Enum" }, e.DirectBaseTypes.Select(t => t.ReflectionName).ToArray()); + Assert.That(e.Kind, Is.EqualTo(TypeKind.Enum)); + Assert.That(e.IsReferenceType, Is.EqualTo(false)); + Assert.That(e.EnumUnderlyingType.ReflectionName, Is.EqualTo("System.Int16")); + Assert.That(e.DirectBaseTypes.Select(t => t.ReflectionName).ToArray(), Is.EqualTo(new[] { "System.Enum" })); } [Test] @@ -498,39 +499,39 @@ public void EnumFieldsTest() var e = GetTypeDefinition(typeof(MyEnum)); IField valueField = e.Fields.First(); IField[] fields = e.Fields.Skip(1).ToArray(); - Assert.AreEqual(5, fields.Length); + Assert.That(fields.Length, Is.EqualTo(5)); - Assert.AreEqual("value__", valueField.Name); - Assert.AreEqual(GetTypeDefinition(typeof(short)), valueField.Type); - Assert.AreEqual(Accessibility.Public, valueField.Accessibility); - Assert.AreEqual(null, valueField.GetConstantValue()); - Assert.IsFalse(valueField.IsConst); - Assert.IsFalse(valueField.IsStatic); + Assert.That(valueField.Name, Is.EqualTo("value__")); + Assert.That(valueField.Type, Is.EqualTo(GetTypeDefinition(typeof(short)))); + Assert.That(valueField.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(valueField.GetConstantValue(), Is.EqualTo(null)); + Assert.That(!valueField.IsConst); + Assert.That(!valueField.IsStatic); foreach (IField f in fields) { - Assert.IsTrue(f.IsStatic); - Assert.IsTrue(f.IsConst); - Assert.AreEqual(Accessibility.Public, f.Accessibility); - Assert.AreSame(e, f.Type); - Assert.AreEqual(typeof(short), f.GetConstantValue().GetType()); + Assert.That(f.IsStatic); + Assert.That(f.IsConst); + Assert.That(f.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(f.Type, Is.SameAs(e)); + Assert.That(f.GetConstantValue().GetType(), Is.EqualTo(typeof(short))); } - Assert.AreEqual("First", fields[0].Name); - Assert.AreEqual(0, fields[0].GetConstantValue()); + Assert.That(fields[0].Name, Is.EqualTo("First")); + Assert.That(fields[0].GetConstantValue(), Is.EqualTo(0)); - Assert.AreEqual("Second", fields[1].Name); - Assert.AreSame(e, fields[1].Type); - Assert.AreEqual(1, fields[1].GetConstantValue()); + Assert.That(fields[1].Name, Is.EqualTo("Second")); + Assert.That(fields[1].Type, Is.SameAs(e)); + Assert.That(fields[1].GetConstantValue(), Is.EqualTo(1)); - Assert.AreEqual("Flag1", fields[2].Name); - Assert.AreEqual(0x10, fields[2].GetConstantValue()); + Assert.That(fields[2].Name, Is.EqualTo("Flag1")); + Assert.That(fields[2].GetConstantValue(), Is.EqualTo(0x10)); - Assert.AreEqual("Flag2", fields[3].Name); - Assert.AreEqual(0x20, fields[3].GetConstantValue()); + Assert.That(fields[3].Name, Is.EqualTo("Flag2")); + Assert.That(fields[3].GetConstantValue(), Is.EqualTo(0x20)); - Assert.AreEqual("CombinedFlags", fields[4].Name); - Assert.AreEqual(0x30, fields[4].GetConstantValue()); + Assert.That(fields[4].Name, Is.EqualTo("CombinedFlags")); + Assert.That(fields[4].GetConstantValue(), Is.EqualTo(0x30)); } [Test] @@ -539,14 +540,12 @@ public void GetNestedTypesFromBaseClassTest() ITypeDefinition d = GetTypeDefinition(typeof(Derived<,>)); IType pBase = d.DirectBaseTypes.Single(); - Assert.AreEqual(typeof(Base<>).FullName + "[[`1]]", pBase.ReflectionName); + Assert.That(pBase.ReflectionName, Is.EqualTo(typeof(Base<>).FullName + "[[`1]]")); // Base[`1].GetNestedTypes() = { Base`1+Nested`1[`1, unbound] } - Assert.AreEqual(new[] { typeof(Base<>.Nested<>).FullName + "[[`1],[]]" }, - pBase.GetNestedTypes().Select(n => n.ReflectionName).ToArray()); + Assert.That(pBase.GetNestedTypes().Select(n => n.ReflectionName).ToArray(), Is.EqualTo(new[] { typeof(Base<>.Nested<>).FullName + "[[`1],[]]" })); // Derived.GetNestedTypes() = { Base`1+Nested`1[`1, unbound] } - Assert.AreEqual(new[] { typeof(Base<>.Nested<>).FullName + "[[`1],[]]" }, - d.GetNestedTypes().Select(n => n.ReflectionName).ToArray()); + Assert.That(d.GetNestedTypes().Select(n => n.ReflectionName).ToArray(), Is.EqualTo(new[] { typeof(Base<>.Nested<>).FullName + "[[`1],[]]" })); // This is 'leaking' the type parameter from B as is usual when retrieving any members from an unbound type. } @@ -555,8 +554,7 @@ public void ParameterizedTypeGetNestedTypesFromBaseClassTest() { // Derived[string,int].GetNestedTypes() = { Base`1+Nested`1[int, unbound] } var d = compilation.FindType(typeof(Derived)); - Assert.AreEqual(new[] { typeof(Base<>.Nested<>).FullName + "[[System.Int32],[]]" }, - d.GetNestedTypes().Select(n => n.ReflectionName).ToArray()); + Assert.That(d.GetNestedTypes().Select(n => n.ReflectionName).ToArray(), Is.EqualTo(new[] { typeof(Base<>.Nested<>).FullName + "[[System.Int32],[]]" })); } [Test] @@ -564,12 +562,11 @@ public void ConstraintsOnOverrideAreInherited() { ITypeDefinition d = GetTypeDefinition(typeof(Derived<,>)); ITypeParameter tp = d.Methods.Single(m => m.Name == "GenericMethodWithConstraints").TypeParameters.Single(); - Assert.AreEqual("Y", tp.Name); - Assert.IsFalse(tp.HasValueTypeConstraint); - Assert.IsFalse(tp.HasReferenceTypeConstraint); - Assert.IsTrue(tp.HasDefaultConstructorConstraint); - Assert.AreEqual(new string[] { "System.Collections.Generic.IComparer`1[[`1]]", "System.Object" }, - tp.DirectBaseTypes.Select(t => t.ReflectionName).ToArray()); + Assert.That(tp.Name, Is.EqualTo("Y")); + Assert.That(!tp.HasValueTypeConstraint); + Assert.That(!tp.HasReferenceTypeConstraint); + Assert.That(tp.HasDefaultConstructorConstraint); + Assert.That(tp.DirectBaseTypes.Select(t => t.ReflectionName).ToArray(), Is.EqualTo(new string[] { "System.Collections.Generic.IComparer`1[[`1]]", "System.Object" })); } [Test] @@ -577,16 +574,16 @@ public void DtorInDerivedClass() { ITypeDefinition c = GetTypeDefinition(typeof(Derived<,>)); IMethod method = c.Methods.Single(m => m.IsDestructor); - Assert.AreEqual(c.FullName + ".Finalize", method.FullName); - Assert.AreSame(c, method.DeclaringType); - Assert.AreEqual(Accessibility.Protected, method.Accessibility); - Assert.AreEqual(SymbolKind.Destructor, method.SymbolKind); - Assert.IsFalse(method.IsVirtual); - Assert.IsFalse(method.IsStatic); - Assert.AreEqual(0, method.Parameters.Count); - Assert.AreEqual(0, method.GetAttributes().Count()); - Assert.IsTrue(method.HasBody); - Assert.IsNull(method.AccessorOwner); + Assert.That(method.FullName, Is.EqualTo(c.FullName + ".Finalize")); + Assert.That(method.DeclaringType, Is.SameAs(c)); + Assert.That(method.Accessibility, Is.EqualTo(Accessibility.Protected)); + Assert.That(method.SymbolKind, Is.EqualTo(SymbolKind.Destructor)); + Assert.That(!method.IsVirtual); + Assert.That(!method.IsStatic); + Assert.That(method.Parameters.Count, Is.EqualTo(0)); + Assert.That(method.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(method.HasBody); + Assert.That(method.AccessorOwner, Is.Null); } [Test] @@ -594,102 +591,102 @@ public void PrivateFinalizeMethodIsNotADtor() { ITypeDefinition c = GetTypeDefinition(typeof(TypeTestAttribute)); IMethod method = c.Methods.Single(m => m.Name == "Finalize"); - Assert.AreEqual(c.FullName + ".Finalize", method.FullName); - Assert.AreSame(c, method.DeclaringType); - Assert.AreEqual(Accessibility.Private, method.Accessibility); - Assert.AreEqual(SymbolKind.Method, method.SymbolKind); - Assert.IsFalse(method.IsVirtual); - Assert.IsFalse(method.IsStatic); - Assert.AreEqual(0, method.Parameters.Count); - Assert.AreEqual(0, method.GetAttributes().Count()); - Assert.IsTrue(method.HasBody); - Assert.IsNull(method.AccessorOwner); + Assert.That(method.FullName, Is.EqualTo(c.FullName + ".Finalize")); + Assert.That(method.DeclaringType, Is.SameAs(c)); + Assert.That(method.Accessibility, Is.EqualTo(Accessibility.Private)); + Assert.That(method.SymbolKind, Is.EqualTo(SymbolKind.Method)); + Assert.That(!method.IsVirtual); + Assert.That(!method.IsStatic); + Assert.That(method.Parameters.Count, Is.EqualTo(0)); + Assert.That(method.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(method.HasBody); + Assert.That(method.AccessorOwner, Is.Null); } [Test] public void DefaultConstructorAddedToStruct() { var ctors = compilation.FindType(typeof(MyStructWithCtor)).GetConstructors(); - Assert.AreEqual(2, ctors.Count()); - Assert.IsFalse(ctors.Any(c => c.IsStatic)); - Assert.IsTrue(ctors.All(c => c.ReturnType.Kind == TypeKind.Void)); - Assert.IsTrue(ctors.All(c => c.Accessibility == Accessibility.Public)); + Assert.That(ctors.Count(), Is.EqualTo(2)); + Assert.That(!ctors.Any(c => c.IsStatic)); + Assert.That(ctors.All(c => c.ReturnType.Kind == TypeKind.Void)); + Assert.That(ctors.All(c => c.Accessibility == Accessibility.Public)); } [Test] public void NoDefaultConstructorAddedToStruct() { var ctors = compilation.FindType(typeof(MyStructWithDefaultCtor)).GetConstructors(); - Assert.AreEqual(1, ctors.Count()); - Assert.IsFalse(ctors.Any(c => c.IsStatic)); - Assert.IsTrue(ctors.All(c => c.ReturnType.Kind == TypeKind.Void)); - Assert.IsTrue(ctors.All(c => c.Accessibility == Accessibility.Public)); + Assert.That(ctors.Count(), Is.EqualTo(1)); + Assert.That(!ctors.Any(c => c.IsStatic)); + Assert.That(ctors.All(c => c.ReturnType.Kind == TypeKind.Void)); + Assert.That(ctors.All(c => c.Accessibility == Accessibility.Public)); } [Test] public void NoDefaultConstructorAddedToClass() { var ctors = compilation.FindType(typeof(MyClassWithCtor)).GetConstructors(); - Assert.AreEqual(Accessibility.Private, ctors.Single().Accessibility); - Assert.AreEqual(1, ctors.Single().Parameters.Count); + Assert.That(ctors.Single().Accessibility, Is.EqualTo(Accessibility.Private)); + Assert.That(ctors.Single().Parameters.Count, Is.EqualTo(1)); } [Test] public void DefaultConstructorOnAbstractClassIsProtected() { var ctors = compilation.FindType(typeof(AbstractClass)).GetConstructors(); - Assert.AreEqual(0, ctors.Single().Parameters.Count); - Assert.AreEqual(Accessibility.Protected, ctors.Single().Accessibility); + Assert.That(ctors.Single().Parameters.Count, Is.EqualTo(0)); + Assert.That(ctors.Single().Accessibility, Is.EqualTo(Accessibility.Protected)); } [Test] public void SerializableAttribute() { IAttribute attr = GetTypeDefinition(typeof(NonCustomAttributes)).GetAttributes().Single(); - Assert.AreEqual("System.SerializableAttribute", attr.AttributeType.FullName); + Assert.That(attr.AttributeType.FullName, Is.EqualTo("System.SerializableAttribute")); } [Test] public void NonSerializedAttribute() { IField field = GetTypeDefinition(typeof(NonCustomAttributes)).Fields.Single(f => f.Name == "NonSerializedField"); - Assert.AreEqual("System.NonSerializedAttribute", field.GetAttributes().Single().AttributeType.FullName); + Assert.That(field.GetAttributes().Single().AttributeType.FullName, Is.EqualTo("System.NonSerializedAttribute")); } [Test] public void ExplicitStructLayoutAttribute() { IAttribute attr = GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).GetAttributes().Single(); - Assert.AreEqual("System.Runtime.InteropServices.StructLayoutAttribute", attr.AttributeType.FullName); + Assert.That(attr.AttributeType.FullName, Is.EqualTo("System.Runtime.InteropServices.StructLayoutAttribute")); var arg1 = attr.FixedArguments.Single(); - Assert.AreEqual("System.Runtime.InteropServices.LayoutKind", arg1.Type.FullName); - Assert.AreEqual((int)LayoutKind.Explicit, arg1.Value); + Assert.That(arg1.Type.FullName, Is.EqualTo("System.Runtime.InteropServices.LayoutKind")); + Assert.That(arg1.Value, Is.EqualTo((int)LayoutKind.Explicit)); var arg2 = attr.NamedArguments[0]; - Assert.AreEqual("CharSet", arg2.Name); - Assert.AreEqual("System.Runtime.InteropServices.CharSet", arg2.Type.FullName); - Assert.AreEqual((int)CharSet.Unicode, arg2.Value); + Assert.That(arg2.Name, Is.EqualTo("CharSet")); + Assert.That(arg2.Type.FullName, Is.EqualTo("System.Runtime.InteropServices.CharSet")); + Assert.That(arg2.Value, Is.EqualTo((int)CharSet.Unicode)); var arg3 = attr.NamedArguments[1]; - Assert.AreEqual("Pack", arg3.Name); - Assert.AreEqual("System.Int32", arg3.Type.FullName); - Assert.AreEqual(8, arg3.Value); + Assert.That(arg3.Name, Is.EqualTo("Pack")); + Assert.That(arg3.Type.FullName, Is.EqualTo("System.Int32")); + Assert.That(arg3.Value, Is.EqualTo(8)); } [Test] public void FieldOffsetAttribute() { IField field = GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field0"); - Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.GetAttributes().Single().AttributeType.FullName); + Assert.That(field.GetAttributes().Single().AttributeType.FullName, Is.EqualTo("System.Runtime.InteropServices.FieldOffsetAttribute")); var arg = field.GetAttributes().Single().FixedArguments.Single(); - Assert.AreEqual("System.Int32", arg.Type.FullName); - Assert.AreEqual(0, arg.Value); + Assert.That(arg.Type.FullName, Is.EqualTo("System.Int32")); + Assert.That(arg.Value, Is.EqualTo(0)); field = GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field100"); - Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.GetAttributes().Single().AttributeType.FullName); + Assert.That(field.GetAttributes().Single().AttributeType.FullName, Is.EqualTo("System.Runtime.InteropServices.FieldOffsetAttribute")); arg = field.GetAttributes().Single().FixedArguments.Single(); - Assert.AreEqual("System.Int32", arg.Type.FullName); - Assert.AreEqual(100, arg.Value); + Assert.That(arg.Type.FullName, Is.EqualTo("System.Int32")); + Assert.That(arg.Value, Is.EqualTo(100)); } [Test] @@ -697,9 +694,9 @@ public void DllImportAttribute() { IMethod method = GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod"); IAttribute dllImport = method.GetAttributes().Single(); - Assert.AreEqual("System.Runtime.InteropServices.DllImportAttribute", dllImport.AttributeType.FullName); - Assert.AreEqual("unmanaged.dll", dllImport.FixedArguments[0].Value); - Assert.AreEqual((int)CharSet.Unicode, dllImport.NamedArguments.Single().Value); + Assert.That(dllImport.AttributeType.FullName, Is.EqualTo("System.Runtime.InteropServices.DllImportAttribute")); + Assert.That(dllImport.FixedArguments[0].Value, Is.EqualTo("unmanaged.dll")); + Assert.That(dllImport.NamedArguments.Single().Value, Is.EqualTo((int)CharSet.Unicode)); } [Test] @@ -707,9 +704,9 @@ public void DllImportAttributeWithPreserveSigFalse() { IMethod method = GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DoNotPreserveSig"); IAttribute dllImport = method.GetAttributes().Single(); - Assert.AreEqual("System.Runtime.InteropServices.DllImportAttribute", dllImport.AttributeType.FullName); - Assert.AreEqual("unmanaged.dll", dllImport.FixedArguments[0].Value); - Assert.AreEqual(false, dllImport.NamedArguments.Single().Value); + Assert.That(dllImport.AttributeType.FullName, Is.EqualTo("System.Runtime.InteropServices.DllImportAttribute")); + Assert.That(dllImport.FixedArguments[0].Value, Is.EqualTo("unmanaged.dll")); + Assert.That(dllImport.NamedArguments.Single().Value, Is.EqualTo(false)); } [Test] @@ -717,20 +714,20 @@ public void PreserveSigAttribute() { IMethod method = GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "PreserveSigAsAttribute"); IAttribute preserveSig = method.GetAttributes().Single(); - Assert.AreEqual("System.Runtime.InteropServices.PreserveSigAttribute", preserveSig.AttributeType.FullName); - Assert.IsTrue(preserveSig.FixedArguments.Length == 0); - Assert.IsTrue(preserveSig.NamedArguments.Length == 0); + Assert.That(preserveSig.AttributeType.FullName, Is.EqualTo("System.Runtime.InteropServices.PreserveSigAttribute")); + Assert.That(preserveSig.FixedArguments.Length == 0); + Assert.That(preserveSig.NamedArguments.Length == 0); } [Test] public void InOutParametersOnRefMethod() { IParameter p = GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod").Parameters.Single(); - Assert.AreEqual(ReferenceKind.Ref, p.ReferenceKind); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.Ref)); var attr = p.GetAttributes().ToList(); - Assert.AreEqual(2, attr.Count); - Assert.AreEqual("System.Runtime.InteropServices.InAttribute", attr[0].AttributeType.FullName); - Assert.AreEqual("System.Runtime.InteropServices.OutAttribute", attr[1].AttributeType.FullName); + Assert.That(attr.Count, Is.EqualTo(2)); + Assert.That(attr[0].AttributeType.FullName, Is.EqualTo("System.Runtime.InteropServices.InAttribute")); + Assert.That(attr[1].AttributeType.FullName, Is.EqualTo("System.Runtime.InteropServices.OutAttribute")); } [Test] @@ -738,70 +735,70 @@ public void MarshalAsAttributeOnMethod() { IMethod method = GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod"); IAttribute marshalAs = method.GetReturnTypeAttributes().Single(); - Assert.AreEqual((int)UnmanagedType.Bool, marshalAs.FixedArguments.Single().Value); + Assert.That(marshalAs.FixedArguments.Single().Value, Is.EqualTo((int)UnmanagedType.Bool)); } [Test] public void MethodWithOutParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithOutParameter").Parameters.Single(); - Assert.IsFalse(p.IsOptional); - Assert.AreEqual(ReferenceKind.Out, p.ReferenceKind); - Assert.AreEqual(0, p.GetAttributes().Count()); - Assert.IsTrue(p.Type.Kind == TypeKind.ByReference); + Assert.That(!p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.Out)); + Assert.That(p.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(p.Type.Kind == TypeKind.ByReference); } [Test] public void MethodWithRefParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithRefParameter").Parameters.Single(); - Assert.IsFalse(p.IsOptional); - Assert.AreEqual(ReferenceKind.Ref, p.ReferenceKind); - Assert.AreEqual(0, p.GetAttributes().Count()); - Assert.IsTrue(p.Type.Kind == TypeKind.ByReference); + Assert.That(!p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.Ref)); + Assert.That(p.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(p.Type.Kind == TypeKind.ByReference); } [Test] public void MethodWithInParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithInParameter").Parameters.Single(); - Assert.IsFalse(p.IsOptional); - Assert.AreEqual(ReferenceKind.In, p.ReferenceKind); - Assert.AreEqual(0, p.GetAttributes().Count()); - Assert.IsTrue(p.Type.Kind == TypeKind.ByReference); + Assert.That(!p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.In)); + Assert.That(p.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(p.Type.Kind == TypeKind.ByReference); } [Test] public void MethodWithParamsArray() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithParamsArray").Parameters.Single(); - Assert.IsFalse(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsTrue(p.IsParams); - Assert.AreEqual(0, p.GetAttributes().Count()); - Assert.IsTrue(p.Type.Kind == TypeKind.Array); + Assert.That(!p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(p.IsParams); + Assert.That(p.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(p.Type.Kind == TypeKind.Array); } [Test] public void MethodWithOptionalParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithOptionalParameter").Parameters.Single(); - Assert.IsTrue(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.IsTrue(p.HasConstantValueInSignature); - Assert.AreEqual(0, p.GetAttributes().Count()); - Assert.AreEqual(4, p.GetConstantValue()); + Assert.That(p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(p.HasConstantValueInSignature); + Assert.That(p.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(p.GetConstantValue(), Is.EqualTo(4)); } [Test] public void MethodWithExplicitOptionalParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithExplicitOptionalParameter").Parameters.Single(); - Assert.IsTrue(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.IsFalse(p.HasConstantValueInSignature); + Assert.That(p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(!p.HasConstantValueInSignature); // explicit optional parameter appears in type system if it's read from C#, but not when read from IL //Assert.AreEqual(1, p.GetAttributes().Count()); } @@ -810,103 +807,103 @@ public void MethodWithExplicitOptionalParameter() public void MethodWithEnumOptionalParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithEnumOptionalParameter").Parameters.Single(); - Assert.IsTrue(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.IsTrue(p.HasConstantValueInSignature); - Assert.AreEqual(0, p.GetAttributes().Count()); - Assert.AreEqual((int)StringComparison.OrdinalIgnoreCase, p.GetConstantValue()); + Assert.That(p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(p.HasConstantValueInSignature); + Assert.That(p.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(p.GetConstantValue(), Is.EqualTo((int)StringComparison.OrdinalIgnoreCase)); } [Test] public void MethodWithOptionalNullableParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithOptionalNullableParameter").Parameters.Single(); - Assert.IsTrue(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.IsTrue(p.HasConstantValueInSignature); - Assert.AreEqual(0, p.GetAttributes().Count()); - Assert.IsNull(p.GetConstantValue()); + Assert.That(p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(p.HasConstantValueInSignature); + Assert.That(p.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(p.GetConstantValue(), Is.Null); } [Test] public void MethodWithOptionalLongParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithOptionalLongParameter").Parameters.Single(); - Assert.IsTrue(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.IsTrue(p.HasConstantValueInSignature); - Assert.AreEqual(1L, p.GetConstantValue()); - Assert.AreEqual(typeof(long), p.GetConstantValue().GetType()); + Assert.That(p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(p.HasConstantValueInSignature); + Assert.That(p.GetConstantValue(), Is.EqualTo(1L)); + Assert.That(p.GetConstantValue().GetType(), Is.EqualTo(typeof(long))); } [Test] public void MethodWithOptionalNullableLongParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithOptionalNullableLongParameter").Parameters.Single(); - Assert.IsTrue(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.IsTrue(p.HasConstantValueInSignature); - Assert.AreEqual(1L, p.GetConstantValue()); - Assert.AreEqual(typeof(long), p.GetConstantValue().GetType()); + Assert.That(p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(p.HasConstantValueInSignature); + Assert.That(p.GetConstantValue(), Is.EqualTo(1L)); + Assert.That(p.GetConstantValue().GetType(), Is.EqualTo(typeof(long))); } [Test] public void MethodWithOptionalDecimalParameter() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithOptionalDecimalParameter").Parameters.Single(); - Assert.IsTrue(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.IsTrue(p.HasConstantValueInSignature); - Assert.AreEqual(1M, p.GetConstantValue()); - Assert.AreEqual(typeof(decimal), p.GetConstantValue().GetType()); + Assert.That(p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(p.HasConstantValueInSignature); + Assert.That(p.GetConstantValue(), Is.EqualTo(1M)); + Assert.That(p.GetConstantValue().GetType(), Is.EqualTo(typeof(decimal))); } [Test] public void VarArgsMethod() { IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "VarArgsMethod").Parameters.Single(); - Assert.IsFalse(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.AreEqual(TypeKind.ArgList, p.Type.Kind); - Assert.AreEqual("", p.Name); + Assert.That(!p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(p.Type.Kind, Is.EqualTo(TypeKind.ArgList)); + Assert.That(p.Name, Is.EqualTo("")); } [Test] public void VarArgsCtor() { IParameter p = GetTypeDefinition(typeof(VarArgsCtor)).Methods.Single(m => m.IsConstructor).Parameters.Single(); - Assert.IsFalse(p.IsOptional); - Assert.AreEqual(ReferenceKind.None, p.ReferenceKind); - Assert.IsFalse(p.IsParams); - Assert.AreEqual(TypeKind.ArgList, p.Type.Kind); - Assert.AreEqual("", p.Name); + Assert.That(!p.IsOptional); + Assert.That(p.ReferenceKind, Is.EqualTo(ReferenceKind.None)); + Assert.That(!p.IsParams); + Assert.That(p.Type.Kind, Is.EqualTo(TypeKind.ArgList)); + Assert.That(p.Name, Is.EqualTo("")); } [Test] public void GenericDelegate_Variance() { ITypeDefinition type = GetTypeDefinition(typeof(GenericDelegate<,>)); - Assert.AreEqual(VarianceModifier.Contravariant, type.TypeParameters[0].Variance); - Assert.AreEqual(VarianceModifier.Covariant, type.TypeParameters[1].Variance); + Assert.That(type.TypeParameters[0].Variance, Is.EqualTo(VarianceModifier.Contravariant)); + Assert.That(type.TypeParameters[1].Variance, Is.EqualTo(VarianceModifier.Covariant)); - Assert.AreSame(type.TypeParameters[1], type.TypeParameters[0].DirectBaseTypes.FirstOrDefault()); + Assert.That(type.TypeParameters[0].DirectBaseTypes.FirstOrDefault(), Is.SameAs(type.TypeParameters[1])); } [Test] public void GenericDelegate_ReferenceTypeConstraints() { ITypeDefinition type = GetTypeDefinition(typeof(GenericDelegate<,>)); - Assert.IsFalse(type.TypeParameters[0].HasReferenceTypeConstraint); - Assert.IsTrue(type.TypeParameters[1].HasReferenceTypeConstraint); + Assert.That(!type.TypeParameters[0].HasReferenceTypeConstraint); + Assert.That(type.TypeParameters[1].HasReferenceTypeConstraint); - Assert.IsNull(type.TypeParameters[0].IsReferenceType); - Assert.AreEqual(true, type.TypeParameters[1].IsReferenceType); + Assert.That(type.TypeParameters[0].IsReferenceType, Is.Null); + Assert.That(type.TypeParameters[1].IsReferenceType, Is.EqualTo(true)); } [Test] @@ -914,9 +911,9 @@ public void GenericDelegate_GetInvokeMethod() { IType type = compilation.FindType(typeof(GenericDelegate)); IMethod m = type.GetDelegateInvokeMethod(); - Assert.AreEqual("Invoke", m.Name); - Assert.AreEqual("System.Object", m.ReturnType.FullName); - Assert.AreEqual("System.String", m.Parameters[0].Type.FullName); + Assert.That(m.Name, Is.EqualTo("Invoke")); + Assert.That(m.ReturnType.FullName, Is.EqualTo("System.Object")); + Assert.That(m.Parameters[0].Type.FullName, Is.EqualTo("System.String")); } [Test] @@ -924,14 +921,14 @@ public void ComInterfaceTest() { ITypeDefinition type = GetTypeDefinition(typeof(IAssemblyEnum)); // [ComImport] - Assert.AreEqual(1, type.GetAttributes().Count(a => a.AttributeType.FullName == typeof(ComImportAttribute).FullName)); + Assert.That(type.GetAttributes().Count(a => a.AttributeType.FullName == typeof(ComImportAttribute).FullName), Is.EqualTo(1)); IMethod m = type.Methods.Single(); - Assert.AreEqual("GetNextAssembly", m.Name); - Assert.AreEqual(Accessibility.Public, m.Accessibility); - Assert.IsTrue(m.IsAbstract); - Assert.IsFalse(m.IsVirtual); - Assert.IsFalse(m.IsSealed); + Assert.That(m.Name, Is.EqualTo("GetNextAssembly")); + Assert.That(m.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(m.IsAbstract); + Assert.That(!m.IsVirtual); + Assert.That(!m.IsSealed); } [Test] @@ -943,9 +940,9 @@ public void InnerClassInGenericClassIsReferencedUsingParameterizedType() IField field3 = type.Fields.Single(f => f.Name == "Field3"); // types must be self-parameterized - Assert.AreEqual("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1+Inner[[`0]]", field1.Type.ReflectionName); - Assert.AreEqual("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1+Inner[[`0]]", field2.Type.ReflectionName); - Assert.AreEqual("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1+Inner[[ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1+Inner[[`0]]]]", field3.Type.ReflectionName); + Assert.That(field1.Type.ReflectionName, Is.EqualTo("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1+Inner[[`0]]")); + Assert.That(field2.Type.ReflectionName, Is.EqualTo("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1+Inner[[`0]]")); + Assert.That(field3.Type.ReflectionName, Is.EqualTo("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1+Inner[[ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1+Inner[[`0]]]]")); } [Test] @@ -953,67 +950,67 @@ public void FlagsOnInterfaceMembersAreCorrect() { ITypeDefinition type = GetTypeDefinition(typeof(IInterfaceWithProperty)); var p = type.Properties.Single(); - Assert.AreEqual(false, p.IsIndexer); - Assert.AreEqual(true, p.IsAbstract); - Assert.AreEqual(true, p.IsOverridable); - Assert.AreEqual(false, p.IsOverride); - Assert.AreEqual(Accessibility.Public, p.Accessibility); - Assert.AreEqual(true, p.Getter.IsAbstract); - Assert.AreEqual(true, p.Getter.IsOverridable); - Assert.AreEqual(false, p.Getter.IsOverride); - Assert.AreEqual(Accessibility.Public, p.Getter.Accessibility); - Assert.AreEqual(false, p.Getter.HasBody); - Assert.AreEqual(true, p.Setter.IsAbstract); - Assert.AreEqual(true, p.Setter.IsOverridable); - Assert.AreEqual(false, p.Setter.IsOverride); - Assert.AreEqual(Accessibility.Public, p.Setter.Accessibility); - Assert.AreEqual(false, p.Setter.HasBody); + Assert.That(p.IsIndexer, Is.EqualTo(false)); + Assert.That(p.IsAbstract, Is.EqualTo(true)); + Assert.That(p.IsOverridable, Is.EqualTo(true)); + Assert.That(p.IsOverride, Is.EqualTo(false)); + Assert.That(p.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.IsAbstract, Is.EqualTo(true)); + Assert.That(p.Getter.IsOverridable, Is.EqualTo(true)); + Assert.That(p.Getter.IsOverride, Is.EqualTo(false)); + Assert.That(p.Getter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.HasBody, Is.EqualTo(false)); + Assert.That(p.Setter.IsAbstract, Is.EqualTo(true)); + Assert.That(p.Setter.IsOverridable, Is.EqualTo(true)); + Assert.That(p.Setter.IsOverride, Is.EqualTo(false)); + Assert.That(p.Setter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Setter.HasBody, Is.EqualTo(false)); type = GetTypeDefinition(typeof(IInterfaceWithIndexers)); p = type.Properties.Single(x => x.Parameters.Count == 2); - Assert.AreEqual(true, p.IsIndexer); - Assert.AreEqual(true, p.IsAbstract); - Assert.AreEqual(true, p.IsOverridable); - Assert.AreEqual(false, p.IsOverride); - Assert.AreEqual(Accessibility.Public, p.Accessibility); - Assert.AreEqual(true, p.Getter.IsAbstract); - Assert.AreEqual(true, p.Getter.IsOverridable); - Assert.AreEqual(false, p.Getter.IsOverride); - Assert.AreEqual(Accessibility.Public, p.Getter.Accessibility); - Assert.AreEqual(true, p.Setter.IsAbstract); - Assert.AreEqual(true, p.Setter.IsOverridable); - Assert.AreEqual(false, p.Setter.IsOverride); - Assert.AreEqual(Accessibility.Public, p.Setter.Accessibility); + Assert.That(p.IsIndexer, Is.EqualTo(true)); + Assert.That(p.IsAbstract, Is.EqualTo(true)); + Assert.That(p.IsOverridable, Is.EqualTo(true)); + Assert.That(p.IsOverride, Is.EqualTo(false)); + Assert.That(p.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Getter.IsAbstract, Is.EqualTo(true)); + Assert.That(p.Getter.IsOverridable, Is.EqualTo(true)); + Assert.That(p.Getter.IsOverride, Is.EqualTo(false)); + Assert.That(p.Getter.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(p.Setter.IsAbstract, Is.EqualTo(true)); + Assert.That(p.Setter.IsOverridable, Is.EqualTo(true)); + Assert.That(p.Setter.IsOverride, Is.EqualTo(false)); + Assert.That(p.Setter.Accessibility, Is.EqualTo(Accessibility.Public)); type = GetTypeDefinition(typeof(IHasEvent)); var e = type.Events.Single(); - Assert.AreEqual(true, e.IsAbstract); - Assert.AreEqual(true, e.IsOverridable); - Assert.AreEqual(false, e.IsOverride); - Assert.AreEqual(Accessibility.Public, e.Accessibility); - Assert.AreEqual(true, e.AddAccessor.IsAbstract); - Assert.AreEqual(true, e.AddAccessor.IsOverridable); - Assert.AreEqual(false, e.AddAccessor.IsOverride); - Assert.AreEqual(Accessibility.Public, e.AddAccessor.Accessibility); - Assert.AreEqual(true, e.RemoveAccessor.IsAbstract); - Assert.AreEqual(true, e.RemoveAccessor.IsOverridable); - Assert.AreEqual(false, e.RemoveAccessor.IsOverride); - Assert.AreEqual(Accessibility.Public, e.RemoveAccessor.Accessibility); + Assert.That(e.IsAbstract, Is.EqualTo(true)); + Assert.That(e.IsOverridable, Is.EqualTo(true)); + Assert.That(e.IsOverride, Is.EqualTo(false)); + Assert.That(e.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(e.AddAccessor.IsAbstract, Is.EqualTo(true)); + Assert.That(e.AddAccessor.IsOverridable, Is.EqualTo(true)); + Assert.That(e.AddAccessor.IsOverride, Is.EqualTo(false)); + Assert.That(e.AddAccessor.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(e.RemoveAccessor.IsAbstract, Is.EqualTo(true)); + Assert.That(e.RemoveAccessor.IsOverridable, Is.EqualTo(true)); + Assert.That(e.RemoveAccessor.IsOverride, Is.EqualTo(false)); + Assert.That(e.RemoveAccessor.Accessibility, Is.EqualTo(Accessibility.Public)); type = GetTypeDefinition(typeof(IDisposable)); var m = type.Methods.Single(); - Assert.AreEqual(true, m.IsAbstract); - Assert.AreEqual(true, m.IsOverridable); - Assert.AreEqual(false, m.IsOverride); - Assert.AreEqual(Accessibility.Public, m.Accessibility); + Assert.That(m.IsAbstract, Is.EqualTo(true)); + Assert.That(m.IsOverridable, Is.EqualTo(true)); + Assert.That(m.IsOverride, Is.EqualTo(false)); + Assert.That(m.Accessibility, Is.EqualTo(Accessibility.Public)); } [Test] public void InnerClassInGenericClass_TypeParameterOwner() { ITypeDefinition type = GetTypeDefinition(typeof(OuterGeneric<>.Inner)); - Assert.AreSame(type.DeclaringTypeDefinition.TypeParameters[0], type.TypeParameters[0]); - Assert.AreSame(type.DeclaringTypeDefinition, type.TypeParameters[0].Owner); + Assert.That(type.TypeParameters[0], Is.SameAs(type.DeclaringTypeDefinition.TypeParameters[0])); + Assert.That(type.TypeParameters[0].Owner, Is.SameAs(type.DeclaringTypeDefinition)); } [Test] @@ -1021,7 +1018,7 @@ public void InnerClassInGenericClass_ReferencesTheOuterClass_Field() { ITypeDefinition type = GetTypeDefinition(typeof(OuterGeneric<>.Inner)); IField f = type.Fields.Single(); - Assert.AreEqual("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1[[`0]]", f.Type.ReflectionName); + Assert.That(f.Type.ReflectionName, Is.EqualTo("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1[[`0]]")); } [Test] @@ -1029,14 +1026,14 @@ public void InnerClassInGenericClass_ReferencesTheOuterClass_Parameter() { ITypeDefinition type = GetTypeDefinition(typeof(OuterGeneric<>.Inner)); IParameter p = type.Methods.Single(m => m.IsConstructor).Parameters.Single(); - Assert.AreEqual("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1[[`0]]", p.Type.ReflectionName); + Assert.That(p.Type.ReflectionName, Is.EqualTo("ICSharpCode.Decompiler.Tests.TypeSystem.OuterGeneric`1[[`0]]")); } CustomAttributeTypedArgument GetParamsAttributeArgument(int index) { ITypeDefinition type = GetTypeDefinition(typeof(ParamsAttribute)); var arr = (AttributeArray)type.GetAttributes().Single().FixedArguments.Single().Value; - Assert.AreEqual(5, arr.Length); + Assert.That(arr.Length, Is.EqualTo(5)); return arr[index]; } @@ -1044,16 +1041,16 @@ CustomAttributeTypedArgument GetParamsAttributeArgument(int index) public void ParamsAttribute_Integer() { var arg = GetParamsAttributeArgument(0); - Assert.AreEqual("System.Int32", arg.Type.FullName); - Assert.AreEqual(1, arg.Value); + Assert.That(arg.Type.FullName, Is.EqualTo("System.Int32")); + Assert.That(arg.Value, Is.EqualTo(1)); } [Test] public void ParamsAttribute_Enum() { var arg = GetParamsAttributeArgument(1); - Assert.AreEqual("System.StringComparison", arg.Type.FullName); - Assert.AreEqual((int)StringComparison.CurrentCulture, arg.Value); + Assert.That(arg.Type.FullName, Is.EqualTo("System.StringComparison")); + Assert.That(arg.Value, Is.EqualTo((int)StringComparison.CurrentCulture)); } [Test] @@ -1061,23 +1058,23 @@ public void ParamsAttribute_NullReference() { var arg = GetParamsAttributeArgument(2); //Assert.AreEqual("System.Object", arg.Type.FullName); - Assert.IsNull(arg.Value); + Assert.That(arg.Value, Is.Null); } [Test] public void ParamsAttribute_Double() { var arg = GetParamsAttributeArgument(3); - Assert.AreEqual("System.Double", arg.Type.FullName); - Assert.AreEqual(4.0, arg.Value); + Assert.That(arg.Type.FullName, Is.EqualTo("System.Double")); + Assert.That(arg.Value, Is.EqualTo(4.0)); } [Test] public void ParamsAttribute_String() { var arg = GetParamsAttributeArgument(4); - Assert.AreEqual("System.String", arg.Type.FullName); - Assert.AreEqual("Test", arg.Value); + Assert.That(arg.Type.FullName, Is.EqualTo("System.String")); + Assert.That(arg.Value, Is.EqualTo("Test")); } [Test] @@ -1086,15 +1083,15 @@ public void ParamsAttribute_Property() ITypeDefinition type = GetTypeDefinition(typeof(ParamsAttribute)); IProperty prop = type.Properties.Single(p => p.Name == "Property"); var attr = prop.GetAttributes().Single(); - Assert.AreEqual(type, attr.AttributeType); + Assert.That(attr.AttributeType, Is.EqualTo(type)); var elements = (AttributeArray)attr.FixedArguments.Single().Value; - Assert.AreEqual(0, elements.Length); + Assert.That(elements.Length, Is.EqualTo(0)); var namedArg = attr.NamedArguments.Single(); - Assert.AreEqual(prop.Name, namedArg.Name); + Assert.That(namedArg.Name, Is.EqualTo(prop.Name)); var arrayElements = (AttributeArray)namedArg.Value; - Assert.AreEqual(2, arrayElements.Length); + Assert.That(arrayElements.Length, Is.EqualTo(2)); } [Test] @@ -1102,8 +1099,8 @@ public void ParamsAttribute_Getter_ReturnType() { ITypeDefinition type = GetTypeDefinition(typeof(ParamsAttribute)); IProperty prop = type.Properties.Single(p => p.Name == "Property"); - Assert.AreEqual(0, prop.Getter.GetAttributes().Count()); - Assert.AreEqual(1, prop.Getter.GetReturnTypeAttributes().Count()); + Assert.That(prop.Getter.GetAttributes().Count(), Is.EqualTo(0)); + Assert.That(prop.Getter.GetReturnTypeAttributes().Count(), Is.EqualTo(1)); } [Test] @@ -1111,8 +1108,8 @@ public void DoubleAttribute_ImplicitNumericConversion() { ITypeDefinition type = GetTypeDefinition(typeof(DoubleAttribute)); var arg = type.GetAttributes().Single().FixedArguments.Single(); - Assert.AreEqual("System.Double", arg.Type.ReflectionName); - Assert.AreEqual(1.0, arg.Value); + Assert.That(arg.Type.ReflectionName, Is.EqualTo("System.Double")); + Assert.That(arg.Value, Is.EqualTo(1.0)); } /* TS no longer provides implicitly implemented interface members. @@ -1135,24 +1132,24 @@ public void StaticityOfEventAccessors() // https://github.com/icsharpcode/NRefactory/issues/20 ITypeDefinition type = GetTypeDefinition(typeof(ClassWithStaticAndNonStaticMembers)); var evt1 = type.Events.Single(e => e.Name == "Event1"); - Assert.IsTrue(evt1.IsStatic); - Assert.IsTrue(evt1.AddAccessor.IsStatic); - Assert.IsTrue(evt1.RemoveAccessor.IsStatic); + Assert.That(evt1.IsStatic); + Assert.That(evt1.AddAccessor.IsStatic); + Assert.That(evt1.RemoveAccessor.IsStatic); var evt2 = type.Events.Single(e => e.Name == "Event2"); - Assert.IsFalse(evt2.IsStatic); - Assert.IsFalse(evt2.AddAccessor.IsStatic); - Assert.IsFalse(evt2.RemoveAccessor.IsStatic); + Assert.That(!evt2.IsStatic); + Assert.That(!evt2.AddAccessor.IsStatic); + Assert.That(!evt2.RemoveAccessor.IsStatic); var evt3 = type.Events.Single(e => e.Name == "Event3"); - Assert.IsTrue(evt3.IsStatic); - Assert.IsTrue(evt3.AddAccessor.IsStatic); - Assert.IsTrue(evt3.RemoveAccessor.IsStatic); + Assert.That(evt3.IsStatic); + Assert.That(evt3.AddAccessor.IsStatic); + Assert.That(evt3.RemoveAccessor.IsStatic); var evt4 = type.Events.Single(e => e.Name == "Event4"); - Assert.IsFalse(evt4.IsStatic); - Assert.IsFalse(evt4.AddAccessor.IsStatic); - Assert.IsFalse(evt4.RemoveAccessor.IsStatic); + Assert.That(!evt4.IsStatic); + Assert.That(!evt4.AddAccessor.IsStatic); + Assert.That(!evt4.RemoveAccessor.IsStatic); } [Test] @@ -1161,24 +1158,24 @@ public void StaticityOfPropertyAccessors() // https://github.com/icsharpcode/NRefactory/issues/20 ITypeDefinition type = GetTypeDefinition(typeof(ClassWithStaticAndNonStaticMembers)); var prop1 = type.Properties.Single(e => e.Name == "Prop1"); - Assert.IsTrue(prop1.IsStatic); - Assert.IsTrue(prop1.Getter.IsStatic); - Assert.IsTrue(prop1.Setter.IsStatic); + Assert.That(prop1.IsStatic); + Assert.That(prop1.Getter.IsStatic); + Assert.That(prop1.Setter.IsStatic); var prop2 = type.Properties.Single(e => e.Name == "Prop2"); - Assert.IsFalse(prop2.IsStatic); - Assert.IsFalse(prop2.Getter.IsStatic); - Assert.IsFalse(prop2.Setter.IsStatic); + Assert.That(!prop2.IsStatic); + Assert.That(!prop2.Getter.IsStatic); + Assert.That(!prop2.Setter.IsStatic); var prop3 = type.Properties.Single(e => e.Name == "Prop3"); - Assert.IsTrue(prop3.IsStatic); - Assert.IsTrue(prop3.Getter.IsStatic); - Assert.IsTrue(prop3.Setter.IsStatic); + Assert.That(prop3.IsStatic); + Assert.That(prop3.Getter.IsStatic); + Assert.That(prop3.Setter.IsStatic); var prop4 = type.Properties.Single(e => e.Name == "Prop4"); - Assert.IsFalse(prop4.IsStatic); - Assert.IsFalse(prop4.Getter.IsStatic); - Assert.IsFalse(prop4.Setter.IsStatic); + Assert.That(!prop4.IsStatic); + Assert.That(!prop4.Getter.IsStatic); + Assert.That(!prop4.Setter.IsStatic); } [Test] @@ -1187,8 +1184,8 @@ public void PropertyAccessorsHaveBody() ITypeDefinition type = GetTypeDefinition(typeof(ClassWithStaticAndNonStaticMembers)); foreach (var prop in type.Properties) { - Assert.IsTrue(prop.Getter.HasBody, prop.Getter.Name); - Assert.IsTrue(prop.Setter.HasBody, prop.Setter.Name); + Assert.That(prop.Getter.HasBody, prop.Getter.Name); + Assert.That(prop.Setter.HasBody, prop.Setter.Name); } } @@ -1197,12 +1194,12 @@ public void EventAccessorNames() { ITypeDefinition type = GetTypeDefinition(typeof(ClassWithStaticAndNonStaticMembers)); var customEvent = type.Events.Single(e => e.Name == "Event1"); - Assert.AreEqual("add_Event1", customEvent.AddAccessor.Name); - Assert.AreEqual("remove_Event1", customEvent.RemoveAccessor.Name); + Assert.That(customEvent.AddAccessor.Name, Is.EqualTo("add_Event1")); + Assert.That(customEvent.RemoveAccessor.Name, Is.EqualTo("remove_Event1")); var normalEvent = type.Events.Single(e => e.Name == "Event3"); - Assert.AreEqual("add_Event3", normalEvent.AddAccessor.Name); - Assert.AreEqual("remove_Event3", normalEvent.RemoveAccessor.Name); + Assert.That(normalEvent.AddAccessor.Name, Is.EqualTo("add_Event3")); + Assert.That(normalEvent.RemoveAccessor.Name, Is.EqualTo("remove_Event3")); } [Test] @@ -1211,8 +1208,8 @@ public void EventAccessorHaveBody() ITypeDefinition type = GetTypeDefinition(typeof(ClassWithStaticAndNonStaticMembers)); foreach (var ev in type.Events) { - Assert.IsTrue(ev.AddAccessor.HasBody, ev.AddAccessor.Name); - Assert.IsTrue(ev.RemoveAccessor.HasBody, ev.RemoveAccessor.Name); + Assert.That(ev.AddAccessor.HasBody, ev.AddAccessor.Name); + Assert.That(ev.RemoveAccessor.HasBody, ev.RemoveAccessor.Name); } } @@ -1270,8 +1267,8 @@ public void ClassThatOverridesGetterOnly() { ITypeDefinition type = GetTypeDefinition(typeof(ClassThatOverridesGetterOnly)); var prop = type.Properties.Single(p => p.Name == "Prop"); - Assert.AreEqual(Accessibility.Public, prop.Accessibility); - Assert.AreEqual(Accessibility.Public, prop.Getter.Accessibility); + Assert.That(prop.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(prop.Getter.Accessibility, Is.EqualTo(Accessibility.Public)); } [Test] @@ -1279,8 +1276,8 @@ public void ClassThatOverridesSetterOnly() { ITypeDefinition type = GetTypeDefinition(typeof(ClassThatOverridesSetterOnly)); var prop = type.Properties.Single(p => p.Name == "Prop"); - Assert.AreEqual(Accessibility.Public, prop.Accessibility); - Assert.AreEqual(Accessibility.Protected, prop.Setter.Accessibility); + Assert.That(prop.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(prop.Setter.Accessibility, Is.EqualTo(Accessibility.Protected)); } /* TS no longer provides implicit interface impls @@ -1300,9 +1297,9 @@ public void PropertyThatImplementsInterfaceIsNotVirtual() { ITypeDefinition type = GetTypeDefinition(typeof(ClassThatImplementsProperty)); var prop = type.Properties.Single(p => p.Name == "Prop"); - Assert.IsFalse(prop.IsVirtual); - Assert.IsFalse(prop.IsOverridable); - Assert.IsFalse(prop.IsSealed); + Assert.That(!prop.IsVirtual); + Assert.That(!prop.IsOverridable); + Assert.That(!prop.IsSealed); } [Test] @@ -1310,10 +1307,10 @@ public void Property_SealedOverride() { ITypeDefinition type = GetTypeDefinition(typeof(ClassThatOverridesAndSealsVirtualProperty)); var prop = type.Properties.Single(p => p.Name == "Prop"); - Assert.IsFalse(prop.IsVirtual); - Assert.IsTrue(prop.IsOverride); - Assert.IsTrue(prop.IsSealed); - Assert.IsFalse(prop.IsOverridable); + Assert.That(!prop.IsVirtual); + Assert.That(prop.IsOverride); + Assert.That(prop.IsSealed); + Assert.That(!prop.IsOverridable); } /* The TS no longer provides implicit interface impls. @@ -1365,26 +1362,26 @@ public void ExplicitDisposableImplementation() { ITypeDefinition disposable = GetTypeDefinition(typeof(ExplicitDisposableImplementation)); IMethod method = disposable.Methods.Single(m => !m.IsConstructor); - Assert.IsTrue(method.IsExplicitInterfaceImplementation); - Assert.AreEqual("System.IDisposable.Dispose", method.ExplicitlyImplementedInterfaceMembers.Single().FullName); + Assert.That(method.IsExplicitInterfaceImplementation); + Assert.That(method.ExplicitlyImplementedInterfaceMembers.Single().FullName, Is.EqualTo("System.IDisposable.Dispose")); } [Test] public void ExplicitImplementationOfUnifiedMethods() { IType type = compilation.FindType(typeof(ExplicitGenericInterfaceImplementationWithUnifiableMethods)); - Assert.AreEqual(2, type.GetMethods(m => m.IsExplicitInterfaceImplementation).Count()); + Assert.That(type.GetMethods(m => m.IsExplicitInterfaceImplementation).Count(), Is.EqualTo(2)); foreach (IMethod method in type.GetMethods(m => m.IsExplicitInterfaceImplementation)) { - Assert.AreEqual(1, method.ExplicitlyImplementedInterfaceMembers.Count(), method.ToString()); - Assert.AreEqual("System.Int32", method.Parameters.Single().Type.ReflectionName); + Assert.That(method.ExplicitlyImplementedInterfaceMembers.Count(), Is.EqualTo(1), method.ToString()); + Assert.That(method.Parameters.Single().Type.ReflectionName, Is.EqualTo("System.Int32")); IMethod interfaceMethod = (IMethod)method.ExplicitlyImplementedInterfaceMembers.Single(); - Assert.AreEqual("System.Int32", interfaceMethod.Parameters.Single().Type.ReflectionName); + Assert.That(interfaceMethod.Parameters.Single().Type.ReflectionName, Is.EqualTo("System.Int32")); var genericParamType = ((IMethod)method.MemberDefinition).Parameters.Single().Type; var interfaceGenericParamType = ((IMethod)interfaceMethod.MemberDefinition).Parameters.Single().Type; - Assert.AreEqual(TypeKind.TypeParameter, genericParamType.Kind); - Assert.AreEqual(TypeKind.TypeParameter, interfaceGenericParamType.Kind); - Assert.AreEqual(genericParamType.ReflectionName, interfaceGenericParamType.ReflectionName); + Assert.That(genericParamType.Kind, Is.EqualTo(TypeKind.TypeParameter)); + Assert.That(interfaceGenericParamType.Kind, Is.EqualTo(TypeKind.TypeParameter)); + Assert.That(interfaceGenericParamType.ReflectionName, Is.EqualTo(genericParamType.ReflectionName)); } } @@ -1395,16 +1392,16 @@ public void ExplicitGenericInterfaceImplementation() IType genericInterfaceOfString = compilation.FindType(typeof(IGenericInterface)); IMethod implMethod1 = impl.Methods.Single(m => !m.IsConstructor && !m.Parameters[1].IsRef); IMethod implMethod2 = impl.Methods.Single(m => !m.IsConstructor && m.Parameters[1].IsRef); - Assert.IsTrue(implMethod1.IsExplicitInterfaceImplementation); - Assert.IsTrue(implMethod2.IsExplicitInterfaceImplementation); + Assert.That(implMethod1.IsExplicitInterfaceImplementation); + Assert.That(implMethod2.IsExplicitInterfaceImplementation); IMethod interfaceMethod1 = (IMethod)implMethod1.ExplicitlyImplementedInterfaceMembers.Single(); - Assert.AreEqual(genericInterfaceOfString, interfaceMethod1.DeclaringType); - Assert.IsTrue(!interfaceMethod1.Parameters[1].IsRef); + Assert.That(interfaceMethod1.DeclaringType, Is.EqualTo(genericInterfaceOfString)); + Assert.That(!interfaceMethod1.Parameters[1].IsRef); IMethod interfaceMethod2 = (IMethod)implMethod2.ExplicitlyImplementedInterfaceMembers.Single(); - Assert.AreEqual(genericInterfaceOfString, interfaceMethod2.DeclaringType); - Assert.IsTrue(interfaceMethod2.Parameters[1].IsRef); + Assert.That(interfaceMethod2.DeclaringType, Is.EqualTo(genericInterfaceOfString)); + Assert.That(interfaceMethod2.Parameters[1].IsRef); } [Test] @@ -1422,9 +1419,9 @@ public void ExplicitlyImplementedPropertiesShouldHaveExplicitlyImplementedAccess { ITypeDefinition type = GetTypeDefinition(typeof(ClassThatImplementsPropertyExplicitly)); var prop = type.Properties.Single(); - Assert.IsTrue(prop.IsExplicitInterfaceImplementation); - Assert.IsTrue(prop.Getter.IsExplicitInterfaceImplementation); - Assert.IsTrue(prop.Setter.IsExplicitInterfaceImplementation); + Assert.That(prop.IsExplicitInterfaceImplementation); + Assert.That(prop.Getter.IsExplicitInterfaceImplementation); + Assert.That(prop.Setter.IsExplicitInterfaceImplementation); } /* The TS no longer provides implicit interface impls. @@ -1484,9 +1481,9 @@ public void MembersDeclaredInDerivedInterfacesDoNotImplementBaseMembers() public void StaticClassTest() { ITypeDefinition type = GetTypeDefinition(typeof(StaticClass)); - Assert.IsTrue(type.IsAbstract); - Assert.IsTrue(type.IsSealed); - Assert.IsTrue(type.IsStatic); + Assert.That(type.IsAbstract); + Assert.That(type.IsSealed); + Assert.That(type.IsStatic); } [Test] @@ -1495,18 +1492,18 @@ public void ExtensionMethodTest() ITypeDefinition type = GetTypeDefinition(typeof(StaticClass)); var method = type.Methods.Single(m => m.Name == "Extension"); - Assert.IsTrue(method.IsStatic); - Assert.IsTrue(method.IsExtensionMethod); - Assert.IsNull(method.ReducedFrom); + Assert.That(method.IsStatic); + Assert.That(method.IsExtensionMethod); + Assert.That(method.ReducedFrom, Is.Null); - Assert.IsTrue(type.HasExtensionMethods); + Assert.That(type.HasExtensionMethods); } [Test] public void NoDefaultConstructorOnStaticClassTest() { ITypeDefinition type = GetTypeDefinition(typeof(StaticClass)); - Assert.AreEqual(0, type.GetConstructors().Count()); + Assert.That(type.GetConstructors().Count(), Is.EqualTo(0)); } [Test] @@ -1514,7 +1511,7 @@ public void IndexerNonDefaultName() { ITypeDefinition type = GetTypeDefinition(typeof(IndexerNonDefaultName)); var indexer = type.GetProperties(p => p.IsIndexer).Single(); - Assert.AreEqual("Foo", indexer.Name); + Assert.That(indexer.Name, Is.EqualTo("Foo")); } [Test] @@ -1522,28 +1519,28 @@ public void TestNullableDefaultParameter() { ITypeDefinition type = GetTypeDefinition(typeof(ClassWithMethodThatHasNullableDefaultParameter)); var method = type.GetMethods().Single(m => m.Name == "Foo"); - Assert.AreEqual(42, method.Parameters.Single().GetConstantValue()); + Assert.That(method.Parameters.Single().GetConstantValue(), Is.EqualTo(42)); } [Test] public void AccessibilityTests() { ITypeDefinition type = GetTypeDefinition(typeof(AccessibilityTest)); - Assert.AreEqual(Accessibility.Public, type.Methods.Single(m => m.Name == "Public").Accessibility); - Assert.AreEqual(Accessibility.Internal, type.Methods.Single(m => m.Name == "Internal").Accessibility); - Assert.AreEqual(Accessibility.ProtectedOrInternal, type.Methods.Single(m => m.Name == "ProtectedInternal").Accessibility); - Assert.AreEqual(Accessibility.ProtectedOrInternal, type.Methods.Single(m => m.Name == "InternalProtected").Accessibility); - Assert.AreEqual(Accessibility.Protected, type.Methods.Single(m => m.Name == "Protected").Accessibility); - Assert.AreEqual(Accessibility.Private, type.Methods.Single(m => m.Name == "Private").Accessibility); - Assert.AreEqual(Accessibility.Private, type.Methods.Single(m => m.Name == "None").Accessibility); + Assert.That(type.Methods.Single(m => m.Name == "Public").Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(type.Methods.Single(m => m.Name == "Internal").Accessibility, Is.EqualTo(Accessibility.Internal)); + Assert.That(type.Methods.Single(m => m.Name == "ProtectedInternal").Accessibility, Is.EqualTo(Accessibility.ProtectedOrInternal)); + Assert.That(type.Methods.Single(m => m.Name == "InternalProtected").Accessibility, Is.EqualTo(Accessibility.ProtectedOrInternal)); + Assert.That(type.Methods.Single(m => m.Name == "Protected").Accessibility, Is.EqualTo(Accessibility.Protected)); + Assert.That(type.Methods.Single(m => m.Name == "Private").Accessibility, Is.EqualTo(Accessibility.Private)); + Assert.That(type.Methods.Single(m => m.Name == "None").Accessibility, Is.EqualTo(Accessibility.Private)); } private void AssertConstantField(ITypeDefinition type, string name, T expected) { var f = type.GetFields().Single(x => x.Name == name); - Assert.IsTrue(f.IsConst); - Assert.AreEqual(expected, f.GetConstantValue()); - Assert.AreEqual(0, f.GetAttributes().Count()); + Assert.That(f.IsConst); + Assert.That(f.GetConstantValue(), Is.EqualTo(expected)); + Assert.That(f.GetAttributes().Count(), Is.EqualTo(0)); } [Test] @@ -1589,8 +1586,8 @@ public void ConstantEnumFromThisAssembly() { ITypeDefinition type = GetTypeDefinition(typeof(ConstantFieldTest)); IField field = type.Fields.Single(f => f.Name == "EnumFromThisAssembly"); - Assert.IsTrue(field.IsConst); - Assert.AreEqual((short)MyEnum.Second, field.GetConstantValue()); + Assert.That(field.IsConst); + Assert.That(field.GetConstantValue(), Is.EqualTo((short)MyEnum.Second)); } [Test] @@ -1598,8 +1595,8 @@ public void ConstantEnumFromAnotherAssembly() { ITypeDefinition type = GetTypeDefinition(typeof(ConstantFieldTest)); IField field = type.Fields.Single(f => f.Name == "EnumFromAnotherAssembly"); - Assert.IsTrue(field.IsConst); - Assert.AreEqual((int)StringComparison.OrdinalIgnoreCase, field.GetConstantValue()); + Assert.That(field.IsConst); + Assert.That(field.GetConstantValue(), Is.EqualTo((int)StringComparison.OrdinalIgnoreCase)); } [Test] @@ -1607,8 +1604,8 @@ public void DefaultOfEnum() { ITypeDefinition type = GetTypeDefinition(typeof(ConstantFieldTest)); IField field = type.Fields.Single(f => f.Name == "DefaultOfEnum"); - Assert.IsTrue(field.IsConst); - Assert.AreEqual((short)default(MyEnum), field.GetConstantValue()); + Assert.That(field.IsConst); + Assert.That(field.GetConstantValue(), Is.EqualTo((short)default(MyEnum))); } [Test] @@ -1620,41 +1617,41 @@ public void ExplicitImplementation() var methods = type.GetMethods(m => m.Name == "M" || m.Name.EndsWith(".M")).ToList(); var imethod = itype.GetMethods(m => m.Name == "M").Single(); Assert.That(methods.Select(m => m.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(methods.SelectMany(m => m.ExplicitlyImplementedInterfaceMembers).Single(), imethod); + Assert.That(imethod, Is.EqualTo(methods.SelectMany(m => m.ExplicitlyImplementedInterfaceMembers).Single())); var properties = type.GetProperties(p => p.Name == "P" || p.Name.EndsWith(".P")).ToList(); var iproperty = itype.GetProperties(m => m.Name == "P").Single(); Assert.That(properties.Select(p => p.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(properties.SelectMany(p => p.ExplicitlyImplementedInterfaceMembers).Single(), iproperty); + Assert.That(iproperty, Is.EqualTo(properties.SelectMany(p => p.ExplicitlyImplementedInterfaceMembers).Single())); Assert.That(properties.Select(p => p.Getter.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(properties.SelectMany(p => p.Getter.ExplicitlyImplementedInterfaceMembers).Single(), iproperty.Getter); + Assert.That(iproperty.Getter, Is.EqualTo(properties.SelectMany(p => p.Getter.ExplicitlyImplementedInterfaceMembers).Single())); Assert.That(properties.Select(p => p.Setter.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(properties.SelectMany(p => p.Setter.ExplicitlyImplementedInterfaceMembers).Single(), iproperty.Setter); + Assert.That(iproperty.Setter, Is.EqualTo(properties.SelectMany(p => p.Setter.ExplicitlyImplementedInterfaceMembers).Single())); var indexers = type.GetProperties(p => p.Name == "Item" || p.Name.EndsWith(".Item")).ToList(); var iindexer = itype.GetProperties(m => m.Name == "Item").Single(); Assert.That(indexers.Select(p => p.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(indexers.SelectMany(p => p.ExplicitlyImplementedInterfaceMembers).Single(), iindexer); + Assert.That(iindexer, Is.EqualTo(indexers.SelectMany(p => p.ExplicitlyImplementedInterfaceMembers).Single())); Assert.That(indexers.Select(p => p.Getter.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(indexers.SelectMany(p => p.Getter.ExplicitlyImplementedInterfaceMembers).Single(), iindexer.Getter); + Assert.That(iindexer.Getter, Is.EqualTo(indexers.SelectMany(p => p.Getter.ExplicitlyImplementedInterfaceMembers).Single())); Assert.That(indexers.Select(p => p.Setter.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(indexers.SelectMany(p => p.Setter.ExplicitlyImplementedInterfaceMembers).Single(), iindexer.Setter); + Assert.That(iindexer.Setter, Is.EqualTo(indexers.SelectMany(p => p.Setter.ExplicitlyImplementedInterfaceMembers).Single())); var events = type.GetEvents(e => e.Name == "E" || e.Name.EndsWith(".E")).ToList(); var ievent = itype.GetEvents(m => m.Name == "E").Single(); Assert.That(events.Select(e => e.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(events.SelectMany(e => e.ExplicitlyImplementedInterfaceMembers).Single(), ievent); + Assert.That(ievent, Is.EqualTo(events.SelectMany(e => e.ExplicitlyImplementedInterfaceMembers).Single())); Assert.That(events.Select(e => e.AddAccessor.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(events.SelectMany(e => e.AddAccessor.ExplicitlyImplementedInterfaceMembers).Single(), ievent.AddAccessor); + Assert.That(ievent.AddAccessor, Is.EqualTo(events.SelectMany(e => e.AddAccessor.ExplicitlyImplementedInterfaceMembers).Single())); Assert.That(events.Select(e => e.RemoveAccessor.ExplicitlyImplementedInterfaceMembers.Count()).ToList(), Is.EquivalentTo(new[] { 0, 1 })); - Assert.AreEqual(events.SelectMany(e => e.RemoveAccessor.ExplicitlyImplementedInterfaceMembers).Single(), ievent.RemoveAccessor); + Assert.That(ievent.RemoveAccessor, Is.EqualTo(events.SelectMany(e => e.RemoveAccessor.ExplicitlyImplementedInterfaceMembers).Single())); } [Test] public void MarshalTests() { ITypeDefinition c = compilation.FindType(typeof(IMarshalAsTests)).GetDefinition(); - Assert.AreEqual(1, c.GetMethods(m => m.Name == "GetCollectionByQuery2").Count()); + Assert.That(c.GetMethods(m => m.Name == "GetCollectionByQuery2").Count(), Is.EqualTo(1)); } @@ -1665,33 +1662,33 @@ public void AttributesUsingNestedMembers() var inner = type.GetNestedTypes().Single(t => t.Name == "Inner"); var myAttribute = type.GetNestedTypes().Single(t => t.Name == "MyAttribute"); var typeTypeTestAttr = type.GetAttributes().Single(a => a.AttributeType.Name == "TypeTestAttribute"); - Assert.AreEqual(42, typeTypeTestAttr.FixedArguments[0].Value); - Assert.AreEqual(inner, typeTypeTestAttr.FixedArguments[1].Value); + Assert.That(typeTypeTestAttr.FixedArguments[0].Value, Is.EqualTo(42)); + Assert.That(typeTypeTestAttr.FixedArguments[1].Value, Is.EqualTo(inner)); var typeMyAttr = type.GetAttributes().Single(a => a.AttributeType.Name == "MyAttribute"); - Assert.AreEqual(myAttribute, typeMyAttr.AttributeType); + Assert.That(typeMyAttr.AttributeType, Is.EqualTo(myAttribute)); var prop = type.GetProperties().Single(p => p.Name == "P"); var propTypeTestAttr = prop.GetAttributes().Single(a => a.AttributeType.Name == "TypeTestAttribute"); - Assert.AreEqual(42, propTypeTestAttr.FixedArguments[0].Value); - Assert.AreEqual(inner, propTypeTestAttr.FixedArguments[1].Value); + Assert.That(propTypeTestAttr.FixedArguments[0].Value, Is.EqualTo(42)); + Assert.That(propTypeTestAttr.FixedArguments[1].Value, Is.EqualTo(inner)); var propMyAttr = prop.GetAttributes().Single(a => a.AttributeType.Name == "MyAttribute"); - Assert.AreEqual(myAttribute, propMyAttr.AttributeType); + Assert.That(propMyAttr.AttributeType, Is.EqualTo(myAttribute)); var attributedInner = (ITypeDefinition)type.GetNestedTypes().Single(t => t.Name == "AttributedInner"); var innerTypeTestAttr = attributedInner.GetAttributes().Single(a => a.AttributeType.Name == "TypeTestAttribute"); - Assert.AreEqual(42, innerTypeTestAttr.FixedArguments[0].Value); - Assert.AreEqual(inner, innerTypeTestAttr.FixedArguments[1].Value); + Assert.That(innerTypeTestAttr.FixedArguments[0].Value, Is.EqualTo(42)); + Assert.That(innerTypeTestAttr.FixedArguments[1].Value, Is.EqualTo(inner)); var innerMyAttr = attributedInner.GetAttributes().Single(a => a.AttributeType.Name == "MyAttribute"); - Assert.AreEqual(myAttribute, innerMyAttr.AttributeType); + Assert.That(innerMyAttr.AttributeType, Is.EqualTo(myAttribute)); var attributedInner2 = (ITypeDefinition)type.GetNestedTypes().Single(t => t.Name == "AttributedInner2"); var inner2 = attributedInner2.GetNestedTypes().Single(t => t.Name == "Inner"); var myAttribute2 = attributedInner2.GetNestedTypes().Single(t => t.Name == "MyAttribute"); var inner2TypeTestAttr = attributedInner2.GetAttributes().Single(a => a.AttributeType.Name == "TypeTestAttribute"); - Assert.AreEqual(43, inner2TypeTestAttr.FixedArguments[0].Value); - Assert.AreEqual(inner2, inner2TypeTestAttr.FixedArguments[1].Value); + Assert.That(inner2TypeTestAttr.FixedArguments[0].Value, Is.EqualTo(43)); + Assert.That(inner2TypeTestAttr.FixedArguments[1].Value, Is.EqualTo(inner2)); var inner2MyAttr = attributedInner2.GetAttributes().Single(a => a.AttributeType.Name == "MyAttribute"); - Assert.AreEqual(myAttribute2, inner2MyAttr.AttributeType); + Assert.That(inner2MyAttr.AttributeType, Is.EqualTo(myAttribute2)); } [Test] @@ -1699,7 +1696,7 @@ public void ClassWithAttributeOnTypeParameter() { var tp = GetTypeDefinition(typeof(ClassWithAttributeOnTypeParameter<>)).TypeParameters.Single(); var attr = tp.GetAttributes().Single(); - Assert.AreEqual("DoubleAttribute", attr.AttributeType.Name); + Assert.That(attr.AttributeType.Name, Is.EqualTo("DoubleAttribute")); } [Test] @@ -1707,19 +1704,19 @@ public void InheritanceTest() { ITypeDefinition c = compilation.FindType(typeof(SystemException)).GetDefinition(); ITypeDefinition c2 = compilation.FindType(typeof(Exception)).GetDefinition(); - Assert.IsNotNull(c, "c is null"); - Assert.IsNotNull(c2, "c2 is null"); + Assert.That(c, Is.Not.Null, "c is null"); + Assert.That(c2, Is.Not.Null, "c2 is null"); //Assert.AreEqual(3, c.BaseTypes.Count); // Inherited interfaces are not reported by Cecil // which matches the behaviour of our C#/VB parsers - Assert.AreEqual("System.Exception", c.DirectBaseTypes.First().FullName); - Assert.AreSame(c2, c.DirectBaseTypes.First()); + Assert.That(c.DirectBaseTypes.First().FullName, Is.EqualTo("System.Exception")); + Assert.That(c.DirectBaseTypes.First(), Is.SameAs(c2)); string[] superTypes = c.GetAllBaseTypes().Select(t => t.ReflectionName).ToArray(); - Assert.AreEqual(new string[] { + Assert.That(superTypes, Is.EqualTo(new string[] { "System.Object", "System.Runtime.Serialization.ISerializable", "System.Runtime.InteropServices._Exception", "System.Exception", "System.SystemException" - }, superTypes); + })); } [Test] @@ -1728,8 +1725,8 @@ public void GenericPropertyTest() ITypeDefinition c = compilation.FindType(typeof(Comparer<>)).GetDefinition(); IProperty def = c.Properties.Single(p => p.Name == "Default"); ParameterizedType pt = (ParameterizedType)def.ReturnType; - Assert.AreEqual("System.Collections.Generic.Comparer", pt.FullName); - Assert.AreEqual(c.TypeParameters[0], pt.TypeArguments[0]); + Assert.That(pt.FullName, Is.EqualTo("System.Collections.Generic.Comparer")); + Assert.That(pt.TypeArguments[0], Is.EqualTo(c.TypeParameters[0])); } [Test] @@ -1737,17 +1734,17 @@ public void PointerTypeTest() { ITypeDefinition c = compilation.FindType(typeof(IntPtr)).GetDefinition(); IMethod toPointer = c.Methods.Single(p => p.Name == "ToPointer"); - Assert.AreEqual("System.Void*", toPointer.ReturnType.ReflectionName); - Assert.IsTrue(toPointer.ReturnType is PointerType); - Assert.AreEqual("System.Void", ((PointerType)toPointer.ReturnType).ElementType.FullName); + Assert.That(toPointer.ReturnType.ReflectionName, Is.EqualTo("System.Void*")); + Assert.That(toPointer.ReturnType is PointerType); + Assert.That(((PointerType)toPointer.ReturnType).ElementType.FullName, Is.EqualTo("System.Void")); } [Test] public void DateTimeDefaultConstructor() { ITypeDefinition c = compilation.FindType(typeof(DateTime)).GetDefinition(); - Assert.AreEqual(1, c.Methods.Count(m => m.IsConstructor && !m.IsStatic && m.Parameters.Count == 0)); - Assert.AreEqual(1, c.GetConstructors().Count(m => m.Parameters.Count == 0)); + Assert.That(c.Methods.Count(m => m.IsConstructor && !m.IsStatic && m.Parameters.Count == 0), Is.EqualTo(1)); + Assert.That(c.GetConstructors().Count(m => m.Parameters.Count == 0), Is.EqualTo(1)); } [Test] @@ -1755,49 +1752,49 @@ public void NoEncodingInfoDefaultConstructor() { ITypeDefinition c = compilation.FindType(typeof(EncodingInfo)).GetDefinition(); // EncodingInfo only has an internal constructor - Assert.IsFalse(c.Methods.Any(m => m.IsConstructor)); + Assert.That(!c.Methods.Any(m => m.IsConstructor)); // and no implicit ctor should be added: - Assert.AreEqual(0, c.GetConstructors().Count()); + Assert.That(c.GetConstructors().Count(), Is.EqualTo(0)); } [Test] public void StaticModifierTest() { ITypeDefinition c = compilation.FindType(typeof(Environment)).GetDefinition(); - Assert.IsNotNull(c, "System.Environment not found"); - Assert.IsTrue(c.IsAbstract, "class should be abstract"); - Assert.IsTrue(c.IsSealed, "class should be sealed"); - Assert.IsTrue(c.IsStatic, "class should be static"); + Assert.That(c, Is.Not.Null, "System.Environment not found"); + Assert.That(c.IsAbstract, "class should be abstract"); + Assert.That(c.IsSealed, "class should be sealed"); + Assert.That(c.IsStatic, "class should be static"); } [Test] public void InnerClassReferenceTest() { ITypeDefinition c = compilation.FindType(typeof(Environment)).GetDefinition(); - Assert.IsNotNull(c, "System.Environment not found"); + Assert.That(c, Is.Not.Null, "System.Environment not found"); IType rt = c.Methods.First(m => m.Name == "GetFolderPath").Parameters[0].Type; - Assert.AreSame(c.NestedTypes.Single(ic => ic.Name == "SpecialFolder"), rt); + Assert.That(rt, Is.SameAs(c.NestedTypes.Single(ic => ic.Name == "SpecialFolder"))); } [Test] public void NestedTypesTest() { ITypeDefinition c = compilation.FindType(typeof(Environment.SpecialFolder)).GetDefinition(); - Assert.IsNotNull(c, "c is null"); - Assert.AreEqual("System.Environment.SpecialFolder", c.FullName); - Assert.AreEqual("System.Environment+SpecialFolder", c.ReflectionName); + Assert.That(c, Is.Not.Null, "c is null"); + Assert.That(c.FullName, Is.EqualTo("System.Environment.SpecialFolder")); + Assert.That(c.ReflectionName, Is.EqualTo("System.Environment+SpecialFolder")); } [Test] public void VoidHasNoMembers() { ITypeDefinition c = compilation.FindType(typeof(void)).GetDefinition(); - Assert.IsNotNull(c, "System.Void not found"); - Assert.AreEqual(TypeKind.Void, c.Kind); - Assert.AreEqual(0, c.GetMethods().Count()); - Assert.AreEqual(0, c.GetProperties().Count()); - Assert.AreEqual(0, c.GetEvents().Count()); - Assert.AreEqual(0, c.GetFields().Count()); + Assert.That(c, Is.Not.Null, "System.Void not found"); + Assert.That(c.Kind, Is.EqualTo(TypeKind.Void)); + Assert.That(c.GetMethods().Count(), Is.EqualTo(0)); + Assert.That(c.GetProperties().Count(), Is.EqualTo(0)); + Assert.That(c.GetEvents().Count(), Is.EqualTo(0)); + Assert.That(c.GetFields().Count(), Is.EqualTo(0)); } [Test] @@ -1805,9 +1802,9 @@ public void Void_SerializableAttribute() { ITypeDefinition c = compilation.FindType(typeof(void)).GetDefinition(); var attr = c.GetAttributes().Single(a => a.AttributeType.FullName == "System.SerializableAttribute"); - Assert.AreEqual(0, attr.Constructor.Parameters.Count); - Assert.AreEqual(0, attr.FixedArguments.Length); - Assert.AreEqual(0, attr.NamedArguments.Length); + Assert.That(attr.Constructor.Parameters.Count, Is.EqualTo(0)); + Assert.That(attr.FixedArguments.Length, Is.EqualTo(0)); + Assert.That(attr.NamedArguments.Length, Is.EqualTo(0)); } [Test] @@ -1815,12 +1812,12 @@ public void Void_StructLayoutAttribute() { ITypeDefinition c = compilation.FindType(typeof(void)).GetDefinition(); var attr = c.GetAttributes().Single(a => a.AttributeType.FullName == "System.Runtime.InteropServices.StructLayoutAttribute"); - Assert.AreEqual(1, attr.Constructor.Parameters.Count); - Assert.AreEqual(1, attr.FixedArguments.Length); - Assert.AreEqual(0, attr.FixedArguments[0].Value); - Assert.AreEqual(1, attr.NamedArguments.Length); - Assert.AreEqual("Size", attr.NamedArguments[0].Name); - Assert.AreEqual(1, attr.NamedArguments[0].Value); + Assert.That(attr.Constructor.Parameters.Count, Is.EqualTo(1)); + Assert.That(attr.FixedArguments.Length, Is.EqualTo(1)); + Assert.That(attr.FixedArguments[0].Value, Is.EqualTo(0)); + Assert.That(attr.NamedArguments.Length, Is.EqualTo(1)); + Assert.That(attr.NamedArguments[0].Name, Is.EqualTo("Size")); + Assert.That(attr.NamedArguments[0].Value, Is.EqualTo(1)); } [Test] @@ -1828,126 +1825,126 @@ public void Void_ComVisibleAttribute() { ITypeDefinition c = compilation.FindType(typeof(void)).GetDefinition(); var attr = c.GetAttributes().Single(a => a.AttributeType.FullName == "System.Runtime.InteropServices.ComVisibleAttribute"); - Assert.AreEqual(1, attr.Constructor.Parameters.Count); - Assert.AreEqual(1, attr.FixedArguments.Length); - Assert.AreEqual(true, attr.FixedArguments[0].Value); - Assert.AreEqual(0, attr.NamedArguments.Length); + Assert.That(attr.Constructor.Parameters.Count, Is.EqualTo(1)); + Assert.That(attr.FixedArguments.Length, Is.EqualTo(1)); + Assert.That(attr.FixedArguments[0].Value, Is.EqualTo(true)); + Assert.That(attr.NamedArguments.Length, Is.EqualTo(0)); } [Test] public void NestedClassInGenericClassTest() { ITypeDefinition dictionary = compilation.FindType(typeof(Dictionary<,>)).GetDefinition(); - Assert.IsNotNull(dictionary); + Assert.That(dictionary, Is.Not.Null); ITypeDefinition valueCollection = compilation.FindType(typeof(Dictionary<,>.ValueCollection)).GetDefinition(); - Assert.IsNotNull(valueCollection); + Assert.That(valueCollection, Is.Not.Null); var dictionaryRT = new ParameterizedType(dictionary, new[] { compilation.FindType(typeof(string)).GetDefinition(), compilation.FindType(typeof(int)).GetDefinition() }); IProperty valueProperty = dictionaryRT.GetProperties(p => p.Name == "Values").Single(); IType parameterizedValueCollection = valueProperty.ReturnType; - Assert.AreEqual("System.Collections.Generic.Dictionary`2+ValueCollection[[System.String],[System.Int32]]", parameterizedValueCollection.ReflectionName); - Assert.AreSame(valueCollection, parameterizedValueCollection.GetDefinition()); + Assert.That(parameterizedValueCollection.ReflectionName, Is.EqualTo("System.Collections.Generic.Dictionary`2+ValueCollection[[System.String],[System.Int32]]")); + Assert.That(parameterizedValueCollection.GetDefinition(), Is.SameAs(valueCollection)); } [Test] public void ValueCollectionCountModifiers() { ITypeDefinition valueCollection = compilation.FindType(typeof(Dictionary<,>.ValueCollection)).GetDefinition(); - Assert.AreEqual(Accessibility.Public, valueCollection.Accessibility); - Assert.IsTrue(valueCollection.IsSealed); - Assert.IsFalse(valueCollection.IsAbstract); - Assert.IsFalse(valueCollection.IsStatic); + Assert.That(valueCollection.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(valueCollection.IsSealed); + Assert.That(!valueCollection.IsAbstract); + Assert.That(!valueCollection.IsStatic); IProperty count = valueCollection.Properties.Single(p => p.Name == "Count"); - Assert.AreEqual(Accessibility.Public, count.Accessibility); + Assert.That(count.Accessibility, Is.EqualTo(Accessibility.Public)); // It's sealed on the IL level; but in C# it's just a normal non-virtual method that happens to implement an interface - Assert.IsFalse(count.IsSealed); - Assert.IsFalse(count.IsVirtual); - Assert.IsFalse(count.IsAbstract); + Assert.That(!count.IsSealed); + Assert.That(!count.IsVirtual); + Assert.That(!count.IsAbstract); } [Test] public void MathAcosModifiers() { ITypeDefinition math = compilation.FindType(typeof(Math)).GetDefinition(); - Assert.AreEqual(Accessibility.Public, math.Accessibility); - Assert.IsTrue(math.IsSealed); - Assert.IsTrue(math.IsAbstract); - Assert.IsTrue(math.IsStatic); + Assert.That(math.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(math.IsSealed); + Assert.That(math.IsAbstract); + Assert.That(math.IsStatic); IMethod acos = math.Methods.Single(p => p.Name == "Acos"); - Assert.AreEqual(Accessibility.Public, acos.Accessibility); - Assert.IsTrue(acos.IsStatic); - Assert.IsFalse(acos.IsAbstract); - Assert.IsFalse(acos.IsSealed); - Assert.IsFalse(acos.IsVirtual); - Assert.IsFalse(acos.IsOverride); + Assert.That(acos.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(acos.IsStatic); + Assert.That(!acos.IsAbstract); + Assert.That(!acos.IsSealed); + Assert.That(!acos.IsVirtual); + Assert.That(!acos.IsOverride); } [Test] public void EncodingModifiers() { ITypeDefinition encoding = compilation.FindType(typeof(Encoding)).GetDefinition(); - Assert.AreEqual(Accessibility.Public, encoding.Accessibility); - Assert.IsFalse(encoding.IsSealed); - Assert.IsTrue(encoding.IsAbstract); + Assert.That(encoding.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(!encoding.IsSealed); + Assert.That(encoding.IsAbstract); IMethod getDecoder = encoding.Methods.Single(p => p.Name == "GetDecoder"); - Assert.AreEqual(Accessibility.Public, getDecoder.Accessibility); - Assert.IsFalse(getDecoder.IsStatic); - Assert.IsFalse(getDecoder.IsAbstract); - Assert.IsFalse(getDecoder.IsSealed); - Assert.IsTrue(getDecoder.IsVirtual); - Assert.IsFalse(getDecoder.IsOverride); + Assert.That(getDecoder.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(!getDecoder.IsStatic); + Assert.That(!getDecoder.IsAbstract); + Assert.That(!getDecoder.IsSealed); + Assert.That(getDecoder.IsVirtual); + Assert.That(!getDecoder.IsOverride); IMethod getMaxByteCount = encoding.Methods.Single(p => p.Name == "GetMaxByteCount"); - Assert.AreEqual(Accessibility.Public, getMaxByteCount.Accessibility); - Assert.IsFalse(getMaxByteCount.IsStatic); - Assert.IsTrue(getMaxByteCount.IsAbstract); - Assert.IsFalse(getMaxByteCount.IsSealed); - Assert.IsFalse(getMaxByteCount.IsVirtual); - Assert.IsFalse(getMaxByteCount.IsOverride); + Assert.That(getMaxByteCount.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(!getMaxByteCount.IsStatic); + Assert.That(getMaxByteCount.IsAbstract); + Assert.That(!getMaxByteCount.IsSealed); + Assert.That(!getMaxByteCount.IsVirtual); + Assert.That(!getMaxByteCount.IsOverride); IProperty encoderFallback = encoding.Properties.Single(p => p.Name == "EncoderFallback"); - Assert.AreEqual(Accessibility.Public, encoderFallback.Accessibility); - Assert.IsFalse(encoderFallback.IsStatic); - Assert.IsFalse(encoderFallback.IsAbstract); - Assert.IsFalse(encoderFallback.IsSealed); - Assert.IsFalse(encoderFallback.IsVirtual); - Assert.IsFalse(encoderFallback.IsOverride); + Assert.That(encoderFallback.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(!encoderFallback.IsStatic); + Assert.That(!encoderFallback.IsAbstract); + Assert.That(!encoderFallback.IsSealed); + Assert.That(!encoderFallback.IsVirtual); + Assert.That(!encoderFallback.IsOverride); } [Test] public void UnicodeEncodingModifiers() { ITypeDefinition encoding = compilation.FindType(typeof(UnicodeEncoding)).GetDefinition(); - Assert.AreEqual(Accessibility.Public, encoding.Accessibility); - Assert.IsFalse(encoding.IsSealed); - Assert.IsFalse(encoding.IsAbstract); + Assert.That(encoding.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(!encoding.IsSealed); + Assert.That(!encoding.IsAbstract); IMethod getDecoder = encoding.Methods.Single(p => p.Name == "GetDecoder"); - Assert.AreEqual(Accessibility.Public, getDecoder.Accessibility); - Assert.IsFalse(getDecoder.IsStatic); - Assert.IsFalse(getDecoder.IsAbstract); - Assert.IsFalse(getDecoder.IsSealed); - Assert.IsFalse(getDecoder.IsVirtual); - Assert.IsTrue(getDecoder.IsOverride); + Assert.That(getDecoder.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(!getDecoder.IsStatic); + Assert.That(!getDecoder.IsAbstract); + Assert.That(!getDecoder.IsSealed); + Assert.That(!getDecoder.IsVirtual); + Assert.That(getDecoder.IsOverride); } [Test] public void UTF32EncodingModifiers() { ITypeDefinition encoding = compilation.FindType(typeof(UTF32Encoding)).GetDefinition(); - Assert.AreEqual(Accessibility.Public, encoding.Accessibility); - Assert.IsTrue(encoding.IsSealed); - Assert.IsFalse(encoding.IsAbstract); + Assert.That(encoding.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(encoding.IsSealed); + Assert.That(!encoding.IsAbstract); IMethod getDecoder = encoding.Methods.Single(p => p.Name == "GetDecoder"); - Assert.AreEqual(Accessibility.Public, getDecoder.Accessibility); - Assert.IsFalse(getDecoder.IsStatic); - Assert.IsFalse(getDecoder.IsAbstract); - Assert.IsFalse(getDecoder.IsSealed); - Assert.IsFalse(getDecoder.IsVirtual); - Assert.IsTrue(getDecoder.IsOverride); + Assert.That(getDecoder.Accessibility, Is.EqualTo(Accessibility.Public)); + Assert.That(!getDecoder.IsStatic); + Assert.That(!getDecoder.IsAbstract); + Assert.That(!getDecoder.IsSealed); + Assert.That(!getDecoder.IsVirtual); + Assert.That(getDecoder.IsOverride); } [Test] @@ -1957,22 +1954,22 @@ public void FindRedirectedType() var typeRef = ReflectionHelper.ParseReflectionName("System.Func`2, System.Core"); ITypeDefinition c = typeRef.Resolve(new SimpleTypeResolveContext(compilationWithSystemCore)).GetDefinition(); - Assert.IsNotNull(c, "System.Func<,> not found"); - Assert.AreEqual("mscorlib", c.ParentModule.AssemblyName); + Assert.That(c, Is.Not.Null, "System.Func<,> not found"); + Assert.That(c.ParentModule.AssemblyName, Is.EqualTo("mscorlib")); } public void DelegateIsClass() { var @delegate = compilation.FindType(KnownTypeCode.Delegate).GetDefinition(); - Assert.AreEqual(TypeKind.Class, @delegate); - Assert.IsFalse(@delegate.IsSealed); + Assert.That(@delegate, Is.EqualTo(TypeKind.Class)); + Assert.That(!@delegate.IsSealed); } public void MulticastDelegateIsClass() { var multicastDelegate = compilation.FindType(KnownTypeCode.MulticastDelegate).GetDefinition(); - Assert.AreEqual(TypeKind.Class, multicastDelegate); - Assert.IsFalse(multicastDelegate.IsSealed); + Assert.That(multicastDelegate, Is.EqualTo(TypeKind.Class)); + Assert.That(!multicastDelegate.IsSealed); } [Test] @@ -1988,13 +1985,13 @@ public void HasSpecialName() var @class = nonCustomAttributes.GetNestedTypes(t => t.Name == "SpecialNameClass").Single().GetDefinition(); var @struct = nonCustomAttributes.GetNestedTypes(t => t.Name == "SpecialNameStruct").Single().GetDefinition(); - Assert.IsTrue(method.HasAttribute(KnownAttribute.SpecialName)); - Assert.IsTrue(property.HasAttribute(KnownAttribute.SpecialName)); - Assert.IsTrue(@event.HasAttribute(KnownAttribute.SpecialName)); - Assert.IsTrue(field.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(method.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(property.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(@event.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(field.HasAttribute(KnownAttribute.SpecialName)); - Assert.IsTrue(@class.HasAttribute(KnownAttribute.SpecialName)); - Assert.IsTrue(@struct.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(@class.HasAttribute(KnownAttribute.SpecialName)); + Assert.That(@struct.HasAttribute(KnownAttribute.SpecialName)); } } } diff --git a/ICSharpCode.Decompiler.Tests/UglyTestRunner.cs b/ICSharpCode.Decompiler.Tests/UglyTestRunner.cs index 1e2cceb6c5..620424ca85 100644 --- a/ICSharpCode.Decompiler.Tests/UglyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/UglyTestRunner.cs @@ -47,7 +47,7 @@ public void AllFilesHaveTests() || file.Extension.Equals(".cs", StringComparison.OrdinalIgnoreCase)) { var testName = file.Name.Split('.')[0]; - Assert.Contains(testName, testNames); + Assert.That(testNames, Has.Member(testName)); } } } diff --git a/ICSharpCode.Decompiler.Tests/Util/BitSetTests.cs b/ICSharpCode.Decompiler.Tests/Util/BitSetTests.cs index 1263bb4fa7..a7c5b3dc3c 100644 --- a/ICSharpCode.Decompiler.Tests/Util/BitSetTests.cs +++ b/ICSharpCode.Decompiler.Tests/Util/BitSetTests.cs @@ -30,13 +30,13 @@ public void SetRange() { var bitset = new BitSet(302); bitset.Set(2, 300); - Assert.IsFalse(bitset[0]); - Assert.IsFalse(bitset[1]); + Assert.That(!bitset[0]); + Assert.That(!bitset[1]); for (int i = 2; i < 300; ++i) { - Assert.IsTrue(bitset[i]); + Assert.That(bitset[i]); } - Assert.IsFalse(bitset[301]); + Assert.That(!bitset[301]); } [Test] @@ -45,12 +45,12 @@ public void ClearRange() var bitset = new BitSet(300); bitset.Set(0, 300); bitset.Clear(1, 299); - Assert.IsTrue(bitset[0]); + Assert.That(bitset[0]); for (int i = 1; i < 299; ++i) { - Assert.IsFalse(bitset[i]); + Assert.That(!bitset[i]); } - Assert.IsTrue(bitset[299]); + Assert.That(bitset[299]); } [Test] @@ -58,14 +58,14 @@ public void AllInRange() { var bitset = new BitSet(300); bitset.Set(1, 299); - Assert.IsTrue(bitset.All(1, 299)); - Assert.IsTrue(bitset.All(10, 290)); - Assert.IsTrue(bitset.All(100, 200)); - Assert.IsFalse(bitset.All(0, 200)); - Assert.IsFalse(bitset.All(0, 1)); - Assert.IsFalse(bitset.All(1, 300)); + Assert.That(bitset.All(1, 299)); + Assert.That(bitset.All(10, 290)); + Assert.That(bitset.All(100, 200)); + Assert.That(!bitset.All(0, 200)); + Assert.That(!bitset.All(0, 1)); + Assert.That(!bitset.All(1, 300)); bitset[200] = false; - Assert.IsFalse(bitset.All(1, 299)); + Assert.That(!bitset.All(1, 299)); } [Test] diff --git a/ICSharpCode.Decompiler.Tests/Util/FileUtilityTests.cs b/ICSharpCode.Decompiler.Tests/Util/FileUtilityTests.cs index e188f94780..19f8ea5e49 100644 --- a/ICSharpCode.Decompiler.Tests/Util/FileUtilityTests.cs +++ b/ICSharpCode.Decompiler.Tests/Util/FileUtilityTests.cs @@ -29,157 +29,157 @@ public class FileUtilityTests [Test] public void NormalizePath() { - Assert.AreEqual(@"c:\temp\test.txt", FileUtility.NormalizePath(@"c:\temp\project\..\test.txt")); - Assert.AreEqual(@"c:\temp\test.txt", FileUtility.NormalizePath(@"c:\temp\project\.\..\test.txt")); - Assert.AreEqual(@"c:\temp\test.txt", FileUtility.NormalizePath(@"c:\temp\\test.txt")); // normalize double backslash - Assert.AreEqual(@"c:\temp", FileUtility.NormalizePath(@"c:\temp\.")); - Assert.AreEqual(@"c:\temp", FileUtility.NormalizePath(@"c:\temp\subdir\..")); + Assert.That(FileUtility.NormalizePath(@"c:\temp\project\..\test.txt"), Is.EqualTo(@"c:\temp\test.txt")); + Assert.That(FileUtility.NormalizePath(@"c:\temp\project\.\..\test.txt"), Is.EqualTo(@"c:\temp\test.txt")); + Assert.That(FileUtility.NormalizePath(@"c:\temp\\test.txt"), Is.EqualTo(@"c:\temp\test.txt")); // normalize double backslash + Assert.That(FileUtility.NormalizePath(@"c:\temp\."), Is.EqualTo(@"c:\temp")); + Assert.That(FileUtility.NormalizePath(@"c:\temp\subdir\.."), Is.EqualTo(@"c:\temp")); } [Test] public void NormalizePath_DriveRoot() { - Assert.AreEqual(@"C:\", FileUtility.NormalizePath(@"C:\")); - Assert.AreEqual(@"C:\", FileUtility.NormalizePath(@"C:/")); - Assert.AreEqual(@"C:\", FileUtility.NormalizePath(@"C:")); - Assert.AreEqual(@"C:\", FileUtility.NormalizePath(@"C:/.")); - Assert.AreEqual(@"C:\", FileUtility.NormalizePath(@"C:/..")); - Assert.AreEqual(@"C:\", FileUtility.NormalizePath(@"C:/./")); - Assert.AreEqual(@"C:\", FileUtility.NormalizePath(@"C:/..\")); + Assert.That(FileUtility.NormalizePath(@"C:\"), Is.EqualTo(@"C:\")); + Assert.That(FileUtility.NormalizePath(@"C:/"), Is.EqualTo(@"C:\")); + Assert.That(FileUtility.NormalizePath(@"C:"), Is.EqualTo(@"C:\")); + Assert.That(FileUtility.NormalizePath(@"C:/."), Is.EqualTo(@"C:\")); + Assert.That(FileUtility.NormalizePath(@"C:/.."), Is.EqualTo(@"C:\")); + Assert.That(FileUtility.NormalizePath(@"C:/./"), Is.EqualTo(@"C:\")); + Assert.That(FileUtility.NormalizePath(@"C:/..\"), Is.EqualTo(@"C:\")); } [Test] public void NormalizePath_UNC() { - Assert.AreEqual(@"\\server\share", FileUtility.NormalizePath(@"\\server\share")); - Assert.AreEqual(@"\\server\share", FileUtility.NormalizePath(@"\\server\share\")); - Assert.AreEqual(@"\\server\share", FileUtility.NormalizePath(@"//server/share/")); - Assert.AreEqual(@"\\server\share\otherdir", FileUtility.NormalizePath(@"//server/share/dir/..\otherdir")); + Assert.That(FileUtility.NormalizePath(@"\\server\share"), Is.EqualTo(@"\\server\share")); + Assert.That(FileUtility.NormalizePath(@"\\server\share\"), Is.EqualTo(@"\\server\share")); + Assert.That(FileUtility.NormalizePath(@"//server/share/"), Is.EqualTo(@"\\server\share")); + Assert.That(FileUtility.NormalizePath(@"//server/share/dir/..\otherdir"), Is.EqualTo(@"\\server\share\otherdir")); } [Test] public void NormalizePath_Web() { - Assert.AreEqual(@"http://danielgrunwald.de/path/", FileUtility.NormalizePath(@"http://danielgrunwald.de/path/")); - Assert.AreEqual(@"browser://http://danielgrunwald.de/path/", FileUtility.NormalizePath(@"browser://http://danielgrunwald.de/wrongpath/../path/")); + Assert.That(FileUtility.NormalizePath(@"http://danielgrunwald.de/path/"), Is.EqualTo(@"http://danielgrunwald.de/path/")); + Assert.That(FileUtility.NormalizePath(@"browser://http://danielgrunwald.de/wrongpath/../path/"), Is.EqualTo(@"browser://http://danielgrunwald.de/path/")); } [Test] public void NormalizePath_Relative() { - Assert.AreEqual(@"../b", FileUtility.NormalizePath(@"..\a\..\b")); - Assert.AreEqual(@".", FileUtility.NormalizePath(@".")); - Assert.AreEqual(@".", FileUtility.NormalizePath(@"a\..")); + Assert.That(FileUtility.NormalizePath(@"..\a\..\b"), Is.EqualTo(@"../b")); + Assert.That(FileUtility.NormalizePath(@"."), Is.EqualTo(@".")); + Assert.That(FileUtility.NormalizePath(@"a\.."), Is.EqualTo(@".")); } [Test] public void NormalizePath_UnixStyle() { - Assert.AreEqual("/", FileUtility.NormalizePath("/")); - Assert.AreEqual("/a/b", FileUtility.NormalizePath("/a/b")); - Assert.AreEqual("/a/b", FileUtility.NormalizePath("/c/../a/./b")); - Assert.AreEqual("/a/b", FileUtility.NormalizePath("/c/../../a/./b")); + Assert.That(FileUtility.NormalizePath("/"), Is.EqualTo("/")); + Assert.That(FileUtility.NormalizePath("/a/b"), Is.EqualTo("/a/b")); + Assert.That(FileUtility.NormalizePath("/c/../a/./b"), Is.EqualTo("/a/b")); + Assert.That(FileUtility.NormalizePath("/c/../../a/./b"), Is.EqualTo("/a/b")); } #endregion [Test] public void TestIsBaseDirectory() { - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\a", @"C:\A\b\hello")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\a", @"C:\a")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\a\", @"C:\a\")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\a\", @"C:\a")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\a", @"C:\a\")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\A", @"C:\a")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\a", @"C:\A")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\a\x\fWufhweoe", @"C:\a\x\fwuFHweoe\a\b\hello")); - - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\b\..\A", @"C:\a")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\HELLO\..\B\..\a", @"C:\b\..\a")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\.\B\..\.\.\a", @"C:\.\.\.\.\.\.\.\a")); - - Assert.IsFalse(FileUtility.IsBaseDirectory(@"C:\b", @"C:\a\b\hello")); - Assert.IsFalse(FileUtility.IsBaseDirectory(@"C:\a\b\hello", @"C:\b")); - Assert.IsFalse(FileUtility.IsBaseDirectory(@"C:\a\x\fwufhweoe", @"C:\a\x\fwuFHweoex\a\b\hello")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\", @"C:\")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"C:\", @"C:\a\b\hello")); - Assert.IsFalse(FileUtility.IsBaseDirectory(@"C:\", @"D:\a\b\hello")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\a", @"C:\A\b\hello")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\a", @"C:\a")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\a\", @"C:\a\")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\a\", @"C:\a")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\a", @"C:\a\")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\A", @"C:\a")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\a", @"C:\A")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\a\x\fWufhweoe", @"C:\a\x\fwuFHweoe\a\b\hello")); + + Assert.That(FileUtility.IsBaseDirectory(@"C:\b\..\A", @"C:\a")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\HELLO\..\B\..\a", @"C:\b\..\a")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\.\B\..\.\.\a", @"C:\.\.\.\.\.\.\.\a")); + + Assert.That(!FileUtility.IsBaseDirectory(@"C:\b", @"C:\a\b\hello")); + Assert.That(!FileUtility.IsBaseDirectory(@"C:\a\b\hello", @"C:\b")); + Assert.That(!FileUtility.IsBaseDirectory(@"C:\a\x\fwufhweoe", @"C:\a\x\fwuFHweoex\a\b\hello")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\", @"C:\")); + Assert.That(FileUtility.IsBaseDirectory(@"C:\", @"C:\a\b\hello")); + Assert.That(!FileUtility.IsBaseDirectory(@"C:\", @"D:\a\b\hello")); } [Test] public void TestIsBaseDirectoryRelative() { - Assert.IsTrue(FileUtility.IsBaseDirectory(@".", @"a\b")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@".", @"a")); - Assert.IsFalse(FileUtility.IsBaseDirectory(@".", @"c:\")); - Assert.IsFalse(FileUtility.IsBaseDirectory(@".", @"/")); + Assert.That(FileUtility.IsBaseDirectory(@".", @"a\b")); + Assert.That(FileUtility.IsBaseDirectory(@".", @"a")); + Assert.That(!FileUtility.IsBaseDirectory(@".", @"c:\")); + Assert.That(!FileUtility.IsBaseDirectory(@".", @"/")); } [Test] public void TestIsBaseDirectoryUnixStyle() { - Assert.IsTrue(FileUtility.IsBaseDirectory(@"/", @"/")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"/", @"/a")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"/", @"/a/subdir")); + Assert.That(FileUtility.IsBaseDirectory(@"/", @"/")); + Assert.That(FileUtility.IsBaseDirectory(@"/", @"/a")); + Assert.That(FileUtility.IsBaseDirectory(@"/", @"/a/subdir")); } [Test] public void TestIsBaseDirectoryUNC() { - Assert.IsTrue(FileUtility.IsBaseDirectory(@"\\server\share", @"\\server\share\dir\subdir")); - Assert.IsTrue(FileUtility.IsBaseDirectory(@"\\server\share", @"\\server\share\dir\subdir")); - Assert.IsFalse(FileUtility.IsBaseDirectory(@"\\server2\share", @"\\server\share\dir\subdir")); + Assert.That(FileUtility.IsBaseDirectory(@"\\server\share", @"\\server\share\dir\subdir")); + Assert.That(FileUtility.IsBaseDirectory(@"\\server\share", @"\\server\share\dir\subdir")); + Assert.That(!FileUtility.IsBaseDirectory(@"\\server2\share", @"\\server\share\dir\subdir")); } [Test] public void TestGetRelativePath() { - Assert.AreEqual(@"blub", FileUtility.GetRelativePath(@"C:\hello\.\..\a", @"C:\.\a\blub")); - Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\hello", @"C:\.\blub\.\..\.\a\.\blub")); - Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\hello\", @"C:\.\blub\.\..\.\a\.\blub")); - Assert.AreEqual(@".", FileUtility.GetRelativePath(@"C:\hello", @"C:\.\hello")); - Assert.AreEqual(@".", FileUtility.GetRelativePath(@"C:\", @"C:\")); - Assert.AreEqual(@"blub", FileUtility.GetRelativePath(@"C:\", @"C:\blub")); - Assert.AreEqual(@"D:\", FileUtility.GetRelativePath(@"C:\", @"D:\")); - Assert.AreEqual(@"D:\def", FileUtility.GetRelativePath(@"C:\abc", @"D:\def")); + Assert.That(FileUtility.GetRelativePath(@"C:\hello\.\..\a", @"C:\.\a\blub"), Is.EqualTo(@"blub")); + Assert.That(FileUtility.GetRelativePath(@"C:\.\.\.\.\hello", @"C:\.\blub\.\..\.\a\.\blub"), Is.EqualTo(@"..\a\blub")); + Assert.That(FileUtility.GetRelativePath(@"C:\.\.\.\.\hello\", @"C:\.\blub\.\..\.\a\.\blub"), Is.EqualTo(@"..\a\blub")); + Assert.That(FileUtility.GetRelativePath(@"C:\hello", @"C:\.\hello"), Is.EqualTo(@".")); + Assert.That(FileUtility.GetRelativePath(@"C:\", @"C:\"), Is.EqualTo(@".")); + Assert.That(FileUtility.GetRelativePath(@"C:\", @"C:\blub"), Is.EqualTo(@"blub")); + Assert.That(FileUtility.GetRelativePath(@"C:\", @"D:\"), Is.EqualTo(@"D:\")); + Assert.That(FileUtility.GetRelativePath(@"C:\abc", @"D:\def"), Is.EqualTo(@"D:\def")); // casing troubles - Assert.AreEqual(@"blub", FileUtility.GetRelativePath(@"C:\hello\.\..\A", @"C:\.\a\blub")); - Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\HELlo", @"C:\.\blub\.\..\.\a\.\blub")); - Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\heLLo\A\..", @"C:\.\blub\.\..\.\a\.\blub")); + Assert.That(FileUtility.GetRelativePath(@"C:\hello\.\..\A", @"C:\.\a\blub"), Is.EqualTo(@"blub")); + Assert.That(FileUtility.GetRelativePath(@"C:\.\.\.\.\HELlo", @"C:\.\blub\.\..\.\a\.\blub"), Is.EqualTo(@"..\a\blub")); + Assert.That(FileUtility.GetRelativePath(@"C:\.\.\.\.\heLLo\A\..", @"C:\.\blub\.\..\.\a\.\blub"), Is.EqualTo(@"..\a\blub")); } [Test] public void RelativeGetRelativePath() { // Relative path - Assert.AreEqual(@"a", FileUtility.GetRelativePath(@".", @"a")); - Assert.AreEqual(@"..", FileUtility.GetRelativePath(@"a", @".")); - Assert.AreEqual(@"..\b", FileUtility.GetRelativePath(@"a", @"b")); - Assert.AreEqual(@"..\..", FileUtility.GetRelativePath(@"a", @"..")); + Assert.That(FileUtility.GetRelativePath(@".", @"a"), Is.EqualTo(@"a")); + Assert.That(FileUtility.GetRelativePath(@"a", @"."), Is.EqualTo(@"..")); + Assert.That(FileUtility.GetRelativePath(@"a", @"b"), Is.EqualTo(@"..\b")); + Assert.That(FileUtility.GetRelativePath(@"a", @".."), Is.EqualTo(@"..\..")); // Getting a path from an absolute path to a relative path isn't really possible; // so we just keep the existing relative path (don't introduce incorrect '..\'). - Assert.AreEqual(@"def", FileUtility.GetRelativePath(@"C:\abc", @"def")); + Assert.That(FileUtility.GetRelativePath(@"C:\abc", @"def"), Is.EqualTo(@"def")); } [Test] public void GetRelativePath_Unix() { - Assert.AreEqual(@"a", FileUtility.GetRelativePath("/", "/a")); - Assert.AreEqual(@"a\b", FileUtility.GetRelativePath("/", "/a/b")); - Assert.AreEqual(@"b", FileUtility.GetRelativePath("/a", "/a/b")); + Assert.That(FileUtility.GetRelativePath("/", "/a"), Is.EqualTo(@"a")); + Assert.That(FileUtility.GetRelativePath("/", "/a/b"), Is.EqualTo(@"a\b")); + Assert.That(FileUtility.GetRelativePath("/a", "/a/b"), Is.EqualTo(@"b")); } [Test] public void TestIsEqualFile() { - Assert.IsTrue(FileUtility.IsEqualFileName(@"C:\.\Hello World.Exe", @"C:\HELLO WOrld.exe")); - Assert.IsTrue(FileUtility.IsEqualFileName(@"C:\bla\..\a\my.file.is.this", @"C:\gg\..\.\.\.\.\a\..\a\MY.FILE.IS.THIS")); + Assert.That(FileUtility.IsEqualFileName(@"C:\.\Hello World.Exe", @"C:\HELLO WOrld.exe")); + Assert.That(FileUtility.IsEqualFileName(@"C:\bla\..\a\my.file.is.this", @"C:\gg\..\.\.\.\.\a\..\a\MY.FILE.IS.THIS")); - Assert.IsFalse(FileUtility.IsEqualFileName(@"C:\.\Hello World.Exe", @"C:\HELLO_WOrld.exe")); - Assert.IsFalse(FileUtility.IsEqualFileName(@"C:\a\my.file.is.this", @"C:\gg\..\.\.\.\.\a\..\b\MY.FILE.IS.THIS")); + Assert.That(!FileUtility.IsEqualFileName(@"C:\.\Hello World.Exe", @"C:\HELLO_WOrld.exe")); + Assert.That(!FileUtility.IsEqualFileName(@"C:\a\my.file.is.this", @"C:\gg\..\.\.\.\.\a\..\b\MY.FILE.IS.THIS")); } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/Util/IntervalTests.cs b/ICSharpCode.Decompiler.Tests/Util/IntervalTests.cs index 6fcf322af4..ff7dbcf1b5 100644 --- a/ICSharpCode.Decompiler.Tests/Util/IntervalTests.cs +++ b/ICSharpCode.Decompiler.Tests/Util/IntervalTests.cs @@ -27,54 +27,54 @@ public class IntervalTests [Test] public void DefaultIsEmpty() { - Assert.IsTrue(default(Interval).IsEmpty); - Assert.IsFalse(default(Interval).Contains(-1)); - Assert.IsFalse(default(Interval).Contains(0)); - Assert.IsFalse(default(Interval).Contains(1)); + Assert.That(default(Interval).IsEmpty); + Assert.That(!default(Interval).Contains(-1)); + Assert.That(!default(Interval).Contains(0)); + Assert.That(!default(Interval).Contains(1)); } [Test] public void EmptyAt1() { Interval i = new Interval(1, 1); - Assert.IsTrue(default(Interval).IsEmpty); - Assert.IsFalse(default(Interval).Contains(-1)); - Assert.IsFalse(default(Interval).Contains(0)); - Assert.IsFalse(default(Interval).Contains(1)); - Assert.IsFalse(default(Interval).Contains(2)); + Assert.That(default(Interval).IsEmpty); + Assert.That(!default(Interval).Contains(-1)); + Assert.That(!default(Interval).Contains(0)); + Assert.That(!default(Interval).Contains(1)); + Assert.That(!default(Interval).Contains(2)); } [Test] public void OneToThree() { Interval i = new Interval(1, 3); - Assert.IsFalse(i.IsEmpty); - Assert.IsFalse(i.Contains(0)); - Assert.IsTrue(i.Contains(1)); - Assert.IsTrue(i.Contains(2)); - Assert.IsFalse(i.Contains(3)); + Assert.That(!i.IsEmpty); + Assert.That(!i.Contains(0)); + Assert.That(i.Contains(1)); + Assert.That(i.Contains(2)); + Assert.That(!i.Contains(3)); } [Test] public void FullInterval() { Interval full = new Interval(int.MinValue, int.MinValue); - Assert.IsFalse(full.IsEmpty); - Assert.IsTrue(full.Contains(int.MinValue)); - Assert.IsTrue(full.Contains(0)); - Assert.IsTrue(full.Contains(int.MaxValue)); + Assert.That(!full.IsEmpty); + Assert.That(full.Contains(int.MinValue)); + Assert.That(full.Contains(0)); + Assert.That(full.Contains(int.MaxValue)); } [Test] public void NonNegativeIntegers() { Interval i = new Interval(0, int.MinValue); - Assert.IsFalse(i.IsEmpty); - Assert.IsTrue(i.Contains(0)); - Assert.IsTrue(i.Contains(1000)); - Assert.IsTrue(i.Contains(int.MaxValue)); - Assert.IsFalse(i.Contains(-1)); - Assert.IsFalse(i.Contains(-1000)); - Assert.IsFalse(i.Contains(int.MinValue)); + Assert.That(!i.IsEmpty); + Assert.That(i.Contains(0)); + Assert.That(i.Contains(1000)); + Assert.That(i.Contains(int.MaxValue)); + Assert.That(!i.Contains(-1)); + Assert.That(!i.Contains(-1000)); + Assert.That(!i.Contains(int.MinValue)); } [Test] @@ -87,12 +87,12 @@ public void Intersection() Interval nonneg = new Interval(0, int.MinValue); Interval nonpos = new Interval(int.MinValue, 1); Interval maxval = new Interval(int.MaxValue, int.MinValue); - Assert.AreEqual(nonneg, full.Intersect(nonneg)); - Assert.AreEqual(nonneg, nonneg.Intersect(full)); - Assert.AreEqual(zero, nonneg.Intersect(zero)); - Assert.AreEqual(zero, nonneg.Intersect(nonpos)); - Assert.AreEqual(maxval, nonneg.Intersect(maxval)); - Assert.AreEqual(empty, nonpos.Intersect(maxval)); + Assert.That(full.Intersect(nonneg), Is.EqualTo(nonneg)); + Assert.That(nonneg.Intersect(full), Is.EqualTo(nonneg)); + Assert.That(nonneg.Intersect(zero), Is.EqualTo(zero)); + Assert.That(nonneg.Intersect(nonpos), Is.EqualTo(zero)); + Assert.That(nonneg.Intersect(maxval), Is.EqualTo(maxval)); + Assert.That(nonpos.Intersect(maxval), Is.EqualTo(empty)); } } } diff --git a/ICSharpCode.Decompiler.Tests/Util/LongSetTests.cs b/ICSharpCode.Decompiler.Tests/Util/LongSetTests.cs index 1718a394bb..e74c8a6980 100644 --- a/ICSharpCode.Decompiler.Tests/Util/LongSetTests.cs +++ b/ICSharpCode.Decompiler.Tests/Util/LongSetTests.cs @@ -32,94 +32,92 @@ public class LongSetTests public void UpperBound() { var longSet = new LongSet(new[] { new LongInterval(1, 5), new LongInterval(6, 7) }.ToImmutableArray()); - Assert.AreEqual(0, longSet.upper_bound(0)); + Assert.That(longSet.upper_bound(0), Is.EqualTo(0)); for (int i = 1; i <= 5; i++) - Assert.AreEqual(1, longSet.upper_bound(i)); + Assert.That(longSet.upper_bound(i), Is.EqualTo(1)); for (int i = 6; i <= 10; i++) - Assert.AreEqual(2, longSet.upper_bound(i)); + Assert.That(longSet.upper_bound(i), Is.EqualTo(2)); } [Test] public void UniverseContainsAll() { - Assert.IsTrue(LongSet.Universe.Contains(long.MinValue)); - Assert.IsTrue(LongSet.Universe.Contains(1)); - Assert.IsTrue(LongSet.Universe.Contains(long.MaxValue)); - Assert.IsFalse(LongSet.Universe.IsEmpty); + Assert.That(LongSet.Universe.Contains(long.MinValue)); + Assert.That(LongSet.Universe.Contains(1)); + Assert.That(LongSet.Universe.Contains(long.MaxValue)); + Assert.That(!LongSet.Universe.IsEmpty); } [Test] public void IntersectUniverse() { - Assert.AreEqual(LongSet.Universe, LongSet.Universe.IntersectWith(LongSet.Universe)); - Assert.AreEqual(LongSet.Empty, LongSet.Universe.IntersectWith(LongSet.Empty)); - Assert.AreEqual(new LongSet(long.MaxValue), LongSet.Universe.IntersectWith(new LongSet(long.MaxValue))); + Assert.That(LongSet.Universe.IntersectWith(LongSet.Universe), Is.EqualTo(LongSet.Universe)); + Assert.That(LongSet.Universe.IntersectWith(LongSet.Empty), Is.EqualTo(LongSet.Empty)); + Assert.That(LongSet.Universe.IntersectWith(new LongSet(long.MaxValue)), Is.EqualTo(new LongSet(long.MaxValue))); var longSet = new LongSet(new[] { new LongInterval(1, 5), new LongInterval(6, 7) }.ToImmutableArray()); - Assert.AreEqual(longSet, longSet.IntersectWith(LongSet.Universe)); + Assert.That(longSet.IntersectWith(LongSet.Universe), Is.EqualTo(longSet)); } [Test] public void UnionUniverse() { - Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(LongSet.Universe)); - Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(LongSet.Empty)); - Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(new LongSet(long.MaxValue))); + Assert.That(LongSet.Universe.UnionWith(LongSet.Universe), Is.EqualTo(LongSet.Universe)); + Assert.That(LongSet.Universe.UnionWith(LongSet.Empty), Is.EqualTo(LongSet.Universe)); + Assert.That(LongSet.Universe.UnionWith(new LongSet(long.MaxValue)), Is.EqualTo(LongSet.Universe)); var longSet = new LongSet(new[] { new LongInterval(1, 5), new LongInterval(6, 7) }.ToImmutableArray()); - Assert.AreEqual(LongSet.Universe, longSet.UnionWith(LongSet.Universe)); + Assert.That(longSet.UnionWith(LongSet.Universe), Is.EqualTo(LongSet.Universe)); } [Test] public void ExceptWithUniverse() { - Assert.AreEqual(LongSet.Universe, LongSet.Universe.ExceptWith(LongSet.Empty)); - Assert.AreEqual(LongSet.Empty, LongSet.Universe.ExceptWith(LongSet.Universe)); - Assert.AreEqual(LongSet.Empty, LongSet.Empty.ExceptWith(LongSet.Universe)); - Assert.AreEqual(LongSet.Empty, LongSet.Empty.ExceptWith(LongSet.Empty)); + Assert.That(LongSet.Universe.ExceptWith(LongSet.Empty), Is.EqualTo(LongSet.Universe)); + Assert.That(LongSet.Universe.ExceptWith(LongSet.Universe), Is.EqualTo(LongSet.Empty)); + Assert.That(LongSet.Empty.ExceptWith(LongSet.Universe), Is.EqualTo(LongSet.Empty)); + Assert.That(LongSet.Empty.ExceptWith(LongSet.Empty), Is.EqualTo(LongSet.Empty)); } [Test] public void UnionWith() { - Assert.AreEqual(new LongSet(new LongInterval(0, 2)), - new LongSet(0).UnionWith(new LongSet(1))); + Assert.That(new LongSet(0).UnionWith(new LongSet(1)), Is.EqualTo(new LongSet(new LongInterval(0, 2)))); - Assert.AreEqual(LongSet.Universe, new LongSet(0).Invert().UnionWith(new LongSet(0))); + Assert.That(new LongSet(0).Invert().UnionWith(new LongSet(0)), Is.EqualTo(LongSet.Universe)); } [Test] public void AddTo() { - Assert.AreEqual(new LongSet(1), new LongSet(0).AddOffset(1)); - Assert.AreEqual(new LongSet(long.MinValue), new LongSet(long.MaxValue).AddOffset(1)); + Assert.That(new LongSet(0).AddOffset(1), Is.EqualTo(new LongSet(1))); + Assert.That(new LongSet(long.MaxValue).AddOffset(1), Is.EqualTo(new LongSet(long.MinValue))); TestAddTo(new LongSet(new LongInterval(-10, 10)), 5); TestAddTo(new LongSet(new LongInterval(-10, 10)), long.MaxValue); - Assert.AreEqual(new LongSet(10).Invert(), new LongSet(0).Invert().AddOffset(10)); - Assert.AreEqual(new LongSet(20).Invert(), new LongSet(30).Invert().AddOffset(-10)); + Assert.That(new LongSet(0).Invert().AddOffset(10), Is.EqualTo(new LongSet(10).Invert())); + Assert.That(new LongSet(30).Invert().AddOffset(-10), Is.EqualTo(new LongSet(20).Invert())); } void TestAddTo(LongSet input, long constant) { - Assert.AreEqual( - input.Values.Select(e => unchecked(e + constant)).OrderBy(e => e).ToList(), - input.AddOffset(constant).Values.ToList()); + Assert.That( + input.AddOffset(constant).Values.ToList(), Is.EqualTo(input.Values.Select(e => unchecked(e + constant)).OrderBy(e => e).ToList())); } [Test] public void Values() { - Assert.IsFalse(LongSet.Empty.Values.Any()); - Assert.IsTrue(LongSet.Universe.Values.Any()); - Assert.AreEqual(new[] { 1, 2, 3 }, new LongSet(LongInterval.Inclusive(1, 3)).Values.ToArray()); + Assert.That(!LongSet.Empty.Values.Any()); + Assert.That(LongSet.Universe.Values.Any()); + Assert.That(new LongSet(LongInterval.Inclusive(1, 3)).Values.ToArray(), Is.EqualTo(new[] { 1, 2, 3 })); } [Test] public void ValueCount() { - Assert.AreEqual(0, LongSet.Empty.Count()); - Assert.AreEqual(ulong.MaxValue, new LongSet(3).Invert().Count()); - Assert.AreEqual(ulong.MaxValue, LongSet.Universe.Count()); - Assert.AreEqual(long.MaxValue + 2ul, new LongSet(LongInterval.Inclusive(-1, long.MaxValue)).Count()); + Assert.That(LongSet.Empty.Count(), Is.EqualTo(0)); + Assert.That(new LongSet(3).Invert().Count(), Is.EqualTo(ulong.MaxValue)); + Assert.That(LongSet.Universe.Count(), Is.EqualTo(ulong.MaxValue)); + Assert.That(new LongSet(LongInterval.Inclusive(-1, long.MaxValue)).Count(), Is.EqualTo(long.MaxValue + 2ul)); } } } diff --git a/ICSharpCode.Decompiler.Tests/Util/ResourceReaderWriterTests.cs b/ICSharpCode.Decompiler.Tests/Util/ResourceReaderWriterTests.cs index cad0afa930..59f8aadce0 100644 --- a/ICSharpCode.Decompiler.Tests/Util/ResourceReaderWriterTests.cs +++ b/ICSharpCode.Decompiler.Tests/Util/ResourceReaderWriterTests.cs @@ -100,9 +100,9 @@ public void Read(string name, object value) using var testFile = ProduceResourcesTestFile(name, value); using var reader = new ResourcesFile(testFile); var items = reader.ToArray(); - Assert.AreEqual(1, items.Length); - Assert.AreEqual(name, items[0].Key); - Assert.AreEqual(value, items[0].Value); + Assert.That(items.Length, Is.EqualTo(1)); + Assert.That(items[0].Key, Is.EqualTo(name)); + Assert.That(items[0].Value, Is.EqualTo(value)); } [TestCase("Null", null, null, "System.Resources.ResXNullRef" + WinFormsAssemblyName)] @@ -124,14 +124,14 @@ public void Read(string name, object value) public void Write(string name, object value, string serializedValue, string typeName) { var element = ProduceResXTest(name, value); - Assert.AreEqual(name, element.Attribute("name")?.Value); + Assert.That(element.Attribute("name")?.Value, Is.EqualTo(name)); if (typeName != null) { - Assert.AreEqual(typeName, element.Attribute("type")?.Value); + Assert.That(element.Attribute("type")?.Value, Is.EqualTo(typeName)); } var v = element.Element("value"); - Assert.IsNotNull(v); - Assert.IsTrue(v.IsEmpty ? serializedValue == null : v.Value == serializedValue); + Assert.That(v, Is.Not.Null); + Assert.That(v.IsEmpty ? serializedValue == null : v.Value == serializedValue); } [Test] @@ -149,10 +149,10 @@ public void BitmapIsResourceSerializedObject() .GetManifestResourceStream(typeof(ResourceReaderWriterTests).Namespace + ".Test.resources"); using var reader = new ResourcesFile(stream); var items = reader.ToArray(); - Assert.AreEqual(3, items.Length); + Assert.That(items.Length, Is.EqualTo(3)); var item = items.FirstOrDefault(i => i.Key == "Bitmap"); - Assert.IsNotNull(item.Key); - Assert.IsInstanceOf(item.Value); + Assert.That(item.Key, Is.Not.Null); + Assert.That(item.Value, Is.InstanceOf()); } [Test] @@ -162,15 +162,15 @@ public void ByteArrayIsSupported() .GetManifestResourceStream(typeof(ResourceReaderWriterTests).Namespace + ".Test.resources"); using var reader = new ResourcesFile(stream); var items = reader.ToArray(); - Assert.AreEqual(3, items.Length); + Assert.That(items.Length, Is.EqualTo(3)); var item = items.FirstOrDefault(i => i.Key == "Byte[]"); - Assert.IsNotNull(item.Key); - Assert.IsInstanceOf(item.Value); + Assert.That(item.Key, Is.Not.Null); + Assert.That(item.Value, Is.InstanceOf()); byte[] array = (byte[])item.Value; - Assert.AreEqual(3, array.Length); - Assert.AreEqual(42, array[0]); - Assert.AreEqual(43, array[1]); - Assert.AreEqual(44, array[2]); + Assert.That(array.Length, Is.EqualTo(3)); + Assert.That(array[0], Is.EqualTo(42)); + Assert.That(array[1], Is.EqualTo(43)); + Assert.That(array[2], Is.EqualTo(44)); } [Test] @@ -180,10 +180,10 @@ public void MemoryStreamIsSupported() .GetManifestResourceStream(typeof(ResourceReaderWriterTests).Namespace + ".Test.resources"); using var reader = new ResourcesFile(stream); var items = reader.ToArray(); - Assert.AreEqual(3, items.Length); + Assert.That(items.Length, Is.EqualTo(3)); var item = items.FirstOrDefault(i => i.Key == "MemoryStream"); - Assert.IsNotNull(item.Key); - Assert.IsInstanceOf(item.Value); + Assert.That(item.Key, Is.Not.Null); + Assert.That(item.Value, Is.InstanceOf()); } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs index 2dcd061392..c21dc07758 100644 --- a/ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/VBPrettyTestRunner.cs @@ -45,8 +45,8 @@ public void AllFilesHaveTests() if (file.Extension.Equals(".vb", StringComparison.OrdinalIgnoreCase)) { var testName = file.Name.Split('.')[0]; - Assert.Contains(testName, testNames); - Assert.IsTrue(File.Exists(Path.Combine(TestCasePath, testName + ".cs"))); + Assert.That(testNames, Has.Member(testName)); + Assert.That(File.Exists(Path.Combine(TestCasePath, testName + ".cs"))); } } } diff --git a/ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs b/ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs index 27acff4ca8..9ed326403b 100644 --- a/ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs +++ b/ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs @@ -179,7 +179,7 @@ void RunTest(string name, string asmPath, string sourcePath) resolver.AddSearchDirectory(Path.GetDirectoryName(asmPath)); var res = module.Resources.First(); Stream bamlStream = LoadBaml(res, name + ".baml"); - Assert.IsNotNull(bamlStream); + Assert.That(bamlStream, Is.Not.Null); BamlDecompilerTypeSystem typeSystem = new BamlDecompilerTypeSystem(module, resolver); var decompiler = new XamlDecompiler(typeSystem, new BamlDecompilerSettings()); diff --git a/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj b/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj index 5ff532b129..b8a51da296 100644 --- a/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj +++ b/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj @@ -32,7 +32,7 @@ - + diff --git a/ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs b/ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs index f9616006c3..f3d2f3c933 100644 --- a/ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs +++ b/ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs @@ -69,7 +69,7 @@ public void VerifyDoesNotShowForNoSymbol() var shouldShow = analyzer.Show(symbol: null); // Assert - Assert.IsFalse(shouldShow, $"The analyzer will be unexpectedly shown for no symbol"); + Assert.That(!shouldShow, $"The analyzer will be unexpectedly shown for no symbol"); } [Test] @@ -85,7 +85,7 @@ public void VerifyDoesNotShowForNonMembers(SymbolKind symbolKind) var shouldShow = analyzer.Show(symbolMock); // Assert - Assert.IsFalse(shouldShow, $"The analyzer will be unexpectedly shown for symbol '{symbolKind}'"); + Assert.That(!shouldShow, $"The analyzer will be unexpectedly shown for symbol '{symbolKind}'"); } [Test] @@ -100,7 +100,7 @@ public void VerifyDoesNotShowForStaticMembers(SymbolKind symbolKind) var shouldShow = analyzer.Show(memberMock); // Assert - Assert.IsFalse(shouldShow, $"The analyzer will be unexpectedly shown for static symbol '{symbolKind}'"); + Assert.That(!shouldShow, $"The analyzer will be unexpectedly shown for static symbol '{symbolKind}'"); } [Test] @@ -117,7 +117,7 @@ public void VerifyDoesNotShowForUnsupportedTypes( var shouldShow = analyzer.Show(memberMock); // Assert - Assert.IsFalse(shouldShow, $"The analyzer will be unexpectedly shown for symbol '{symbolKind}' and '{typeKind}'"); + Assert.That(!shouldShow, $"The analyzer will be unexpectedly shown for symbol '{symbolKind}' and '{typeKind}'"); } [Test] @@ -134,7 +134,7 @@ public void VerifyShowsForSupportedTypes( var shouldShow = analyzer.Show(memberMock); // Assert - Assert.IsTrue(shouldShow, $"The analyzer will not be shown for symbol '{symbolKind}' and '{typeKind}'"); + Assert.That(shouldShow, $"The analyzer will not be shown for symbol '{symbolKind}' and '{typeKind}'"); } [Test] @@ -148,13 +148,13 @@ public void VerifyReturnsOnlyInterfaceMembers() var results = analyzer.Analyze(symbol, new AnalyzerContext()); // Assert - Assert.IsNotNull(results); - Assert.AreEqual(1, results.Count()); + Assert.That(results, Is.Not.Null); + Assert.That(results.Count(), Is.EqualTo(1)); var result = results.FirstOrDefault() as IMethod; - Assert.IsNotNull(result); - Assert.IsNotNull(result.DeclaringTypeDefinition); - Assert.AreEqual(TypeKind.Interface, result.DeclaringTypeDefinition.Kind); - Assert.AreEqual(nameof(ITestInterface), result.DeclaringTypeDefinition.Name); + Assert.That(result, Is.Not.Null); + Assert.That(result.DeclaringTypeDefinition, Is.Not.Null); + Assert.That(result.DeclaringTypeDefinition.Kind, Is.EqualTo(TypeKind.Interface)); + Assert.That(result.DeclaringTypeDefinition.Name, Is.EqualTo(nameof(ITestInterface))); } private ISymbol SetupSymbolForAnalysis(Type type, string methodName) diff --git a/ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs b/ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs index 0f9f46cbbf..9cd7726d65 100644 --- a/ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs +++ b/ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs @@ -42,11 +42,11 @@ public void MainAssemblyUsesSystemStringEmpty() var results = new MethodUsesAnalyzer().Analyze(symbol, context).ToList(); - Assert.IsTrue(results.Count == 1); + Assert.That(results.Count == 1); var field = results.Single() as IField; - Assert.IsNotNull(field); - Assert.IsFalse(field.MetadataToken.IsNil); - Assert.AreEqual(field.FullName, "System.String.Empty"); + Assert.That(field, Is.Not.Null); + Assert.That(!field.MetadataToken.IsNil); + Assert.That("System.String.Empty", Is.EqualTo(field.FullName)); } } } diff --git a/ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs b/ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs index 76af5ca9c9..b89a02d486 100644 --- a/ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs +++ b/ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs @@ -59,10 +59,10 @@ public void SystemInt32UsedByMainAssembly() var results = new TypeUsedByAnalyzer().Analyze(symbol, context).ToList(); - Assert.IsNotEmpty(results); + Assert.That(results, Is.Not.Empty); var method = results.OfType().SingleOrDefault(m => m.FullName == "ICSharpCode.ILSpy.Tests.Analyzers.TestCases.Main.MainAssembly.UsesInt32"); - Assert.IsNotNull(method); - Assert.IsFalse(method.MetadataToken.IsNil); + Assert.That(method, Is.Not.Null); + Assert.That(!method.MetadataToken.IsNil); } } } diff --git a/ILSpy.Tests/ILSpy.Tests.csproj b/ILSpy.Tests/ILSpy.Tests.csproj index c5e5771c68..5bb3d121fb 100644 --- a/ILSpy.Tests/ILSpy.Tests.csproj +++ b/ILSpy.Tests/ILSpy.Tests.csproj @@ -55,7 +55,7 @@ - + diff --git a/NuGet.config b/NuGet.config index 8c93079308..5209a02bfd 100644 --- a/NuGet.config +++ b/NuGet.config @@ -19,5 +19,5 @@ - --> +