diff --git a/.gitignore b/.gitignore index 20ccecc..20aa641 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ _ReSharper.* ConventionTests*.nupkg _NCrunch* *.received.txt -*.orig \ No newline at end of file +*.orig +packages \ No newline at end of file diff --git a/Samples/SampleApp.Tests/ProjectConfigurationTests.cs b/Samples/SampleApp.Tests/ProjectConfigurationTests.cs new file mode 100644 index 0000000..1564718 --- /dev/null +++ b/Samples/SampleApp.Tests/ProjectConfigurationTests.cs @@ -0,0 +1,55 @@ +namespace SampleApp.Tests +{ + 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; + + [SetUp] + public void Setup() + { + projectLocator = Substitute.For(); + projectProvider = Substitute.For(); + projectProvider + .LoadProjectDocument(Arg.Any()) + .Returns(XDocument.Parse(File.ReadAllText(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)); + } + + [Test] + public void debug_configurations_should_have_optimize_false() + { + Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Debug, "Optimize", "false"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator)); + } + + [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)); + } + + [Test] + public void release_configurations_should_have_optimize_true() + { + Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "Optimize", "true"), new ProjectPropertyGroups(typeof(DomainClass).Assembly, projectProvider, projectLocator)); + } + } +} \ No newline at end of file diff --git a/Samples/SampleApp.Tests/SampleApp.Tests.csproj b/Samples/SampleApp.Tests/SampleApp.Tests.csproj index fd7a560..95a3ead 100644 --- a/Samples/SampleApp.Tests/SampleApp.Tests.csproj +++ b/Samples/SampleApp.Tests/SampleApp.Tests.csproj @@ -31,10 +31,30 @@ 4 + + True + ..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + + False + ..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.dll + + + ..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Mdb.dll + + + ..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Pdb.dll + + + ..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Rocks.dll + False ..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll + + ..\..\packages\NSubstitute.1.6.1.0\lib\NET40\NSubstitute.dll + ..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll @@ -49,10 +69,33 @@ ..\..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll + + True + ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll + ..\..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll - + + True + ..\..\packages\Microsoft.AspNet.Mvc.4.0.40804.0\lib\net40\System.Web.Mvc.dll + + + True + ..\..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll + + + True + ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll + + + True + ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll + + + True + ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll + @@ -63,6 +106,7 @@ + diff --git a/Samples/SampleApp.Tests/packages.config b/Samples/SampleApp.Tests/packages.config index 17c4ae1..544b579 100644 --- a/Samples/SampleApp.Tests/packages.config +++ b/Samples/SampleApp.Tests/packages.config @@ -1,8 +1,14 @@  + + + + + + \ No newline at end of file diff --git a/Samples/SampleApp/SampleApp.csproj b/Samples/SampleApp/SampleApp.csproj index 94d4482..8540b3b 100644 --- a/Samples/SampleApp/SampleApp.csproj +++ b/Samples/SampleApp/SampleApp.csproj @@ -31,26 +31,53 @@ 4 + + True + ..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + - ..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll + ..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll - ..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll + ..\..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll - ..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll + ..\..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll - ..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll + ..\..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll + + + True + ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll - ..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll + ..\..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll + + + True + ..\..\packages\Microsoft.AspNet.Mvc.4.0.40804.0\lib\net40\System.Web.Mvc.dll + + + True + ..\..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll + + + True + ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll + + + True + ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll + + + True + ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll - diff --git a/Samples/SampleApp/packages.config b/Samples/SampleApp/packages.config index f59046e..6512b52 100644 --- a/Samples/SampleApp/packages.config +++ b/Samples/SampleApp/packages.config @@ -1,7 +1,11 @@  + + + + \ No newline at end of file diff --git a/TestAssembly/TestAssembly.csproj b/TestAssembly/TestAssembly.csproj index e6a01b8..d88df18 100644 --- a/TestAssembly/TestAssembly.csproj +++ b/TestAssembly/TestAssembly.csproj @@ -49,13 +49,36 @@ ..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll + + True + ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll + ..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll ..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.30506.0\lib\net40\System.Web.Http.WebHost.dll - + + True + ..\packages\Microsoft.AspNet.Mvc.4.0.40804.0\lib\net40\System.Web.Mvc.dll + + + True + ..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll + + + True + ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll + + + True + ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll + + + True + ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll + diff --git a/TestAssembly/packages.config b/TestAssembly/packages.config index ae6ab70..8436107 100644 --- a/TestAssembly/packages.config +++ b/TestAssembly/packages.config @@ -1,9 +1,12 @@  + + + diff --git a/TestStack.ConventionTests.Tests/ConventionData/ProjectPropertyGroupsTests.cs b/TestStack.ConventionTests.Tests/ConventionData/ProjectPropertyGroupsTests.cs new file mode 100644 index 0000000..6843a8d --- /dev/null +++ b/TestStack.ConventionTests.Tests/ConventionData/ProjectPropertyGroupsTests.cs @@ -0,0 +1,37 @@ +namespace TestStack.ConventionTests.Tests.ConventionData +{ + using System.Linq; + using System.Xml.Linq; + using NSubstitute; + using NUnit.Framework; + using TestStack.ConventionTests.ConventionData; + using TestStack.ConventionTests.Internal; + using TestStack.ConventionTests.Tests.Properties; + + [TestFixture] + public class ProjectPropertyGroupsTests + { + IProjectProvider projectProvider; + + [SetUp] + public void Setup() + { + projectProvider = Substitute.For(); + } + + [Test] + public void can_parse_a_normal_project_file_to_read_global_debug_and_release_property_groups() + { + projectProvider + .LoadProjectDocument(Arg.Any()) + .Returns(XDocument.Parse(Resources.ProjectFileWithBinReference)); + + var projectGroups = new ProjectPropertyGroups(typeof(ProjectPropertyGroups).Assembly, projectProvider, Substitute.For()); + + Assert.That(projectGroups.PropertyGroups.Length, Is.EqualTo(3)); + Assert.That(projectGroups.PropertyGroups.Any(item => item.Debug)); + Assert.That(projectGroups.PropertyGroups.Any(item => item.Release)); + Assert.That(projectGroups.PropertyGroups.Any(item => item.Global)); + } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.all_configuration_groups_should_have_optimize_true_if_property_defined.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.all_configuration_groups_should_have_optimize_true_if_property_defined.approved.txt new file mode 100644 index 0000000..183a444 --- /dev/null +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.all_configuration_groups_should_have_optimize_true_if_property_defined.approved.txt @@ -0,0 +1,4 @@ +'Optimize property in Release|AnyCPU must have a value of true' for 'Project property groups in TestStack.ConventionTests.Tests' +-------------------------------------------------------------------------------------------------------------------------------- + + Optimize:false diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.all_configuration_groups_should_have_platform_AnyCPU.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.all_configuration_groups_should_have_platform_AnyCPU.approved.txt new file mode 100644 index 0000000..f8ebe7a --- /dev/null +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.all_configuration_groups_should_have_platform_AnyCPU.approved.txt @@ -0,0 +1,4 @@ +'Platform property in Release|x86 must have a value of AnyCPU' for 'Project property groups in TestStack.ConventionTests.Tests' +------------------------------------------------------------------------------------------------------------------------------- + + Platform:x86 diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs b/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs index 8775ee9..b2734fd 100644 --- a/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs @@ -74,5 +74,53 @@ public void scripts_not_embedded_resources_with_approved_exceptions() Convention.IsWithApprovedExeptions(new FilesAreEmbeddedResources(".sql"), project); } + + [Test] + public void release_debug_type_should_be_pdb_only() + { + projectProvider + .LoadProjectDocument(Arg.Any()) + .Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull)); + + var projectLocator = Substitute.For(); + var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator); + var ex = + Assert.Throws( + () => Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.Release, "DebugType", "pdbonly"), propertyGroups)); + + Approvals.Verify(ex.Message); + } + + [Test] + public void all_configuration_groups_should_have_platform_AnyCPU() + { + projectProvider + .LoadProjectDocument(Arg.Any()) + .Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull)); + + var projectLocator = Substitute.For(); + var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator); + var ex = + Assert.Throws( + () => Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.All, "Platform", "AnyCPU"), propertyGroups)); + + Approvals.Verify(ex.Message); + } + + [Test] + public void all_configuration_groups_should_have_optimize_true_if_property_defined() + { + projectProvider + .LoadProjectDocument(Arg.Any()) + .Returns(XDocument.Parse(Resources.ProjectFileWithReleaseDebugTypeFull)); + + var projectLocator = Substitute.For(); + var propertyGroups = new ProjectPropertyGroups(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator); + var ex = + Assert.Throws( + () => Convention.Is(new ConfigurationHasSpecificValue(ConfigurationType.All, "Optimize", "true"), propertyGroups)); + + Approvals.Verify(ex.Message); + } } } \ No newline at end of file diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.release_debug_type_should_be_pdb_only.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.release_debug_type_should_be_pdb_only.approved.txt new file mode 100644 index 0000000..525c95e --- /dev/null +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.release_debug_type_should_be_pdb_only.approved.txt @@ -0,0 +1,9 @@ +'DebugType property in Release|AnyCPU must have a value of pdbonly' for 'Project property groups in TestStack.ConventionTests.Tests' +------------------------------------------------------------------------------------------------------------------------------------ + + DebugType:full + +'DebugType property in Release|x86 must have a value of pdbonly' for 'Project property groups in TestStack.ConventionTests.Tests' +--------------------------------------------------------------------------------------------------------------------------------- + + DebugType:full diff --git a/TestStack.ConventionTests.Tests/Properties/Resources.Designer.cs b/TestStack.ConventionTests.Tests/Properties/Resources.Designer.cs index 37c497c..625521b 100644 --- a/TestStack.ConventionTests.Tests/Properties/Resources.Designer.cs +++ b/TestStack.ConventionTests.Tests/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.32559 +// Runtime Version:4.0.30319.34014 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -94,5 +94,19 @@ internal static string ProjectFileWithInvalidSqlScriptFile { return ResourceManager.GetString("ProjectFileWithInvalidSqlScriptFile", resourceCulture); } } + + /// + /// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8"?> + ///<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + /// <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + /// <DebugType>full</DebugType> + /// </PropertyGroup> + ///</Project>. + /// + internal static string ProjectFileWithReleaseDebugTypeFull { + get { + return ResourceManager.GetString("ProjectFileWithReleaseDebugTypeFull", resourceCulture); + } + } } } diff --git a/TestStack.ConventionTests.Tests/Properties/Resources.resx b/TestStack.ConventionTests.Tests/Properties/Resources.resx index 74f2e24..1f3e8ab 100644 --- a/TestStack.ConventionTests.Tests/Properties/Resources.resx +++ b/TestStack.ConventionTests.Tests/Properties/Resources.resx @@ -124,4 +124,7 @@ ..\Resources\ProjectFileWithInvalidSqlScriptFile.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + ..\resources\projectfilewithreleasedebugtypefull.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + \ No newline at end of file diff --git a/TestStack.ConventionTests.Tests/Resources/ProjectFileWithReleaseDebugTypeFull.txt b/TestStack.ConventionTests.Tests/Resources/ProjectFileWithReleaseDebugTypeFull.txt new file mode 100644 index 0000000..126a645 --- /dev/null +++ b/TestStack.ConventionTests.Tests/Resources/ProjectFileWithReleaseDebugTypeFull.txt @@ -0,0 +1,15 @@ + + + + AnyCPU + + + AnyCPU + full + false + + + x86 + full + + \ No newline at end of file diff --git a/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj b/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj index 09a9d04..fd63170 100644 --- a/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj +++ b/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj @@ -62,6 +62,7 @@ + @@ -104,6 +105,9 @@ + + +