Skip to content

Commit

Permalink
Bugfix and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Counts committed Dec 6, 2014
1 parent 6c44a4f commit 45f3c68
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 264 deletions.
99 changes: 51 additions & 48 deletions ApprovalTests.Tests/Asp/Mvc/MvcTest.cs
@@ -1,71 +1,74 @@
using System.Collections.Specialized;

using ApprovalTests.Asp;
using ApprovalTests.Asp.Mvc;
using ApprovalTests.Reporters;

using CassiniDev;

using MvcApplication1;
using MvcApplication1.Controllers;
using MvcApplication1.Models;

using NUnit.Framework;

namespace ApprovalTests.Tests.Asp.Mvc
{
public class MvcTest
{
[TestFixture]
[UseReporter(typeof (TortoiseDiffReporter), typeof (AllFailingTestsClipboardReporter))]
public class TryingMvcViewApproval
{
private CassiniDevServer server = new CassiniDevServer();

[TestFixtureSetUp]
public void Setup()
{
PortFactory.MvcPort = 11624;
server.StartServer(MvcApplication.Path, PortFactory.MvcPort, "/", "localhost");
}
public class MvcTest
{
[TestFixture]
[UseReporter(typeof(DiffReporter), typeof(AllFailingTestsClipboardReporter))]
public class TryingMvcViewApproval
{
private readonly CassiniDevServer server = new CassiniDevServer();

[TestFixtureTearDown]
public void TearDown()
{
server.StopServer();
}
[TestFixtureSetUp]
public void Setup()
{
PortFactory.MvcPort = 11624;
this.server.StartServer(MvcApplication.Path, PortFactory.MvcPort, "/", "localhost");
}

[TestFixtureTearDown]
public void TearDown()
{
this.server.StopServer();
}

[Test]
public void TestingSomeMvcView()
{
//AspApprovals.VerifyUrlViaPost("http://localhost:11624/Cool/Index");
MvcApprovals.VerifyMvcPage(new CoolController().Index);
}
[Test]
public void TestingSomeMvcView()
{
// AspApprovals.VerifyUrlViaPost("http://localhost:11624/Cool/Index");
MvcApprovals.VerifyMvcPage(new CoolController().Index);
}

[Test]
public void TestingPostView()
{
MvcApprovals.VerifyUrlViaPost("http://localhost:11624/Cool/SaveName", new NameValueCollection {{"Name", "Henrik"}});
}
[Test]
public void TestingPostView()
{
MvcApprovals.VerifyUrlViaPost("http://localhost:11624/Cool/SaveName", new NameValueCollection { { "Name", "Henrik" } });
}

[Test]
public void TestingMvcWithPost()
{
MvcApprovals.VerifyMvcViaPost<Person>(new CoolController().SaveName, new NameValueCollection {{"Name", "Henrik"}});
}
[Test]
public void TestingMvcWithPost()
{
MvcApprovals.VerifyMvcViaPost<Person>(new CoolController().SaveName, new NameValueCollection { { "Name", "Henrik" } });
}

[Test]
public void TestingMvcWithPost2()
{
MvcApprovals.VerifyMvcViaPost<Person>(new CoolController().SaveName, new Person {Name = "Henrik"});
}
[Test]
public void TestingMvcWithPost2()
{
MvcApprovals.VerifyMvcViaPost(new CoolController().SaveName, new Person { Name = "Henrik" });
}

# if DEBUG
#if DEBUG

[Test]
public void TestWithName()
{
MvcApprovals.VerifyMvcPage(new CoolController().TestName);
}
[Test]
public void TestWithName()
{
MvcApprovals.VerifyMvcPage(new CoolController().TestName);
}

#endif
}
}
}
}
}
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head><base href="http://localhost:11624/Cool">
<meta charset="utf-8" />
Expand Down
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head><base href="http://localhost:11624/Cool">
<meta charset="utf-8" />
Expand Down
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head><base href="http://localhost:11624/Cool">
<meta charset="utf-8" />
Expand Down
58 changes: 29 additions & 29 deletions ApprovalTests.Tests/FailedApprovalTests.cs
Expand Up @@ -4,36 +4,36 @@

