Skip to content

Commit 7b63a34

Browse files
author
Jake Ginnivan
committed
Fixed tests, introduced 'IsWithApprovedExeptions' for activating approvals in ConventionTest
1 parent 46d1bda commit 7b63a34

23 files changed

+170
-55
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Header
2+
3+
Approved Exception
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace TestStack.ConventionTests.Tests
2+
{
3+
using ApprovalTests.Reporters;
4+
using NUnit.Framework;
5+
using TestStack.ConventionTests.Internal;
6+
7+
[TestFixture]
8+
[UseReporter(typeof(DiffReporter))] //NOTE: Can we take care of this in IsWithApprovedExceptions?
9+
public class ConventionAssertionClassTests
10+
{
11+
[Test]
12+
public void approval_mismatch()
13+
{
14+
//NOTE Do not approve any changes to this test
15+
var ex = Assert.Throws<ConventionFailedException>(() => Convention.IsWithApprovedExeptions(new FailingConvention(), new FakeData()));
16+
17+
StringAssert.Contains("Approved exceptions for convention differs", ex.Message);
18+
StringAssert.Contains("Failed Approval: Received file ", ex.Message);
19+
StringAssert.Contains("does not match approved file", ex.Message);
20+
}
21+
22+
public class FakeData : IConventionData
23+
{
24+
public void ThrowIfHasInvalidSource()
25+
{
26+
}
27+
}
28+
29+
public class FailingConvention : IConvention<FakeData>
30+
{
31+
public ConventionResult Execute(FakeData data)
32+
{
33+
return ConventionResult.For(new[] { "" }, "Header", (s, builder) => builder.AppendLine("Different"));
34+
}
35+
}
36+
}
37+
}

TestStack.ConventionTests.Tests/ProjectBasedConventions.BrokenReferences.received.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

TestStack.ConventionTests.Tests/ProjectBasedConventions.ReferencingBinObj.approved.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

TestStack.ConventionTests.Tests/ProjectBasedConventions.ScriptsNotEmbeddedResources.approved.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

TestStack.ConventionTests.Tests/ProjectBasedConventions.ScriptsNotEmbeddedResources.approved.txt.orig

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Some invalid assembly references found in TestStack.ConventionTests.Tests
2+
3+
bin\Debug\ApprovalTests.dll
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Some invalid assembly references found in TestStack.ConventionTests.Tests
2+
3+
bin\Debug\ApprovalTests.dll

TestStack.ConventionTests.Tests/ProjectBasedConventions.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace TestStack.ConventionTests.Tests
22
{
33
using System.Xml.Linq;
4+
using ApprovalTests;
45
using ApprovalTests.Reporters;
56
using NSubstitute;
67
using NUnit.Framework;
@@ -24,24 +25,49 @@ public void Setup()
2425
}
2526

2627
[Test]
27-
public void ReferencingBinObj()
28+
public void assemblies_referencing_bin_obj()
2829
{
2930
projectProvider
3031
.LoadProjectDocument(Arg.Any<string>())
3132
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));
3233

33-
Convention.Is(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project);
34+
var ex = Assert.Throws<ConventionFailedException>(() => Convention.Is(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project));
35+
36+
Approvals.Verify(ex.Message);
37+
}
38+
39+
[Test]
40+
public void assemblies_referencing_bin_obj_with_approved_exceptions()
41+
{
42+
projectProvider
43+
.LoadProjectDocument(Arg.Any<string>())
44+
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));
45+
46+
Convention.IsWithApprovedExeptions(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project);
47+
}
48+
49+
[Test]
50+
public void scripts_not_embedded_resources()
51+
{
52+
project.Includes = i => i.EndsWith(".sql");
53+
projectProvider
54+
.LoadProjectDocument(Arg.Any<string>())
55+
.Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile));
56+
57+
var ex = Assert.Throws<ConventionFailedException>(() => Convention.Is(new FilesAreEmbeddedResources(), project));
58+
59+
Approvals.Verify(ex.Message);
3460
}
3561

3662
[Test]
37-
public void ScriptsNotEmbeddedResources()
63+
public void scripts_not_embedded_resources_with_approved_exceptions()
3864
{
3965
project.Includes = i => i.EndsWith(".sql");
4066
projectProvider
4167
.LoadProjectDocument(Arg.Any<string>())
4268
.Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile));
4369

44-
Convention.Is(new FilesAreEmbeddedResources(), project);
70+
Convention.IsWithApprovedExeptions(new FilesAreEmbeddedResources(), project);
4571
}
4672
}
4773
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The following files which should be embedded resources:
2+
3+
Scripts\Script2.sql

0 commit comments

Comments
 (0)