Skip to content

Commit 3b2ef28

Browse files
committed
Breaking change - Mono.Cecil dependency removed
- Removed IProjectLocator, you cannot find the project without reading PDB's - Users can either pass a path in, or give a project provider which can return the xml directly This results in simpler and easier to understand usage. Less magic and we don't have the mono.cecil dependency :)
1 parent 611d124 commit 3b2ef28

21 files changed

+123
-154
lines changed

ConventionTests.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.22823.1
4+
VisualStudioVersion = 14.0.24720.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AF9054EE-FE89-47A4-9156-BE54A837F2F7}"
77
ProjectSection(SolutionItems) = preProject

Samples/SampleApp.Tests/ProjectConfigurationTests.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,51 @@
22
{
33
using System;
44
using System.IO;
5-
using System.Xml.Linq;
6-
using NSubstitute;
75
using NUnit.Framework;
8-
using SampleApp.Domain;
9-
using SampleApp.Dtos;
106
using TestStack.ConventionTests;
117
using TestStack.ConventionTests.ConventionData;
128
using TestStack.ConventionTests.Conventions;
13-
using TestStack.ConventionTests.Internal;
149

1510
[TestFixture]
1611
public class ProjectConfigurationTests
1712
{
18-
IProjectLocator projectLocator;
19-
IProjectProvider projectProvider;
13+
string projectLocation;
2014

21-
[SetUp]
22-
public void Setup()
15+
public ProjectConfigurationTests()
2316
{
24-
projectLocator = Substitute.For<IProjectLocator>();
25-
projectProvider = Substitute.For<IProjectProvider>();
26-
projectProvider
27-
.LoadProjectDocument(Arg.Any<string>())
28-
.Returns(XDocument.Parse(File.ReadAllText(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\SampleApp\SampleApp.csproj")))));
17+
projectLocation = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\SampleApp\SampleApp.csproj"));
2918
}
3019

3120
[Test]
3221
public void debug_configurations_should_have_debug_type_pdb_only()
3322
{
34-
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Debug, "DebugType", "full"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
23+
var configurationHasSpecificValue = new ConfigurationHasSpecificValue(ConfigurationType.Debug, "DebugType", "full");
24+
var projectPropertyGroups = new ProjectPropertyGroups(projectLocation);
25+
Convention.Is(configurationHasSpecificValue, projectPropertyGroups);
3526
}
3627

3728
[Test]
3829
public void debug_configurations_should_have_optimize_false()
3930
{
40-
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Debug, "Optimize", "false"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
31+
var configurationHasSpecificValue = new ConfigurationHasSpecificValue(ConfigurationType.Debug, "Optimize", "false");
32+
var projectPropertyGroups = new ProjectPropertyGroups(projectLocation);
33+
Convention.Is(configurationHasSpecificValue, projectPropertyGroups);
4134
}
4235

4336
[Test]
4437
public void release_configurations_should_have_debug_type_pdb_only()
4538
{
46-
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "DebugType", "pdbonly"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
39+
var configurationHasSpecificValue = new ConfigurationHasSpecificValue(ConfigurationType.Release, "DebugType", "pdbonly");
40+
var projectPropertyGroups = new ProjectPropertyGroups(projectLocation);
41+
Convention.Is(configurationHasSpecificValue, projectPropertyGroups);
4742
}
4843

4944
[Test]
5045
public void release_configurations_should_have_optimize_true()
5146
{
52-
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "Optimize", "true"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
47+
var configurationHasSpecificValue = new ConfigurationHasSpecificValue(ConfigurationType.Release, "Optimize", "true");
48+
var projectPropertyGroups = new ProjectPropertyGroups(projectLocation);
49+
Convention.Is(configurationHasSpecificValue, projectPropertyGroups);
5350
}
5451
}
5552
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace SampleApp.Tests
22
{
3+
using System;
4+
using System.IO;
35
using NUnit.Framework;
46
using SampleApp.Domain;
57
using TestStack.ConventionTests;
@@ -9,11 +11,17 @@
911
[TestFixture]
1012
public class SqlScriptTests
1113
{
14+
string projectLocation;
15+
16+
public SqlScriptTests()
17+
{
18+
projectLocation = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\SampleApp\SampleApp.csproj"));
19+
}
20+
1221
[Test]
13-
[Explicit] // Only works when shadow copy disabled for tests
1422
public void SqlScriptsShouldBeEmbeddedResources()
1523
{
16-
Convention.Is(new FilesAreEmbeddedResources(".sql"), new ProjectFileItems(typeof(DomainClass).Assembly));
24+
Convention.Is(new FilesAreEmbeddedResources(".sql"), new ProjectFileItems(projectLocation));
1725
}
1826
}
1927
}

TestStack.ConventionTests.Tests/ConventionData/ProjectPropertyGroupsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public void Setup()
2323
public void can_parse_a_normal_project_file_to_read_global_debug_and_release_property_groups()
2424
{
2525
projectProvider
26-
.LoadProjectDocument(Arg.Any<string>())
26+
.LoadProjectDocument()
2727
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));
2828

29-
var projectGroups = new ProjectPropertyGroups(typeof(ProjectPropertyGroups).Assembly, projectProvider, Substitute.For<IProjectLocator>());
29+
var projectGroups = new ProjectPropertyGroups(projectProvider);
3030

3131
Assert.That(projectGroups.PropertyGroups.Length, Is.EqualTo(3));
3232
Assert.That(projectGroups.PropertyGroups.Any(item => item.Debug));
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'Optimize property in Release|AnyCPU must have a value of true' for 'Project property groups in TestStack.ConventionTests.Tests'
2-
--------------------------------------------------------------------------------------------------------------------------------
1+
'Optimize property in Release|AnyCPU must have a value of true' for 'Project property groups in ProjectName'
2+
------------------------------------------------------------------------------------------------------------
33

44
Optimize:false
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
'Platform property in Release|x86 must have a value of AnyCPU' for 'Project property groups in TestStack.ConventionTests.Tests'
2-
-------------------------------------------------------------------------------------------------------------------------------
1+
'Platform property in Global must have a value of AnyCPU' for 'Project property groups in ProjectName'
2+
------------------------------------------------------------------------------------------------------
3+
4+
5+
'Platform property in Release|AnyCPU must have a value of AnyCPU' for 'Project property groups in ProjectName'
6+
--------------------------------------------------------------------------------------------------------------
7+
8+
9+
'Platform property in Release|x86 must have a value of AnyCPU' for 'Project property groups in ProjectName'
10+
-----------------------------------------------------------------------------------------------------------
311

412
Platform:x86
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'Project must not reference dlls from bin or obj directories' for 'Project references in TestStack.ConventionTests.Tests'
2-
-------------------------------------------------------------------------------------------------------------------------
1+
'Project must not reference dlls from bin or obj directories' for 'Project references in ProjectName'
2+
-----------------------------------------------------------------------------------------------------
33

44
bin\Debug\ApprovalTests.dll
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'Project must not reference dlls from bin or obj directories' for 'Project references in TestStack.ConventionTests.Tests'
2-
-------------------------------------------------------------------------------------------------------------------------
1+
'Project must not reference dlls from bin or obj directories' for 'Project references in ProjectName'
2+
-----------------------------------------------------------------------------------------------------
33

44
bin\Debug\ApprovalTests.dll

TestStack.ConventionTests.Tests/ProjectBasedConventions.cs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ public class ProjectBasedConventions
1818
public void Setup()
1919
{
2020
projectProvider = Substitute.For<IProjectProvider>();
21+
projectProvider.GetName().Returns("ProjectName");
2122
}
2223

2324
[Test]
2425
public void assemblies_referencing_bin_obj()
2526
{
2627
projectProvider
27-
.LoadProjectDocument(Arg.Any<string>())
28+
.LoadProjectDocument()
2829
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));
29-
30-
var projectLocator = Substitute.For<IProjectLocator>();
31-
var project = new ProjectReferences(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
30+
31+
var project = new ProjectReferences(projectProvider);
3232
var failures = Convention.GetFailures(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project);
3333

3434
failures.ShouldMatchApproved();
@@ -38,12 +38,10 @@ public void assemblies_referencing_bin_obj()
3838
public void assemblies_referencing_bin_obj_with_approved_exceptions()
3939
{
4040
projectProvider
41-
.LoadProjectDocument(Arg.Any<string>())
41+
.LoadProjectDocument()
4242
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));
4343

44-
45-
var projectLocator = Substitute.For<IProjectLocator>();
46-
var project = new ProjectReferences(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
44+
var project = new ProjectReferences(projectProvider);
4745
var failures = Convention.GetFailures(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project);
4846

4947
failures.ShouldMatchApproved();
@@ -53,11 +51,10 @@ public void assemblies_referencing_bin_obj_with_approved_exceptions()
5351
public void scripts_not_embedded_resources()
5452
{
5553
projectProvider
56-
.LoadProjectDocument(Arg.Any<string>())
54+
.LoadProjectDocument()
5755
.Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile));
58-
59-
var projectLocator = Substitute.For<IProjectLocator>();
60-
var project = new ProjectFileItems(typeof (ProjectBasedConventions).Assembly, projectProvider, projectLocator);
56+
57+
var project = new ProjectFileItems(projectProvider);
6158
var failures = Convention.GetFailures(new FilesAreEmbeddedResources(".sql"), project);
6259

6360
failures.ShouldMatchApproved();
@@ -66,10 +63,9 @@ public void scripts_not_embedded_resources()
6663
[Test]
6764
public void scripts_not_embedded_resources_with_approved_exceptions()
6865
{
69-
var projectLocator = Substitute.For<IProjectLocator>();
70-
var project = new ProjectFileItems(typeof (ProjectBasedConventions).Assembly, projectProvider, projectLocator);
66+
var project = new ProjectFileItems(projectProvider);
7167
projectProvider
72-
.LoadProjectDocument(Arg.Any<string>())
68+
.LoadProjectDocument()
7369
.Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile));
7470

7571
Convention.GetFailures(new FilesAreEmbeddedResources(".sql"), project);
@@ -79,11 +75,10 @@ public void scripts_not_embedded_resources_with_approved_exceptions()
7975
public void release_debug_type_should_be_pdb_only()
8076
{
8177
projectProvider
82-
.LoadProjectDocument(Arg.Any<string>())
78+
.LoadProjectDocument()
8379
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));
8480