namespace ApprovalTests.Tests
{
[TestFixture]
[UseReporter(typeof(CleanupReporter))]
internal class FailedApprovalTests
{
[Test]
[ExpectedException(typeof(ApprovalMismatchException))]
public void EnumerableDoesNotMatchApproval()
{
Approvals.VerifyAll(new[] { "Does not match" }, "collection");
}
[TestFixture]
[UseReporter(typeof(CleanupReporter))]
public class FailedApprovalTests
{
[Test]
[ExpectedException(typeof(ApprovalMismatchException))]
public void EnumerableDoesNotMatchApproval()
{
Approvals.VerifyAll(new[] { "Does not match" }, "collection");
}

[Test]
[ExpectedException(typeof(ApprovalMissingException))]
public void EnumerableNotApprovedYet()
{
Approvals.VerifyAll(new[] { "Not approved" }, "collection");
}
[Test]
[ExpectedException(typeof(ApprovalMissingException))]
public void EnumerableNotApprovedYet()
{
Approvals.VerifyAll(new[] { "Not approved" }, "collection");
}

[Test]
[ExpectedException(typeof(ApprovalMismatchException))]
public void TextDoesNotMatchApproval()
{
Approvals.Verify("should fail with mismatch");
}
[Test]
[ExpectedException(typeof(ApprovalMismatchException))]
public void TextDoesNotMatchApproval()
{
Approvals.Verify("should fail with mismatch");
}

[Test]
[ExpectedException(typeof(ApprovalMissingException))]
public void TextNotApprovedYet()
{
Approvals.Verify("should fail with a missing exception");
}
}
[Test]
[ExpectedException(typeof(ApprovalMissingException))]
public void TextNotApprovedYet()
{
Approvals.Verify("should fail with a missing exception");
}
}
}
112 changes: 55 additions & 57 deletions ApprovalTests.Tests/Reporters/GenericDiffReporterTest.cs
@@ -1,72 +1,70 @@
using System.IO;
using ApprovalTests.Reporters;
using ApprovalUtilities.Utilities;
using NUnit.Framework;
using System.IO;

