Skip to content

Commit

Permalink
Breaking change - Mono.Cecil dependency removed
Browse files Browse the repository at this point in the history
 - 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 :)
  • Loading branch information
JakeGinnivan committed Jan 30, 2016
1 parent 611d124 commit 3b2ef28
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 154 deletions.
2 changes: 1 addition & 1 deletion ConventionTests.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22823.1
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AF9054EE-FE89-47A4-9156-BE54A837F2F7}"
ProjectSection(SolutionItems) = preProject
Expand Down
33 changes: 15 additions & 18 deletions Samples/SampleApp.Tests/ProjectConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,51 @@
{
using System;
using System.IO;
using System.Xml.Linq;
using NSubstitute;
using NUnit.Framework;
using SampleApp.Domain;
using SampleApp.Dtos;
using TestStack.ConventionTests;
using TestStack.ConventionTests.ConventionData;
using TestStack.ConventionTests.Conventions;
using TestStack.ConventionTests.Internal;

[TestFixture]
public class ProjectConfigurationTests
{
IProjectLocator projectLocator;
IProjectProvider projectProvider;
string projectLocation;

[SetUp]
public void Setup()
public ProjectConfigurationTests()
{
projectLocator = Substitute.For<IProjectLocator>();
projectProvider = Substitute.For<IProjectProvider>();
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.Returns(XDocument.Parse(File.ReadAllText(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\SampleApp\SampleApp.csproj")))));
projectLocation = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\SampleApp\SampleApp.csproj"));
}

[Test]
public void debug_configurations_should_have_debug_type_pdb_only()
{
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Debug, "DebugType", "full"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
var configurationHasSpecificValue = new ConfigurationHasSpecificValue(ConfigurationType.Debug, "DebugType", "full");
var projectPropertyGroups = new ProjectPropertyGroups(projectLocation);
Convention.Is(configurationHasSpecificValue, projectPropertyGroups);
}

[Test]
public void debug_configurations_should_have_optimize_false()
{
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Debug, "Optimize", "false"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
var configurationHasSpecificValue = new ConfigurationHasSpecificValue(ConfigurationType.Debug, "Optimize", "false");
var projectPropertyGroups = new ProjectPropertyGroups(projectLocation);
Convention.Is(configurationHasSpecificValue, projectPropertyGroups);
}

[Test]
public void release_configurations_should_have_debug_type_pdb_only()
{
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "DebugType", "pdbonly"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
var configurationHasSpecificValue = new ConfigurationHasSpecificValue(ConfigurationType.Release, "DebugType", "pdbonly");
var projectPropertyGroups = new ProjectPropertyGroups(projectLocation);
Convention.Is(configurationHasSpecificValue, projectPropertyGroups);
}

[Test]
public void release_configurations_should_have_optimize_true()
{
Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "Optimize", "true"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator));
var configurationHasSpecificValue = new ConfigurationHasSpecificValue(ConfigurationType.Release, "Optimize", "true");
var projectPropertyGroups = new ProjectPropertyGroups(projectLocation);
Convention.Is(configurationHasSpecificValue, projectPropertyGroups);
}
}
}
12 changes: 10 additions & 2 deletions Samples/SampleApp.Tests/SqlScriptTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace SampleApp.Tests
{
using System;
using System.IO;
using NUnit.Framework;
using SampleApp.Domain;
using TestStack.ConventionTests;
Expand All @@ -9,11 +11,17 @@
[TestFixture]
public class SqlScriptTests
{
string projectLocation;

public SqlScriptTests()
{
projectLocation = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\SampleApp\SampleApp.csproj"));
}

[Test]
[Explicit] // Only works when shadow copy disabled for tests
public void SqlScriptsShouldBeEmbeddedResources()
{
Convention.Is(new FilesAreEmbeddedResources(".sql"), new ProjectFileItems(typeof(DomainClass).Assembly));
Convention.Is(new FilesAreEmbeddedResources(".sql"), new ProjectFileItems(projectLocation));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public void Setup()
public void can_parse_a_normal_project_file_to_read_global_debug_and_release_property_groups()
{
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.LoadProjectDocument()
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));

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

Assert.That(projectGroups.PropertyGroups.Length, Is.EqualTo(3));
Assert.That(projectGroups.PropertyGroups.Any(item => item.Debug));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'Optimize property in Release|AnyCPU must have a value of true' for 'Project property groups in TestStack.ConventionTests.Tests'
--------------------------------------------------------------------------------------------------------------------------------
'Optimize property in Release|AnyCPU must have a value of true' for 'Project property groups in ProjectName'
------------------------------------------------------------------------------------------------------------

Optimize:false
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
'Platform property in Release|x86 must have a value of AnyCPU' for 'Project property groups in TestStack.ConventionTests.Tests'
-------------------------------------------------------------------------------------------------------------------------------
'Platform property in Global must have a value of AnyCPU' for 'Project property groups in ProjectName'
------------------------------------------------------------------------------------------------------


'Platform property in Release|AnyCPU must have a value of AnyCPU' for 'Project property groups in ProjectName'
--------------------------------------------------------------------------------------------------------------


'Platform property in Release|x86 must have a value of AnyCPU' for 'Project property groups in ProjectName'
-----------------------------------------------------------------------------------------------------------

Platform:x86
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'Project must not reference dlls from bin or obj directories' for 'Project references in TestStack.ConventionTests.Tests'
-------------------------------------------------------------------------------------------------------------------------
'Project must not reference dlls from bin or obj directories' for 'Project references in ProjectName'
-----------------------------------------------------------------------------------------------------

bin\Debug\ApprovalTests.dll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'Project must not reference dlls from bin or obj directories' for 'Project references in TestStack.ConventionTests.Tests'
-------------------------------------------------------------------------------------------------------------------------
'Project must not reference dlls from bin or obj directories' for 'Project references in ProjectName'
-----------------------------------------------------------------------------------------------------

bin\Debug\ApprovalTests.dll
41 changes: 17 additions & 24 deletions TestStack.ConventionTests.Tests/ProjectBasedConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public class ProjectBasedConventions
public void Setup()
{
projectProvider = Substitute.For<IProjectProvider>();
projectProvider.GetName().Returns("ProjectName");
}

[Test]
public void assemblies_referencing_bin_obj()
{
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.LoadProjectDocument()
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));

var projectLocator = Substitute.For<IProjectLocator>();
var project = new ProjectReferences(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);

var project = new ProjectReferences(projectProvider);
var failures = Convention.GetFailures(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project);

failures.ShouldMatchApproved();
Expand All @@ -38,12 +38,10 @@ public void assemblies_referencing_bin_obj()
public void assemblies_referencing_bin_obj_with_approved_exceptions()
{
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.LoadProjectDocument()
.Returns(XDocument.Parse(Resources.ProjectFileWithBinReference));


var projectLocator = Substitute.For<IProjectLocator>();
var project = new ProjectReferences(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
var project = new ProjectReferences(projectProvider);
var failures = Convention.GetFailures(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project);

failures.ShouldMatchApproved();
Expand All @@ -53,11 +51,10 @@ public void assemblies_referencing_bin_obj_with_approved_exceptions()
public void scripts_not_embedded_resources()
{
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.LoadProjectDocument()
.Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile));

var projectLocator = Substitute.For<IProjectLocator>();
var project = new ProjectFileItems(typeof (ProjectBasedConventions).Assembly, projectProvider, projectLocator);

var project = new ProjectFileItems(projectProvider);
var failures = Convention.GetFailures(new FilesAreEmbeddedResources(".sql"), project);

failures.ShouldMatchApproved();
Expand All @@ -66,10 +63,9 @@ public void scripts_not_embedded_resources()
[Test]
public void scripts_not_embedded_resources_with_approved_exceptions()
{
var projectLocator = Substitute.For<IProjectLocator>();
var project = new ProjectFileItems(typeof (ProjectBasedConventions).Assembly, projectProvider, projectLocator);
var project = new ProjectFileItems(projectProvider);
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.LoadProjectDocument()
.Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile));

Convention.GetFailures(new FilesAreEmbeddedResources(".sql"), project);
Expand All @@ -79,11 +75,10 @@ public void scripts_not_embedded_resources_with_approved_exceptions()
public void release_debug_type_should_be_pdb_only()
{
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.LoadProjectDocument()
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));

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

failures.ShouldMatchApproved();
Expand All @@ -93,11 +88,10 @@ public void release_debug_type_should_be_pdb_only()
public void all_configuration_groups_should_have_platform_AnyCPU()
{
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.LoadProjectDocument()
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));

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

