Skip to content

Commit

Permalink
Improved unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Oct 27, 2016
1 parent 5ba47ba commit da1a151
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 334 deletions.
61 changes: 40 additions & 21 deletions ReportGeneratorTest/FileManager.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Palmmedia.ReportGeneratorTest
{
internal static class FileManager
[TestClass]
public static class FileManager
{
private const string TEMPDIRECTORY = @"C:\temp";

internal static string GetCSharpReportDirectory() => Path.Combine(GetFilesDirectory(), "CSharp", "Reports");

internal static string GetFSharpReportDirectory() => Path.Combine(GetFilesDirectory(), "FSharp", "Reports");

internal static string GetJavaReportDirectory() => Path.Combine(GetFilesDirectory(), "Java", "Reports");

internal static string GetCSharpCodeDirectory() => Path.Combine(GetFilesDirectory(), "CSharp", "Project");

internal static string GetFSharpCodeDirectory() => Path.Combine(GetFilesDirectory(), "FSharp", "Project");

internal static string GetJavaCodeDirectory() => Path.Combine(GetFilesDirectory(), "Java", "Project");

internal static string GetFilesDirectory()
{
var baseDirectory = new DirectoryInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.Parent.FullName;
return Path.Combine(baseDirectory, "ReportGenerator.Testprojects");
}

internal static void CopyTestClasses()
[AssemblyInitialize]
public static void CopyTestClasses(TestContext context)
{
if (!Directory.Exists(TEMPDIRECTORY))
{
Expand Down Expand Up @@ -54,7 +39,8 @@ internal static void CopyTestClasses()
}
}

internal static void DeleteTestClasses()
[AssemblyCleanup]
public static void DeleteTestClasses()
{
if (Directory.Exists(TEMPDIRECTORY))
{
Expand All @@ -66,7 +52,40 @@ internal static void DeleteTestClasses()
{
File.Delete(fileInfo.FullName);
}

string javaDir = Path.Combine(TEMPDIRECTORY, "test");
files = new DirectoryInfo(javaDir).GetFiles("*.java");

foreach (var fileInfo in files)
{
File.Delete(fileInfo.FullName);
}

Directory.Delete(javaDir);

if (!Directory.EnumerateFiles(TEMPDIRECTORY).Any())
{
Directory.Delete(TEMPDIRECTORY);
}
}
}

internal static string GetCSharpReportDirectory() => Path.Combine(GetFilesDirectory(), "CSharp", "Reports");

internal static string GetFSharpReportDirectory() => Path.Combine(GetFilesDirectory(), "FSharp", "Reports");

internal static string GetJavaReportDirectory() => Path.Combine(GetFilesDirectory(), "Java", "Reports");

internal static string GetCSharpCodeDirectory() => Path.Combine(GetFilesDirectory(), "CSharp", "Project");

internal static string GetFSharpCodeDirectory() => Path.Combine(GetFilesDirectory(), "FSharp", "Project");

internal static string GetJavaCodeDirectory() => Path.Combine(GetFilesDirectory(), "Java", "Project");

internal static string GetFilesDirectory()
{
var baseDirectory = new DirectoryInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.Parent.FullName;
return Path.Combine(baseDirectory, "ReportGenerator.Testprojects");
}
}
}
31 changes: 0 additions & 31 deletions ReportGeneratorTest/Parser/Analysis/CodeFileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,6 @@ namespace Palmmedia.ReportGeneratorTest.Parser.Analysis
[TestClass]
public class CodeFileTest
{
#region Additional test attributes

// You can use the following additional attributes as you write your tests:

// Use ClassInitialize to run code before running the first test in the class
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

// Use TestInitialize to run code before running each test
// [TestInitialize]
// public void MyTestInitialize()
// {
// }

// Use TestCleanup to run code after each test has run
// [TestCleanup]
// public void MyTestCleanup()
// {
// }
#endregion

/// <summary>
/// A test for the Constructor
/// </summary>
Expand Down
11 changes: 0 additions & 11 deletions ReportGeneratorTest/Parser/CoberturaParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,15 @@ public class CoberturaParserTest

#region Additional test attributes

// You can use the following additional attributes as you write your tests:

// Use ClassInitialize to run code before running the first test in the class
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();

var report = XDocument.Load(FilePath1);
new CoberturaReportPreprocessor(report).Execute();
assemblies = new CoberturaParser(report).Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
Expand Down
9 changes: 0 additions & 9 deletions ReportGeneratorTest/Parser/DotCoverParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,9 @@ public class DotCoverParserTest
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();

assemblies = new DotCoverParser(XDocument.Load(FilePath1)).Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
Expand Down
9 changes: 0 additions & 9 deletions ReportGeneratorTest/Parser/DynamicCodeCoverageParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,10 @@ public class DynamicCodeCoverageParserTest
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();

var report = XDocument.Load(FilePath);
assemblies = new DynamicCodeCoverageParser(report).Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
Expand Down
9 changes: 0 additions & 9 deletions ReportGeneratorTest/Parser/MultiReportParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class MultiReportParserTest
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();

var multiReportParser = new MultiReportParser();
multiReportParser.AddParser(new PartCover22Parser(XDocument.Load(FilePath1)));
multiReportParser.AddParser(new PartCover22Parser(XDocument.Load(FilePath1)));
Expand All @@ -53,13 +51,6 @@ public static void MyClassInitialize(TestContext testContext)
assembliesWithPreprocessing = multiReportParser.Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
Expand Down
20 changes: 0 additions & 20 deletions ReportGeneratorTest/Parser/NCoverParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,10 @@ public class NCoverParserTest
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();

var report = XDocument.Load(FilePath);
assemblies = new NCoverParser(report).Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

// Use TestInitialize to run code before running each test
// [TestInitialize]
// public void MyTestInitialize()
// {
// }

// Use TestCleanup to run code after each test has run
// [TestCleanup]
// public void MyTestCleanup()
// {
// }
#endregion

/// <summary>
Expand Down
9 changes: 0 additions & 9 deletions ReportGeneratorTest/Parser/OpenCoverParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class OpenCoverParserTest
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();

assembliesWithoutPreprocessing = new OpenCoverParser(XDocument.Load(FilePath1)).Assemblies;

var report = XDocument.Load(FilePath1);
Expand All @@ -52,13 +50,6 @@ public static void MyClassInitialize(TestContext testContext)
assembliesWithTrackedMethods = new OpenCoverParser(report).Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
Expand Down
9 changes: 0 additions & 9 deletions ReportGeneratorTest/Parser/PartCover22ParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class PartCover22ParserTest
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();

assembliesWithoutPreprocessing = new PartCover22Parser(XDocument.Load(FilePath)).Assemblies;

var report = XDocument.Load(FilePath);
Expand All @@ -42,13 +40,6 @@ public static void MyClassInitialize(TestContext testContext)
assembliesWithPreprocessing = new PartCover22Parser(report).Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
Expand Down
9 changes: 0 additions & 9 deletions ReportGeneratorTest/Parser/PartCover23ParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class PartCover23ParserTest
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();

assembliesWithoutPreprocessing = new PartCover23Parser(XDocument.Load(FilePath)).Assemblies;

var report = XDocument.Load(FilePath);
Expand All @@ -42,13 +40,6 @@ public static void MyClassInitialize(TestContext testContext)
assembliesWithPreprocessing = new PartCover23Parser(report).Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
Expand Down
8 changes: 0 additions & 8 deletions ReportGeneratorTest/Parser/PartCover23ParserTest_35109.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class PartCover23ParserTest_35109
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();
assembliesWithoutPreprocessing = new PartCover23Parser(XDocument.Load(FilePath)).Assemblies;

var report = XDocument.Load(FilePath);
Expand All @@ -42,13 +41,6 @@ public static void MyClassInitialize(TestContext testContext)
assembliesWithPreprocessing = new PartCover23Parser(report).Assemblies;
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,6 @@ public class CoberturaReportPreprocessorTest
{
private static readonly string FilePath = Path.Combine(FileManager.GetJavaReportDirectory(), "Cobertura2.1.1.xml");

#region Additional test attributes

// You can use the following additional attributes as you write your tests:

// Use ClassInitialize to run code before running the first test in the class
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
/// A test for Execute
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@ public class DotCoverReportPreprocessorTest
{
private static readonly string FSharpFilePath = Path.Combine(FileManager.GetFSharpReportDirectory(), "dotCover.xml");

#region Additional test attributes

// You can use the following additional attributes as you write your tests:

// Use ClassInitialize to run code before running the first test in the class
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
FileManager.CopyTestClasses();
}

// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup]
public static void MyClassCleanup()
{
FileManager.DeleteTestClasses();
}

#endregion

/// <summary>
/// A test for Execute
/// </summary>
Expand Down
Loading

0 comments on commit da1a151

Please sign in to comment.