Permalink
Browse files

Rewrite all tests as MSpec specs.

  • Loading branch information...
forki committed Feb 19, 2011
1 parent 4f33b39 commit 9aaa3207fc5d2fc33fca9019dce7409071c81701
Showing with 521 additions and 970 deletions.
  1. +25 −36 src/test/Test.FAKECore/FileHandling/BaseFunctions.cs
  2. +30 −0 src/test/Test.FAKECore/FileHandling/CleanDirectorySpecs.cs
  3. +36 −0 src/test/Test.FAKECore/FileHandling/CopyDirectorySpec.cs
  4. +22 −0 src/test/Test.FAKECore/FileHandling/FileComparisonSpecs.cs
  5. +46 −0 src/test/Test.FAKECore/FileHandling/GlobbingSpecs.cs
  6. +0 −58 src/test/Test.FAKECore/FileHandling/TestCleanDir.cs
  7. +0 −27 src/test/Test.FAKECore/FileHandling/TestCompareFiles.cs
  8. +0 −43 src/test/Test.FAKECore/FileHandling/TestCopyDir.cs
  9. +0 −59 src/test/Test.FAKECore/FileHandling/TestDirectoryScan.cs
  10. +0 −60 src/test/Test.FAKECore/FileHandling/TestFileScan.cs
  11. +0 −42 src/test/Test.FAKECore/FileHandling/TestRelativeFileScan.cs
  12. +46 −0 src/test/Test.FAKECore/Globbing/Directories/GlobbingOfDirectoriesSpecs.cs
  13. +0 −52 src/test/Test.FAKECore/Globbing/Directories/TestGlobbingOfDirectories.cs
  14. +48 −0 src/test/Test.FAKECore/RelativePathsSpecs.cs
  15. +0 −51 src/test/Test.FAKECore/SideBySideSpecification/FindReferencesTest.cs
  16. +39 −0 src/test/Test.FAKECore/SideBySideSpecification/ReferencesScanningSpecs.cs
  17. +40 −0 src/test/Test.FAKECore/SideBySideSpecification/SpecsRemovementSpecs.cs
  18. +0 −45 src/test/Test.FAKECore/SideBySideSpecification/SpecsRemovementTest.cs
  19. +34 −0 src/test/Test.FAKECore/StringHelperSpecs.cs
  20. +0 −55 src/test/Test.FAKECore/StringHelperTest.cs
  21. +12 −19 src/test/Test.FAKECore/Test.FAKECore.csproj
  22. +8 −4 src/test/Test.FAKECore/TestData.cs
  23. +0 −27 src/test/Test.FAKECore/TestIfFAKEIsAvailable.cs
  24. +0 −74 src/test/Test.FAKECore/TestRelativePaths.cs
  25. +0 −26 src/test/Test.FAKECore/XMLHandling/TestLoadXML.cs
  26. +0 −66 src/test/Test.FAKECore/XMLHandling/TestXMLPoke.cs
  27. +69 −0 src/test/Test.FAKECore/XmlSpecs.cs
  28. +62 −0 src/test/Test.Git/Sha1Specs.cs
  29. +0 −106 src/test/Test.Git/ShouldExtensions.cs
  30. +4 −7 src/test/Test.Git/Test.Git.csproj
  31. +0 −58 src/test/Test.Git/TestSha1.cs
  32. +0 −32 src/test/Test.Git/TestSha1OfFile.cs
  33. +0 −23 src/test/Test.Git/TestSha1WithUmlauts.cs