failures.ShouldMatchApproved();
Expand All @@ -107,11 +101,10 @@ public void all_configuration_groups_should_have_platform_AnyCPU()
public void all_configuration_groups_should_have_optimize_true_if_property_defined()
{
projectProvider
.LoadProjectDocument(Arg.Any<string>())
.LoadProjectDocument()
.Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull));

var projectLocator = Substitute.For<IProjectLocator>();
var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator);
var propertyGroups = new ProjectPropertyGroups(projectProvider);
var failures =
Convention.GetFailures(new ConfigurationHasSpecificValue(ConfigurationType.All, "Optimize", "true"),
propertyGroups);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'DebugType property in Release|AnyCPU must have a value of pdbonly' for 'Project property groups in TestStack.ConventionTests.Tests'
------------------------------------------------------------------------------------------------------------------------------------
'DebugType property in Release|AnyCPU must have a value of pdbonly' for 'Project property groups in ProjectName'
----------------------------------------------------------------------------------------------------------------

DebugType:full

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

DebugType:full
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'.sql Files must be embedded resources' for 'Project file items in TestStack.ConventionTests.Tests'
---------------------------------------------------------------------------------------------------
'.sql Files must be embedded resources' for 'Project file items in ProjectName'
-------------------------------------------------------------------------------

