Skip to content

Commit a51a373

Browse files
ewildeJakeGinnivan
authored andcommitted
Implement configuration convention Closes #58
1 parent 6a99e41 commit a51a373

17 files changed

+399
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ _ReSharper.*
1414
ConventionTests*.nupkg
1515
_NCrunch*
1616
*.received.txt
17-
*.orig
17+
*.orig
18+
packages
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace SampleApp.Tests
2+
{
3+
using System;
4+
using System.IO;
5+
using System.Xml.Linq;
6+
using NSubstitute;
7+
using NUnit.Framework;
8+
using SampleApp.Domain;
9+
using SampleApp.Dtos;
10+
using TestStack.ConventionTests;
11+
using TestStack.ConventionTests.ConventionData;
12+
using TestStack.ConventionTests.Conventions;
13+
using TestStack.ConventionTests.Internal;
14+
15+
[TestFixture]
16+
public class ProjectConfigurationTests
17+
{
18+
IProjectLocator projectLocator;
19+
IProjectProvider projectProvider;
20+
21+
[SetUp]
22+
public void Setup()
23+
{
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")))));
29+
}
30+
31+
[Test]
32+
public void debug_configurations_should_have_debug_type_pdb_only()
33+
{
34+
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Debug, "DebugType", "full"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
35+
}
36+
37+
[Test]
38+
public void debug_configurations_should_have_optimize_false()
39+
{
40+
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Debug, "Optimize", "false"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
41+
}
42+
43+
[Test]
44+
public void release_configurations_should_have_debug_type_pdb_only()
45+
{
46+
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "DebugType", "pdbonly"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
47+
}
48+
49+
[Test]
50+
public void release_configurations_should_have_optimize_true()
51+
{
52+
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "Optimize", "true"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
53+
}
54+
}
55+
}

Samples/SampleApp.Tests/SampleApp.Tests.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,26 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34+
<Reference Include="Mono.Cecil, Version=0.9.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
35+
<SpecificVersion>False</SpecificVersion>
36+
<HintPath>..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Mono.Cecil.Mdb">
39+
<HintPath>..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Mono.Cecil.Pdb">
42+
<HintPath>..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Mono.Cecil.Rocks">
45+
<HintPath>..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
46+
</Reference>
3447
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
3548
<SpecificVersion>False</SpecificVersion>
3649
<HintPath>..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
3750
</Reference>
51+
<Reference Include="NSubstitute">
52+
<HintPath>..\..\packages\NSubstitute.1.6.1.0\lib\NET40\NSubstitute.dll</HintPath>
53+
</Reference>
3854
<Reference Include="nunit.framework">
3955
<HintPath>..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
4056
</Reference>
@@ -63,6 +79,7 @@
6379
<Compile Include="DomainTests.cs" />
6480
<Compile Include="DtoTests.cs" />
6581
<Compile Include="MvcTests.cs" />
82+
<Compile Include="ProjectConfigurationTests.cs" />
6683
<Compile Include="Properties\AssemblyInfo.cs" />
6784
<Compile Include="SqlScriptTests.cs" />
6885
<Compile Include="WebApiTests.cs" />