85-
var projectLocator = Substitute.For<IProjectLocator>();
86-
var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
81+
var propertyGroups = new ProjectPropertyGroups(projectProvider);
8782
var failures = Convention.GetFailures(new ConfigurationHasSpecificValue(ConfigurationType.Release, "DebugType", "pdbonly"), propertyGroups);
8883

8984
failures.ShouldMatchApproved();
@@ -93,11 +88,10 @@ public void release_debug_type_should_be_pdb_only()
9388
public void all_configuration_groups_should_have_platform_AnyCPU()
9489
{
9590
projectProvider
96-
.LoadProjectDocument(Arg.Any<string>())
91+
.LoadProjectDocument()
9792
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));
9893

99-
var projectLocator = Substitute.For<IProjectLocator>();
100-
var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
94+
var propertyGroups = new ProjectPropertyGroups(projectProvider);
10195
var failures = Convention.GetFailures(new ConfigurationHasSpecificValue(ConfigurationType.All, "Platform", "AnyCPU"), propertyGroups);
10296

10397
failures.ShouldMatchApproved();
@@ -107,11 +101,10 @@ public void all_configuration_groups_should_have_platform_AnyCPU()
107101
public void all_configuration_groups_should_have_optimize_true_if_property_defined()
108102
{
109103
projectProvider
110-
.LoadProjectDocument(Arg.Any<string>())
104+
.LoadProjectDocument()
111105
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));
112106

113-
var projectLocator = Substitute.For<IProjectLocator>();
114-
var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
107+
var propertyGroups = new ProjectPropertyGroups(projectProvider);
115108
var failures =
116109
Convention.GetFailures(new ConfigurationHasSpecificValue(ConfigurationType.All, "Optimize", "true"),
117110
propertyGroups);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
'DebugType property in Release|AnyCPU must have a value of pdbonly' for 'Project property groups in TestStack.ConventionTests.Tests'
2-
------------------------------------------------------------------------------------------------------------------------------------
1+
'DebugType property in Release|AnyCPU must have a value of pdbonly' for 'Project property groups in ProjectName'
2+
----------------------------------------------------------------------------------------------------------------
33

44
DebugType:full
55

6-
'DebugType property in Release|x86 must have a value of pdbonly' for 'Project property groups in TestStack.ConventionTests.Tests'
7-
---------------------------------------------------------------------------------------------------------------------------------
6+
'DebugType property in Release|x86 must have a value of pdbonly' for 'Project property groups in ProjectName'
7+
-------------------------------------------------------------------------------------------------------------
88

99
DebugType:full

0 commit comments

Comments
 (0)