@@ -1,14 +1,31 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Fake;
using Machine.Specifications;
using Microsoft.FSharp.Core;
using NUnit.Framework;
namespace Test.FAKECore.FileHandling
{
[TestFixture]
{
public class when_creating_test_directory_structure : BaseFunctions
{
Because of = CreateTestDirStructure;
It should_create_all_dirs = () => AllDirectories().Length.ShouldEqual(16);
It should_create_no_files = () => AllFiles().ShouldBeEmpty();
}
public class when_creating_test_file_structure : BaseFunctions
{
Because of = CreateTestFileStructure;
It should_create_all_dirs = () => AllDirectories().Length.ShouldEqual(16);
It should_create_all_files = () => AllFiles().Length.ShouldEqual(17);
}
public class BaseFunctions
{
/// <summary>
@@ -20,7 +37,6 @@ public static void CleanDir(string dir)
FileHelper.CleanDir(dir);
}
/// <summary>
/// Creates the test dir structure.
/// </summary>
@@ -40,18 +56,6 @@ public static void CreateTestDirStructure()
CleanDir(TestData.TestDir + "\\Dir8\\Sub1");
}
/// <summary>
/// Tests if dir is empty or doesn't exists.
/// </summary>
/// <param name="dir">The dir.</param>
public static void TestIfDirIsEmpty(string dir)
{
var di = new DirectoryInfo(dir);
if (!di.Exists) return;
Assert.AreEqual(0, Directory.GetDirectories(dir, "*", SearchOption.AllDirectories).Length);
Assert.AreEqual(0, Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories).Length);
}
/// <summary>
/// Creates a test file.
/// </summary>
@@ -166,29 +170,14 @@ public static void CreateTestFileStructure()
}
/// <summary>
/// Tests the creating of directories.
/// </summary>
[Test]
public void TestDirStructure()
public static string[] AllDirectories()
{
CreateTestDirStructure();
Assert.AreEqual(16, Directory.GetDirectories(TestData.TestDir, "*", SearchOption.AllDirectories).Length);
Assert.AreEqual(0, Directory.GetFiles(TestData.TestDir, "*.*", SearchOption.AllDirectories).Length);
return Directory.GetDirectories(TestData.TestDir, "*", SearchOption.AllDirectories);
}
/// <summary>
/// Tests the creating of directories and files.
/// </summary>
[Test]
public void TestFileStructure()
protected static string[] AllFiles()
{
CreateTestFileStructure();
Assert.AreEqual(16, Directory.GetDirectories(TestData.TestDir, "*", SearchOption.AllDirectories).Length);
Assert.AreEqual(17, Directory.GetFiles(TestData.TestDir, "*.*", SearchOption.AllDirectories).Length);
return Directory.GetFiles(TestData.TestDir, "*.*", SearchOption.AllDirectories);
}
}
}
@@ -0,0 +1,30 @@
using System.IO;
using Machine.Specifications;
namespace Test.FAKECore.FileHandling
{
public class when_cleaning_empty_directory_after_creating_test_structure : BaseFunctions
{
Establish context = CreateTestDirStructure;
Because of = () => CleanDir(TestData.TestDir);
It should_cleaned_all_dirs = () => AllDirectories().ShouldBeEmpty();
It should_cleaned_all_files = () => AllFiles().ShouldBeEmpty();
It should_still_exist = () => new DirectoryInfo(TestData.TestDir).Exists.ShouldBeTrue();
}
public class when_cleaning_directory_after_creating_test_structure : BaseFunctions
{
Establish context = CreateTestFileStructure;
Because of = () => CleanDir(TestData.TestDir);
It should_be_writeable =
() => new DirectoryInfo(TestData.TestDir).Attributes.ShouldEqual(FileAttributes.Directory);
It should_cleaned_all_dirs = () => AllDirectories().ShouldBeEmpty();
It should_cleaned_all_files = () => AllFiles().ShouldBeEmpty();
It should_still_exist = () => new DirectoryInfo(TestData.TestDir).Exists.ShouldBeTrue();
}
}
@@ -0,0 +1,36 @@
using System.IO;
using Fake;
using Machine.Specifications;
namespace Test.FAKECore.FileHandling
{
public class when_copying_directory_with_subfolders_but_without_filter : BaseFunctions
{
Establish context = CreateTestFileStructure;
Because of = () => FileHelper.CopyDir(Target, TestData.SubDir7, AllFilesFunction);
It should_have_copied_all_files =
() => Directory.GetFiles(Target, "*.*", SearchOption.AllDirectories).Length.ShouldEqual(6);
It should_have_copied_the_subfolder =
() => Directory.GetDirectories(Target, "*", SearchOption.AllDirectories).Length.ShouldEqual(1);
private static readonly string Target = string.Format("{0}\\CopyTo", TestData.TestDir);
}
public class when_copying_directory_but_without_filter : BaseFunctions
{
Establish context = CreateTestFileStructure;
Because of = () => FileHelper.CopyDir(Target, TestData.SubDir1, AllFilesFunction);
It should_have_copied_all_files =
() => Directory.GetFiles(Target, "*.*", SearchOption.AllDirectories).Length.ShouldEqual(3);
It should_not_have_copied_a_subfolder =
() => Directory.GetDirectories(Target, "*", SearchOption.AllDirectories).ShouldBeEmpty();
private static readonly string Target = string.Format("{0}\\CopyTo", TestData.TestDir);
}
}
@@ -0,0 +1,22 @@
using System.IO;
using Fake;
using Machine.Specifications;
namespace Test.FAKECore.FileHandling
{
public class when_comparing_nonidentical_files
{
private static readonly FileInfo File1 = new FileInfo(@"TestData\AllObjects.txt");
private static readonly FileInfo File2 = new FileInfo(@"TestData\AllObjects_2.txt");
It should_not_be_identical = () => FileHelper.FilesAreEqual(File1, File2).ShouldBeFalse();
}
public class when_comparing_identical_files
{
private static readonly FileInfo File1 = new FileInfo(@"TestData\AllObjects.txt");
private static readonly FileInfo File2 = new FileInfo(@"TestData\AllObjects.txt");
It should_be_identical = () => FileHelper.FilesAreEqual(File1, File2).ShouldBeTrue();
}
}
@@ -0,0 +1,46 @@
using System.Linq;
using Fake;
using Machine.Specifications;
namespace Test.FAKECore.FileHandling
{
public class when_creating_some_directories_and_scanning_them : BaseFunctions
{
Establish context = CreateTestDirStructure;
It should_find_the_test_dir = () => Scan("Test").First().ShouldEqual(TestData.TestDir);
It should_find_only_the_test_dir = () => Scan("Test").Count.ShouldEqual(1);
It should_find_Dir2 = () => ScanCount("**/Dir2").ShouldEqual(1);
It should_find_Sub1_in_subfolder = () => ScanCount("**/**/Sub1").ShouldEqual(6);
It should_find_Sub1 = () => ScanCount("**/Sub1").ShouldEqual(6);
It should_find_Sub1_in_sub2 = () => ScanCount("**/Sub2/Sub1").ShouldEqual(1);
It should_find_Sub2 = () => ScanCount("**/Sub2").ShouldEqual(2);
It should_find_test_directory_in_base_directory = () => Scan(@"Test").First().ShouldEqual(TestData.TestDir);
}
public class when_creating_some_files_and_scanning_them : BaseFunctions
{
Establish context = CreateTestFileStructure;
It should_find_file1 = () => ScanCount("**/file1.nav").ShouldEqual(3);
It should_find_file1_with_every_extension = () => ScanCount("**/file1.*").ShouldEqual(5);
It should_find_file_x = () => ScanCount("**/file?.n??").ShouldEqual(11);
It should_find_file_x_in_subfolder = () => ScanCount("**/Sub1/**/file*.*").ShouldEqual(6);
It should_find_every_nav_file_in_every_folder = () => ScanCount("**/*.nav").ShouldEqual(7);
It should_not_find_a_nav_file_in_root = () => ScanCount("*.nav").ShouldEqual(0);
It should_find_all_files_in_test_folder = () => ScanCount("Test/*.*").ShouldEqual(5);
}
public class when_creating_some_files_and_scanning_them_with_concrete_path : BaseFunctions
{
Establish context = CreateTestFileStructure;
It should_find_file1 = () => ScanCount(FileSetHelper.DefaultBaseDir + "/**/file1.nav").ShouldEqual(3);
It should_find_file1_with_every_extension = () => ScanCount(FileSetHelper.DefaultBaseDir + "/**/file1.*").ShouldEqual(5);
It should_find_file_x = () => ScanCount(FileSetHelper.DefaultBaseDir + "/**/file?.n??").ShouldEqual(11);
It should_find_file_x_in_subfolder = () => ScanCount(FileSetHelper.DefaultBaseDir + "/Test/**/Sub1/**/file*.*").ShouldEqual(6);
It should_find_every_nav_file_in_every_folder = () => ScanCount(FileSetHelper.DefaultBaseDir + "/Test/**/*.nav").ShouldEqual(7);
It should_not_find_a_nav_file_in_root = () => ScanCount(FileSetHelper.DefaultBaseDir + "/*.nav").ShouldEqual(0);
It should_find_all_files_in_test_folder = () => ScanCount(FileSetHelper.DefaultBaseDir + "/Test/*.*").ShouldEqual(5);
}
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 9aaa320

Please sign in to comment.