Samples/SampleApp.Tests/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net40" />
44
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.30506.0" targetFramework="net40" />
55
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
6+
<package id="Mono.Cecil" version="0.9.5.4" targetFramework="net40" />
67
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
8+
<package id="NSubstitute" version="1.6.1.0" targetFramework="net40" />
79
<package id="NUnit" version="2.6.2" targetFramework="net40" />
810
</packages>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace TestStack.ConventionTests.Tests.ConventionData
2+
{
3+
using System.Linq;
4+
using System.Xml.Linq;
5+
using NSubstitute;
6+
using NUnit.Framework;
7+
using TestStack.ConventionTests.ConventionData;
8+
using TestStack.ConventionTests.Internal;
9+
using TestStack.ConventionTests.Tests.Properties;
10+
11+
[TestFixture]
12+
public class ProjectPropertyGroupsTests
13+
{
14+
IProjectProvider projectProvider;
15+
16+
[SetUp]
17+
public void Setup()
18+
{
19+
projectProvider = Substitute.For<IProjectProvider>();
20+
}
21+
22+
[Test]
23+
public void can_parse_a_normal_project_file_to_read_global_debug_and_release_property_groups()
24+
{
25+
projectProvider
26+
.LoadProjectDocument(Arg.Any<string>())
27+
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));
28+
29+
var projectGroups = new ProjectPropertyGroups(typeof(ProjectPropertyGroups).Assembly, projectProvider, Substitute.For<IProjectLocator>());
30+
31+
Assert.That(projectGroups.PropertyGroups.Length, Is.EqualTo(3));
32+
Assert.That(projectGroups.PropertyGroups.Any(item => item.Debug));
33+
Assert.That(projectGroups.PropertyGroups.Any(item => item.Release));
34+
Assert.That(projectGroups.PropertyGroups.Any(item => item.Global));
35+
}
36+
}
37+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'Optimize property in Release|AnyCPU must have a value of true' for 'Project property groups in TestStack.ConventionTests.Tests'
2+
--------------------------------------------------------------------------------------------------------------------------------
3+
4+
Optimize:false
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'Platform property in Release|x86 must have a value of AnyCPU' for 'Project property groups in TestStack.ConventionTests.Tests'
2+
-------------------------------------------------------------------------------------------------------------------------------
3+
4+
Platform:x86

TestStack.ConventionTests.Tests/ProjectBasedConventions.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,53 @@ public void scripts_not_embedded_resources_with_approved_exceptions()
7474

7575
Convention.IsWithApprovedExeptions(new FilesAreEmbeddedResources(".sql"), project);
7676
}
77+
78+
[Test]
79+
public void release_debug_type_should_be_pdb_only()
80+
{
81+
projectProvider
82+
.LoadProjectDocument(Arg.Any<string>())
83+
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));
84+
85+
var projectLocator = Substitute.For<IProjectLocator>();
86+
var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
87+
var ex =
88+
Assert.Throws<ConventionFailedException>(
89+
() => Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "DebugType", "pdbonly"), propertyGroups));
90+
91+
Approvals.Verify(ex.Message);
92+
}
93+
94+
[Test]
95+
public void all_configuration_groups_should_have_platform_AnyCPU()
96+
{
97+
projectProvider
98+
.LoadProjectDocument(Arg.Any<string>())
99+
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));
100+
101+
var projectLocator = Substitute.For<IProjectLocator>();
102+
var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
103+
var ex =
104+
Assert.Throws<ConventionFailedException>(
105+
() => Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.All, "Platform", "AnyCPU"), propertyGroups));
106+
107+
Approvals.Verify(ex.Message);
108+
}
109+
110+
[Test]
111+
public void all_configuration_groups_should_have_optimize_true_if_property_defined()
112+
{
113+
projectProvider
114+
.LoadProjectDocument(Arg.Any<string>())
115+
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));
116+
117+
var projectLocator = Substitute.For<IProjectLocator>();
118+
var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
119+
var ex =
120+
Assert.Throws<ConventionFailedException>(
121+
() => Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.All, "Optimize", "true"), propertyGroups));
122+
123+
Approvals.Verify(ex.Message);
124+
}
77125
}
78126
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'DebugType property in Release|AnyCPU must have a value of pdbonly' for 'Project property groups in TestStack.ConventionTests.Tests'
2+
------------------------------------------------------------------------------------------------------------------------------------
3+
4+
DebugType:full
5+
6+
'DebugType property in Release|x86 must have a value of pdbonly' for 'Project property groups in TestStack.ConventionTests.Tests'
7+
---------------------------------------------------------------------------------------------------------------------------------
8+
9+
DebugType:full

TestStack.ConventionTests.Tests/Properties/Resources.Designer.cs

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)