Permalink
Browse files

Replaced MBUnit with NUnit.

  • Loading branch information...
1 parent e8c2536 commit cd200fa5046255ed0794eae360f2db6da6c4e424 @arturek arturek committed Mar 1, 2011
@@ -2,16 +2,16 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using MbUnit.Framework;
+using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.CustomAttributes
{
public class CustomAttributeTests : DecompilerTestBase
{
- [StaticTestFactory]
- public static IEnumerable<Test> CustomAttributeSamples()
- {
- return GenerateSectionTests(@"CustomAttributes\S_CustomAttributeSamples.cs");
+ [Test]
+ public void CustomAttributeSamples()
+ {
+ ValidateFileRoundtrip(@"CustomAttributes\S_CustomAttributeSamples.cs");
}
[Test]
@@ -46,7 +46,7 @@ namespace AttributeWithTypeArgument
[AttributeUsage(AttributeTargets.All)]
public class MyTypeAttribute : Attribute
{
- public MyTypeAttribute(Type t)
+ public MyTypeAttribute(Type t) : base()
{
}
}
@@ -7,31 +7,12 @@
using Decompiler;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
-using MbUnit.Framework;
+using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
{
public abstract class DecompilerTestBase
{
- protected static IEnumerable<Test> GenerateSectionTests(string samplesFileName)
- {
- string code = File.ReadAllText(Path.Combine(@"..\..\Tests", samplesFileName));
- foreach (var sectionName in CodeSampleFileParser.ListSections(code))
- {
- if (sectionName.EndsWith("(ignored)", StringComparison.OrdinalIgnoreCase))
- continue;
-
- var testedSectionName = sectionName;
- yield return new TestCase(testedSectionName, () =>
- {
- var testCode = CodeSampleFileParser.GetSection(testedSectionName, code);
- System.Diagnostics.Debug.WriteLine(testCode);
- var decompiledTestCode = RoundtripCode(testCode);
- Assert.AreEqual(testCode, decompiledTestCode);
- });
- }
- }
-
protected static void ValidateFileRoundtrip(string samplesFileName)
{
var lines = File.ReadAllLines(Path.Combine(@"..\..\Tests", samplesFileName));
@@ -38,10 +38,7 @@
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Gallio, Version=3.3.0.0, Culture=neutral, PublicKeyToken=eb9cfa67ee6ab36e, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- </Reference>
- <Reference Include="MbUnit, Version=3.3.0.0, Culture=neutral, PublicKeyToken=eb9cfa67ee6ab36e, processorArchitecture=MSIL">
+ <Reference Include="nunit.framework, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
@@ -59,10 +56,10 @@
<Compile Include="Helpers\RemoveCompilerAttribute.cs" />
<Compile Include="Types\EnumTests.cs" />
<Compile Include="Types\TypeTests.cs" />
- <None Include="Types\S_DelegateConstruction.cs" />
+ <Compile Include="DelegateConstruction.cs" />
<None Include="CustomAttributes\S_CustomAttributes.cs" />
- <None Include="Loops.cs" />
- <None Include="Types\S_PropertiesAndEvents.cs" />
+ <Compile Include="Loops.cs" />
+ <Compile Include="PropertiesAndEvents.cs" />
<None Include="CustomAttributes\S_CustomAttributeSamples.cs" />
<Compile Include="CodeSampleFileParser.cs" />
<Compile Include="CustomAttributes\CustomAttributeTests.cs" />
@@ -72,7 +69,7 @@
<Compile Include="Generics.cs" />
<Compile Include="MultidimensionalArray.cs" />
<Compile Include="TestRunner.cs" />
- <None Include="Types\S_ValueTypes.cs" />
+ <Compile Include="ValueTypes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">
@@ -9,7 +9,6 @@
using Decompiler;
using Microsoft.CSharp;
using Mono.Cecil;
-using MbUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
{
@@ -22,24 +21,6 @@ public static void Main()
Console.ReadKey();
}
- public void RoundtripFile(string fileName)
- {
- string code = File.ReadAllText(fileName);
- AssemblyDefinition assembly = Compile(code);
- AstBuilder decompiler = new AstBuilder(new DecompilerContext());
- decompiler.AddAssembly(assembly);
- StringWriter output = new StringWriter();
- decompiler.GenerateCode(new PlainTextOutput(output));
-
- var decompiledCode = output.ToString();
- var onlyCode = "using System;" + Environment.NewLine + StripCodeFileHeader(code);
-
- File.WriteAllText(Path.ChangeExtension(fileName, ".decomp.cs"), decompiledCode);
- File.WriteAllText(Path.ChangeExtension(fileName, ".code.cs"), onlyCode);
-
- Assert.AreEqual(onlyCode, decompiledCode);
- }
-
static void TestFile(string fileName)
{
string code = File.ReadAllText(fileName);
@@ -55,39 +36,6 @@ static void TestFile(string fileName)
}
}
- static string StripCodeFileHeader(string code)
- {
- var reader = new StringReader(code);
-
- var buffer = new StringWriter();
-
- string line;
- var skipBlankLine = false;
- while ((line = reader.ReadLine()) != null)
- {
- if (line.Trim().StartsWith("//"))
- {
- skipBlankLine = true;
- continue;
- }
- else if (line.StartsWith("using "))
- {
- skipBlankLine = true;
- continue;
- }
- else if (skipBlankLine && String.IsNullOrWhiteSpace(line))
- {
- continue;
- }
-
- skipBlankLine = false;
-
- buffer.WriteLine(line);
- }
-
- return buffer.ToString();
- }
-
static bool Compare(string input1, string input2, StringWriter diff)
{
bool ok = true;
@@ -2,16 +2,16 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using MbUnit.Framework;
+using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Types
{
public class EnumTests : DecompilerTestBase
{
- [StaticTestFactory]
- public static IEnumerable<Test> EnumSamples()
+ [Test]
+ public void EnumSamples()
{
- return GenerateSectionTests(@"Types\S_EnumSamples.cs");
+ ValidateFileRoundtrip(@"Types\S_EnumSamples.cs");
}
}
}
@@ -2,28 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using MbUnit.Framework;
+using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Types
{
public class TypeTests : DecompilerTestBase
{
- [Test]
- public void ValueTypes()
- {
- ValidateFileRoundtrip(@"Types\S_ValueTypes.cs");
- }
-
- [Test]
- public void PropertiesAndEvents()
- {
- ValidateFileRoundtrip(@"Types\S_PropertiesAndEvents.cs");
- }
-
- [Test]
- public void DelegateConstruction()
- {
- ValidateFileRoundtrip(@"Types\S_DelegateConstruction.cs");
- }
}
}

0 comments on commit cd200fa

Please sign in to comment.