Scripts\Script2.sql
24 changes: 10 additions & 14 deletions TestStack.ConventionTests/ConventionData/AbstractProjectData.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
namespace TestStack.ConventionTests.ConventionData
{
using System.Reflection;
using System.IO;
using System.Xml.Linq;
using TestStack.ConventionTests.Internal;

public abstract class AbstractProjectData : IConventionData
{
protected AbstractProjectData(Assembly assembly, IProjectProvider projectProvider = null, IProjectLocator projectLocator = null)
protected AbstractProjectData(IProjectProvider projectProvider)
{
Assembly = assembly;
ProjectProvider = projectProvider ?? new ProjectProvider();
ProjectLocator = projectLocator ?? new AssemblyProjectLocator();
ProjectProvider = projectProvider;
}
protected AbstractProjectData(string projectFilePath)
{
ProjectProvider = new ProjectFileFromDiskProvider(projectFilePath);
}

public Assembly Assembly { get; private set; }

public IProjectLocator ProjectLocator { get; private set; }

public IProjectProvider ProjectProvider { get; private set; }

public string Description { get { return Assembly.GetName().Name; } }
public string Description { get { return ProjectProvider.GetName(); } }

public bool HasData { get { return ProjectLocator.ResolveProjectFilePath(Assembly) != null; } }
public bool HasData { get { return true; } }

protected XDocument GetProject()
{
var location = ProjectLocator.ResolveProjectFilePath(Assembly);
var project = ProjectProvider.LoadProjectDocument(location);
return project;
return ProjectProvider.LoadProjectDocument();
}
}
}
9 changes: 6 additions & 3 deletions TestStack.ConventionTests/ConventionData/ProjectFileItems.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace TestStack.ConventionTests.ConventionData
{
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using TestStack.ConventionTests.Internal;

Expand All @@ -10,8 +9,12 @@
/// </summary>
public class ProjectFileItems : AbstractProjectData
{
public ProjectFileItems(Assembly assembly, IProjectProvider projectProvider = null, IProjectLocator projectLocator = null)
: base(assembly, projectProvider, projectLocator)
public ProjectFileItems(IProjectProvider projectProvider)
: base(projectProvider)
{
}

public ProjectFileItems(string projectFilePath) : base(projectFilePath)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
{
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using TestStack.ConventionTests.Internal;

public class ProjectPropertyGroups : AbstractProjectData
{
public ProjectPropertyGroups(Assembly assembly, IProjectProvider projectProvider = null, IProjectLocator projectLocator = null)
: base(assembly, projectProvider, projectLocator)
public ProjectPropertyGroups(IProjectProvider projectProvider)
: base(projectProvider)
{
}
public ProjectPropertyGroups(string projectFileLocation)
: base(projectFileLocation)
{
}

Expand Down
10 changes: 6 additions & 4 deletions TestStack.ConventionTests/ConventionData/ProjectReferences.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
namespace TestStack.ConventionTests.ConventionData
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using TestStack.ConventionTests.Internal;

public class ProjectReferences : AbstractProjectData
{
public ProjectReferences(Assembly assembly, IProjectProvider projectProvider = null, IProjectLocator projectLocator = null)
: base(assembly, projectProvider, projectLocator)
public ProjectReferences(IProjectProvider projectProvider)
: base(projectProvider)
{
}

public ProjectReferences(string projectFilePath) : base(projectFilePath)
{
}

Expand Down
Loading

0 comments on commit 3b2ef28

Please sign in to comment.