diff --git a/.gitattributes b/.gitattributes index fdfb52a..d83c924 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ ### Check me into the root of the repo ### as .gitattributes +*.approved.* binary *.doc diff=astextplain *.DOC diff=astextplain diff --git a/.gitignore b/.gitignore index 61b885c..28cbc70 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,5 @@ _ReSharper.* *.suo *.crunchproject.local.xml *.crunchsolution.local.xml -*.ncrunchsolution -*.ncrunchproject + +packages/ \ No newline at end of file diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config new file mode 100644 index 0000000..67f8ea0 --- /dev/null +++ b/.nuget/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets new file mode 100644 index 0000000..46a1b6c --- /dev/null +++ b/.nuget/NuGet.targets @@ -0,0 +1,133 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + false + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) + + + + + $(SolutionDir).nuget + packages.config + + + + + $(NuGetToolsPath)\NuGet.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 $(NuGetExePath) + + $(TargetDir.Trim('\\')) + + -RequireConsent + -NonInteractive + + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) " + $(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AssemblyUnderTest/AssemblyUnderTest.csproj b/AssemblyUnderTest/AssemblyUnderTest.csproj new file mode 100644 index 0000000..391944e --- /dev/null +++ b/AssemblyUnderTest/AssemblyUnderTest.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {1603A139-C9DB-4836-A36D-25A0F4591AED} + Library + Properties + AssemblyUnderTest + AssemblyUnderTest + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AssemblyUnderTest/ClassWithNoDefaultCtor.cs b/AssemblyUnderTest/ClassWithNoDefaultCtor.cs new file mode 100644 index 0000000..ea29457 --- /dev/null +++ b/AssemblyUnderTest/ClassWithNoDefaultCtor.cs @@ -0,0 +1,7 @@ +namespace AssemblyUnderTest +{ + public class ClassWithNoDefaultCtor + { + public ClassWithNoDefaultCtor(string foo) { } + } +} \ No newline at end of file diff --git a/AssemblyUnderTest/ClassWithPrivateDefaultCtor.cs b/AssemblyUnderTest/ClassWithPrivateDefaultCtor.cs new file mode 100644 index 0000000..069aa6e --- /dev/null +++ b/AssemblyUnderTest/ClassWithPrivateDefaultCtor.cs @@ -0,0 +1,7 @@ +namespace AssemblyUnderTest +{ + public class ClassWithPrivateDefaultCtor + { + private ClassWithPrivateDefaultCtor() { } + } +} \ No newline at end of file diff --git a/AssemblyUnderTest/ClassWithProtectedDefaultCtor.cs b/AssemblyUnderTest/ClassWithProtectedDefaultCtor.cs new file mode 100644 index 0000000..7ed6110 --- /dev/null +++ b/AssemblyUnderTest/ClassWithProtectedDefaultCtor.cs @@ -0,0 +1,7 @@ +namespace AssemblyUnderTest +{ + public class ClassWithProtectedDefaultCtor + { + protected ClassWithProtectedDefaultCtor(){} + } +} \ No newline at end of file diff --git a/AssemblyUnderTest/ClassWithPublicDefaultCtor.cs b/AssemblyUnderTest/ClassWithPublicDefaultCtor.cs new file mode 100644 index 0000000..06da90c --- /dev/null +++ b/AssemblyUnderTest/ClassWithPublicDefaultCtor.cs @@ -0,0 +1,7 @@ +namespace AssemblyUnderTest +{ + public class ClassWithPublicDefaultCtor + { + public ClassWithPublicDefaultCtor() { } + } +} \ No newline at end of file diff --git a/AssemblyUnderTest/Properties/AssemblyInfo.cs b/AssemblyUnderTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..87525b1 --- /dev/null +++ b/AssemblyUnderTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("AssemblyUnderTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AssemblyUnderTest")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("57cd6073-8a60-47e8-bff1-99e67a4a4c0f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AssemblyUnderTest/SampleDomainClass.cs b/AssemblyUnderTest/SampleDomainClass.cs new file mode 100644 index 0000000..d0c9aaa --- /dev/null +++ b/AssemblyUnderTest/SampleDomainClass.cs @@ -0,0 +1,8 @@ +namespace AssemblyUnderTest +{ + public class SampleDomainClass + { + public void TestNonVirtual() { } + public virtual void Virtual() { } + } +} \ No newline at end of file diff --git a/ConventionTests.Framework/ConventionTests.Framework.csproj b/ConventionTests.Framework/ConventionTests.Framework.csproj new file mode 100644 index 0000000..f026f7f --- /dev/null +++ b/ConventionTests.Framework/ConventionTests.Framework.csproj @@ -0,0 +1,108 @@ + + + + + Debug + AnyCPU + {50A4FB13-241B-4FCE-B4B2-AD35D4F83297} + Library + Properties + ConventionTests + ConventionTests.Framework + v4.0 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\ApprovalTests.3.0.01\lib\net40\ApprovalTests.dll + + + ..\packages\ApprovalUtilities.3.0.01\lib\net35\ApprovalUtilities.dll + + + ..\packages\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll + + + ..\packages\Castle.Windsor.3.2.1\lib\net40\Castle.Windsor.dll + + + ..\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 + + + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {1E12EA0C-9182-4029-991A-B0B9D38F5783} + ConventionTests + + + + + Designer + + + + + + + \ No newline at end of file diff --git a/ConventionTests/ConventionTests.NUnit.nuspec b/ConventionTests.Framework/ConventionTests.NUnit.nuspec similarity index 88% rename from ConventionTests/ConventionTests.NUnit.nuspec rename to ConventionTests.Framework/ConventionTests.NUnit.nuspec index aa1564c..75e1370 100644 --- a/ConventionTests/ConventionTests.NUnit.nuspec +++ b/ConventionTests.Framework/ConventionTests.NUnit.nuspec @@ -1,18 +1,18 @@ - - - - 1.0.4 - Krzysztof Kozmic - Krzysztof Kozmic - - - - - - ConventionTests - ConventionTests - false - Simple convention-tester - Simple code-only package offering some structure to tests validating conventions. - + + + + 1.0.4 + Krzysztof Kozmic + Krzysztof Kozmic + + + + + + ConventionTests.Framework + ConventionTests.Framework + false + Simple convention-tester + Simple code-only package offering some structure to tests validating conventions. + \ No newline at end of file diff --git a/ConventionTests/Conventions/Internal/AssemblyProjectLocator.cs b/ConventionTests.Framework/Conventions/Internal/AssemblyProjectLocator.cs similarity index 100% rename from ConventionTests/Conventions/Internal/AssemblyProjectLocator.cs rename to ConventionTests.Framework/Conventions/Internal/AssemblyProjectLocator.cs diff --git a/ConventionTests.Framework/Conventions/Internal/ConventionReflectionExtensions.cs b/ConventionTests.Framework/Conventions/Internal/ConventionReflectionExtensions.cs new file mode 100644 index 0000000..884ccce --- /dev/null +++ b/ConventionTests.Framework/Conventions/Internal/ConventionReflectionExtensions.cs @@ -0,0 +1,33 @@ +namespace ConventionTests +{ + using System; + using System.Linq; + using System.Reflection; + + public static class ConventionReflectionExtensions + { + public static IConventionTest[] GetAllConventions(Assembly assembly) + { + var conventionTypes = GetConventionTypes(); + return Array.ConvertAll(conventionTypes, CreateConvention); + } + + static bool IsConventionTest(Type type) + { + return type.IsClass && type.IsAbstract == false && typeof(IConventionTest).IsAssignableFrom(type); + } + + static IConventionTest CreateConvention(Type t) + { + return (IConventionTest)Activator.CreateInstance(t); + } + + static Type[] GetConventionTypes() + { + var types = + Assembly.GetExecutingAssembly().GetExportedTypes().Where( + IsConventionTest).ToArray(); + return types; + } + } +} \ No newline at end of file diff --git a/ConventionTests/Conventions/Internal/ConventionTest.Generic.cs b/ConventionTests.Framework/Conventions/Internal/ConventionTest.Generic.cs similarity index 100% rename from ConventionTests/Conventions/Internal/ConventionTest.Generic.cs rename to ConventionTests.Framework/Conventions/Internal/ConventionTest.Generic.cs diff --git a/ConventionTests/Conventions/Internal/ConventionTest.cs b/ConventionTests.Framework/Conventions/Internal/ConventionTest.cs similarity index 100% rename from ConventionTests/Conventions/Internal/ConventionTest.cs rename to ConventionTests.Framework/Conventions/Internal/ConventionTest.cs diff --git a/ConventionTests/Conventions/Internal/ConventionTestBase.cs b/ConventionTests.Framework/Conventions/Internal/ConventionTestBase.cs similarity index 100% rename from ConventionTests/Conventions/Internal/ConventionTestBase.cs rename to ConventionTests.Framework/Conventions/Internal/ConventionTestBase.cs diff --git a/ConventionTests/Conventions/Internal/ConventionTestNamer.cs b/ConventionTests.Framework/Conventions/Internal/ConventionTestNamer.cs similarity index 100% rename from ConventionTests/Conventions/Internal/ConventionTestNamer.cs rename to ConventionTests.Framework/Conventions/Internal/ConventionTestNamer.cs diff --git a/ConventionTests/Conventions/Internal/IAssert.cs b/ConventionTests.Framework/Conventions/Internal/IAssert.cs similarity index 100% rename from ConventionTests/Conventions/Internal/IAssert.cs rename to ConventionTests.Framework/Conventions/Internal/IAssert.cs diff --git a/ConventionTests/Conventions/Internal/IConventionTest.cs b/ConventionTests.Framework/Conventions/Internal/IConventionTest.cs similarity index 100% rename from ConventionTests/Conventions/Internal/IConventionTest.cs rename to ConventionTests.Framework/Conventions/Internal/IConventionTest.cs diff --git a/ConventionTests/Conventions/Internal/IProjectLocator.cs b/ConventionTests.Framework/Conventions/Internal/IProjectLocator.cs similarity index 100% rename from ConventionTests/Conventions/Internal/IProjectLocator.cs rename to ConventionTests.Framework/Conventions/Internal/IProjectLocator.cs diff --git a/ConventionTests/Conventions/Internal/ProjectConventionData.cs b/ConventionTests.Framework/Conventions/Internal/ProjectConventionData.cs similarity index 100% rename from ConventionTests/Conventions/Internal/ProjectConventionData.cs rename to ConventionTests.Framework/Conventions/Internal/ProjectConventionData.cs diff --git a/ConventionTests/Conventions/Internal/ProjectConvetionTest.cs b/ConventionTests.Framework/Conventions/Internal/ProjectConvetionTest.cs similarity index 100% rename from ConventionTests/Conventions/Internal/ProjectConvetionTest.cs rename to ConventionTests.Framework/Conventions/Internal/ProjectConvetionTest.cs diff --git a/ConventionTests/Conventions/Internal/WindsorConventionData.cs b/ConventionTests.Framework/Conventions/Internal/WindsorConventionData.cs similarity index 100% rename from ConventionTests/Conventions/Internal/WindsorConventionData.cs rename to ConventionTests.Framework/Conventions/Internal/WindsorConventionData.cs diff --git a/ConventionTests/Conventions/Internal/WindsorConventionTest.cs b/ConventionTests.Framework/Conventions/Internal/WindsorConventionTest.cs similarity index 100% rename from ConventionTests/Conventions/Internal/WindsorConventionTest.cs rename to ConventionTests.Framework/Conventions/Internal/WindsorConventionTest.cs diff --git a/ConventionTests/Conventions/__Run.cs b/ConventionTests.Framework/Conventions/__Run.cs similarity index 88% rename from ConventionTests/Conventions/__Run.cs rename to ConventionTests.Framework/Conventions/__Run.cs index 1ca16af..0b917c2 100644 --- a/ConventionTests/Conventions/__Run.cs +++ b/ConventionTests.Framework/Conventions/__Run.cs @@ -22,7 +22,7 @@ public TestCaseData[] Conventions [MethodImpl(MethodImplOptions.NoInlining)] get { - var conventions = ReflectionExtensions.GetAllConventions(Assembly.GetExecutingAssembly()); + var conventions = ConventionReflectionExtensions.GetAllConventions(Assembly.GetExecutingAssembly()); var tests = Array.ConvertAll(conventions, BuildTestData); return tests; } diff --git a/ConventionTests.Framework/Properties/AssemblyInfo.cs b/ConventionTests.Framework/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d27125f --- /dev/null +++ b/ConventionTests.Framework/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConventionTests.Framework")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConventionTests.Framework")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("6c6091a8-45d6-4cd6-9d9d-2824b8d4e739")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ConventionTests/packages.config b/ConventionTests.Framework/packages.config similarity index 56% rename from ConventionTests/packages.config rename to ConventionTests.Framework/packages.config index 7cd9237..77ebe4a 100644 --- a/ConventionTests/packages.config +++ b/ConventionTests.Framework/packages.config @@ -1,8 +1,9 @@ - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/ConventionTests.Tests/ConventionTests.Tests.csproj b/ConventionTests.Tests/ConventionTests.Tests.csproj new file mode 100644 index 0000000..52d30ac --- /dev/null +++ b/ConventionTests.Tests/ConventionTests.Tests.csproj @@ -0,0 +1,78 @@ + + + + + Debug + AnyCPU + {AC81D49C-FB62-484E-8A6B-6A16F5E3D3A0} + Library + Properties + ConventionTests.Tests + ConventionTests.Tests + v4.0 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\ApprovalTests.3.0.01\lib\net40\ApprovalTests.dll + + + ..\packages\ApprovalUtilities.3.0.01\lib\net35\ApprovalUtilities.dll + + + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + + + + + + + + + + + + + + + + + + + {1603A139-C9DB-4836-A36D-25A0F4591AED} + AssemblyUnderTest + + + {1E12EA0C-9182-4029-991A-B0B9D38F5783} + ConventionTests + + + + + + \ No newline at end of file diff --git a/ConventionTests.Tests/DefaultConventionTests.all_classes_have_default_constructor.approved.txt b/ConventionTests.Tests/DefaultConventionTests.all_classes_have_default_constructor.approved.txt new file mode 100644 index 0000000..8f3f291 --- /dev/null +++ b/ConventionTests.Tests/DefaultConventionTests.all_classes_have_default_constructor.approved.txt @@ -0,0 +1,3 @@ +Convention has failing items + AssemblyUnderTest.ClassWithNoDefaultCtor does not have a default constructor + AssemblyUnderTest.ClassWithPrivateDefaultCtor does not have a default constructor diff --git a/ConventionTests.Tests/DefaultConventionTests.all_methods_are_virtual.approved.txt b/ConventionTests.Tests/DefaultConventionTests.all_methods_are_virtual.approved.txt new file mode 100644 index 0000000..8422815 --- /dev/null +++ b/ConventionTests.Tests/DefaultConventionTests.all_methods_are_virtual.approved.txt @@ -0,0 +1,3 @@ +Convention has failing items + AssemblyUnderTest.SampleDomainClass has non virtual method(s): + TestNonVirtual diff --git a/ConventionTests.Tests/DefaultConventionTests.cs b/ConventionTests.Tests/DefaultConventionTests.cs new file mode 100644 index 0000000..e43f0e7 --- /dev/null +++ b/ConventionTests.Tests/DefaultConventionTests.cs @@ -0,0 +1,39 @@ +namespace ConventionTests.Tests +{ + using System; + using ApprovalTests; + using ApprovalTests.Reporters; + using AssemblyUnderTest; + using NUnit.Framework; + + [TestFixture] + [UseReporter(typeof(DiffReporter))] + public class DefaultConventionTests + { + Type[] sourceTypes; + + [SetUp] + public void Setup() + { + sourceTypes = typeof(SampleDomainClass).Assembly.GetTypes(); + } + + [Test] + public void all_methods_are_virtual() + { + var virtualConvention = new AllMethodsAreVirtualConvention(sourceTypes); + + var exception = Assert.Throws(virtualConvention.AssertConvention); + Approvals.Verify(exception.Message); + } + + [Test] + public void all_classes_have_default_constructor() + { + var constructorConvention = new ClassHasDefaultConstructorConvention(sourceTypes); + + var exception = Assert.Throws(constructorConvention.AssertConvention); + Approvals.Verify(exception.Message); + } + } +} diff --git a/ConventionTests.Tests/Properties/AssemblyInfo.cs b/ConventionTests.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..471d7a8 --- /dev/null +++ b/ConventionTests.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConventionTests.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConventionTests.Tests")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ac95d5d1-3d90-4cf6-8898-0812670811cb")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ConventionTests.Tests/packages.config b/ConventionTests.Tests/packages.config new file mode 100644 index 0000000..aebf213 --- /dev/null +++ b/ConventionTests.Tests/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ConventionTests.sln b/ConventionTests.sln index 4c3ed0b..15719ed 100644 --- a/ConventionTests.sln +++ b/ConventionTests.sln @@ -1,8 +1,26 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConventionTests", "ConventionTests\ConventionTests.csproj", "{1E12EA0C-9182-4029-991A-B0B9D38F5783}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssemblyUnderTest", "AssemblyUnderTest\AssemblyUnderTest.csproj", "{1603A139-C9DB-4836-A36D-25A0F4591AED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConventionTests.Framework", "ConventionTests.Framework\ConventionTests.Framework.csproj", "{50A4FB13-241B-4FCE-B4B2-AD35D4F83297}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6E65C50D-660A-46BE-9869-92AA0C0313C6}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{27E5B6F6-082C-4564-B54B-937222B4820D}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConventionTests.Tests", "ConventionTests.Tests\ConventionTests.Tests.csproj", "{AC81D49C-FB62-484E-8A6B-6A16F5E3D3A0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -13,6 +31,18 @@ Global {1E12EA0C-9182-4029-991A-B0B9D38F5783}.Debug|Any CPU.Build.0 = Debug|Any CPU {1E12EA0C-9182-4029-991A-B0B9D38F5783}.Release|Any CPU.ActiveCfg = Release|Any CPU {1E12EA0C-9182-4029-991A-B0B9D38F5783}.Release|Any CPU.Build.0 = Release|Any CPU + {1603A139-C9DB-4836-A36D-25A0F4591AED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1603A139-C9DB-4836-A36D-25A0F4591AED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1603A139-C9DB-4836-A36D-25A0F4591AED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1603A139-C9DB-4836-A36D-25A0F4591AED}.Release|Any CPU.Build.0 = Release|Any CPU + {50A4FB13-241B-4FCE-B4B2-AD35D4F83297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50A4FB13-241B-4FCE-B4B2-AD35D4F83297}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50A4FB13-241B-4FCE-B4B2-AD35D4F83297}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50A4FB13-241B-4FCE-B4B2-AD35D4F83297}.Release|Any CPU.Build.0 = Release|Any CPU + {AC81D49C-FB62-484E-8A6B-6A16F5E3D3A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC81D49C-FB62-484E-8A6B-6A16F5E3D3A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC81D49C-FB62-484E-8A6B-6A16F5E3D3A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC81D49C-FB62-484E-8A6B-6A16F5E3D3A0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ConventionTests/Conventions/Internal/ConventionData.Generic.cs b/ConventionTests/ConventionData.Generic.cs similarity index 100% rename from ConventionTests/Conventions/Internal/ConventionData.Generic.cs rename to ConventionTests/ConventionData.Generic.cs diff --git a/ConventionTests/Conventions/Internal/ConventionData.cs b/ConventionTests/ConventionData.cs similarity index 77% rename from ConventionTests/Conventions/Internal/ConventionData.cs rename to ConventionTests/ConventionData.cs index bf84777..f73946e 100644 --- a/ConventionTests/Conventions/Internal/ConventionData.cs +++ b/ConventionTests/ConventionData.cs @@ -1,6 +1,7 @@ namespace ConventionTests { using System; + using System.Linq; using System.Reflection; using System.Text; @@ -82,5 +83,30 @@ public ConventionData WithApprovedExceptions(string explanation = null) HasApprovedExceptions = true; return this; } + + public void AssertConvention() + { + var results = ConventionFailureSummary(); + if (!string.IsNullOrEmpty(results)) + { + throw new ConventionFailedException(results); + } + } + + public string ConventionFailureSummary() + { + //TODO Support WithApprovedExecptions? + var message = new StringBuilder(); + var invalidItems = SourceTypes.Where(i => !Must(i)).ToArray(); + + message.AppendLine(Description ?? "Convention has failing items"); + foreach (var invalidType in invalidItems) + { + message.Append('\t'); + ItemDescription(invalidType, message); + } + + return message.ToString(); + } } } \ No newline at end of file diff --git a/ConventionTests/ConventionFailedException.cs b/ConventionTests/ConventionFailedException.cs new file mode 100644 index 0000000..e230f77 --- /dev/null +++ b/ConventionTests/ConventionFailedException.cs @@ -0,0 +1,15 @@ +namespace ConventionTests +{ + using System; + using System.Runtime.Serialization; + + [Serializable] + public class ConventionFailedException : Exception + { + public ConventionFailedException() { } + public ConventionFailedException(string message) : base(message) { } + public ConventionFailedException(string message, Exception inner) : base(message, inner) { } + protected ConventionFailedException(SerializationInfo info, StreamingContext context) + : base(info, context) { } + } +} \ No newline at end of file diff --git a/ConventionTests/ConventionTests.csproj b/ConventionTests/ConventionTests.csproj index 740a1cf..3c2b43e 100644 --- a/ConventionTests/ConventionTests.csproj +++ b/ConventionTests/ConventionTests.csproj @@ -31,39 +31,7 @@ 4 - - False - ..\packages\ApprovalTests.2.2\lib\ApprovalTests.dll - - - False - ..\packages\ApprovalTests.2.2\lib\ApprovalUtilities.dll - - - False - ..\packages\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll - - - False - ..\packages\Castle.Windsor.3.2.0\lib\net40\Castle.Windsor.dll - - - ..\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\NUnit.2.6.2\lib\nunit.framework.dll - @@ -73,29 +41,21 @@ - - - - - - - - - - - - - - - - + + + + + + + + + - + Designer -