namespace ApprovalTests.Tests.Reporters
{
[TestFixture]
public class GenericDiffReporterTest
{
[Test]
public void TestGetActualProgramFileEchos()
{
string NoneExistingFile = @"C:\ThisDirectoryShouldNotExist\ThisFileShouldNotExist.exe";
Assert.AreEqual(NoneExistingFile, GenericDiffReporter.GetActualProgramFile(NoneExistingFile));
}

[Test]
public void TestGetCurrentProject()
{
var file = PathUtilities.GetAdjacentFile("GenericDiffReporterTest.TestLaunchesBeyondCompareImage.approved.txt");
string currentProjectFile = Path.GetFileName(VisualStudioProjectFileAdder.GetCurrentProjectFile(file));

Assert.AreEqual("ApprovalTests.Tests.csproj", currentProjectFile);
}
[TestFixture]
public class GenericDiffReporterTest
{
[Test]
public void TestGetActualProgramFileEchos()
{
string NoneExistingFile = @"C:\ThisDirectoryShouldNotExist\ThisFileShouldNotExist.exe";
Assert.AreEqual(NoneExistingFile, GenericDiffReporter.GetActualProgramFile(NoneExistingFile));
}

[Test]
public void TestGetCurrentProjectNotFound()
{
var project = VisualStudioProjectFileAdder.GetCurrentProjectFile("C:\\");
[Test]
public void TestGetCurrentProject()
{
var file = PathUtilities.GetAdjacentFile("GenericDiffReporterTest.TestLaunchesBeyondCompareImage.approved.txt");
string currentProjectFile = Path.GetFileName(VisualStudioProjectFileAdder.GetCurrentProjectFile(file));

Assert.AreEqual(null, project);
}
Assert.AreEqual("ApprovalTests.Tests.csproj", currentProjectFile);
}

[Test]
public void TestGetCurrentProjectNotFound()
{
var project = VisualStudioProjectFileAdder.GetCurrentProjectFile("C:\\");

[Test]
public void TestMissingDots()
{
var e =
ExceptionUtilities.GetException(() => GenericDiffReporter.RegisterTextFileTypes(".exe", "txt", ".error", "asp"));
Approvals.Verify(e);
}
Assert.AreEqual(null, project);
}

[Test]
public void TestProgramsExist()
{
Assert.IsFalse(new GenericDiffReporter("this_should_never_exist", "").IsWorkingInThisEnvironment("any.txt"));
}
[Test]
public void TestMissingDots()
{
var e =
ExceptionUtilities.GetException(() => GenericDiffReporter.RegisterTextFileTypes(".exe", "txt", ".error", "asp"));
Approvals.Verify(e);
}

[Test]
public void TestRegisterWorks()
{
var r = new TortoiseDiffReporter();
GenericDiffReporter.RegisterTextFileTypes(".myCrazyExtension");
Assert.IsTrue(r.IsWorkingInThisEnvironment("file.myCrazyExtension"));
}
[Test]
public void TestProgramsExist()
{
Assert.IsFalse(new GenericDiffReporter("this_should_never_exist", "").IsWorkingInThisEnvironment("any.txt"));
}

[Test]
public void TestRegisterWorks()
{
var r = new CodeCompareReporter();
GenericDiffReporter.RegisterTextFileTypes(".myCrazyExtension");
Assert.IsTrue(r.IsWorkingInThisEnvironment("file.myCrazyExtension"));
}

[Test]
[UseReporter(typeof (ClipboardReporter))]
public void TestEnsureFileExist()
{
var imageFile = PathUtilities.GetAdjacentFile("TestImage.png");
if (File.Exists(imageFile))
{
File.Delete(imageFile);
}
GenericDiffReporter.EnsureFileExists(imageFile);
Approvals.VerifyFile(imageFile);
}
}
[Test]
[UseReporter(typeof(ClipboardReporter))]
public void TestEnsureFileExist()
{
var imageFile = PathUtilities.GetAdjacentFile("TestImage.png");
if (File.Exists(imageFile))
{
File.Delete(imageFile);
}
GenericDiffReporter.EnsureFileExists(imageFile);
Approvals.VerifyFile(imageFile);
}
}
}
27 changes: 16 additions & 11 deletions ApprovalTests.Tests/Reporters/TortoiseImageDiffTest.cs
Expand Up @@ -4,15 +4,20 @@

namespace ApprovalTests.Tests.Reporters
{
[TestFixture]
public class TortoiseImageDiffTest
{
[Test]
public void TestIsImage()
{
var files = new string[] { "image.png", "image.gif", "image.jpg", "image.jpeg",
"image.tif", "image.tiff","movie.avi", "text.txt", "excel.xls" };
Approvals.VerifyAll(files, f => "{0} => {1}".FormatWith(f, TortoiseImageDiffReporter.INSTANCE.IsWorkingInThisEnvironment(f)));
}
}
[TestFixture]
public class TortoiseImageDiffTest
{
[Test]
public void TestIsImage()
{
var files = new[]
{
"image.png", "image.gif", "image.jpg", "image.jpeg", "image.tif", "image.tiff",
"movie.avi", "text.txt", "excel.xls"
};
Approvals.VerifyAll(
files,
f => "{0} => {1}".FormatWith(f, TortoiseImageDiffReporter.INSTANCE.IsWorkingInThisEnvironment(f)));
}
}
}
1 change: 1 addition & 0 deletions ApprovalTests.sln.DotSettings
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantUsingDirective/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1200/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1600/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1633/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedParameter_002EGlobal/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedParameter_002ELocal/@EntryIndexedValue">ERROR</s:String>
Expand Down

0 comments on commit 45f3c68

Please sign in to comment.