From 5843c80b28be45bf024d030d6a879d46aa2155c5 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozmic Date: Tue, 30 Jul 2013 18:12:14 +1000 Subject: [PATCH 1/4] another iteration of API experiments This relates to issue #9, also see discussion under pull request #12 and #11 --- .../TypeBasedConventions.cs | 29 ++++++----- TestStack.ConventionTests/Convention.cs | 36 +++++++++++++ TestStack.ConventionTests/ConventionData.cs | 11 ---- .../AllClassesHaveDefaultConstructor.cs | 28 +++++++++-- .../Conventions/AllMethodsAreVirtual.cs | 45 +++++++++++++---- TestStack.ConventionTests/IConvention.cs | 9 ++++ .../Internal/ConventionResult.cs | 50 +++++++++++++++++++ .../TestStack.ConventionTests.csproj | 10 +++- TestStack.ConventionTests/Types.cs | 16 ++++++ TestStack.ConventionTests/packages.config | 2 + 10 files changed, 196 insertions(+), 40 deletions(-) delete mode 100644 TestStack.ConventionTests/ConventionData.cs create mode 100644 TestStack.ConventionTests/IConvention.cs create mode 100644 TestStack.ConventionTests/Internal/ConventionResult.cs create mode 100644 TestStack.ConventionTests/Types.cs diff --git a/TestStack.ConventionTests.Tests/TypeBasedConventions.cs b/TestStack.ConventionTests.Tests/TypeBasedConventions.cs index d870e34..e5a2faa 100644 --- a/TestStack.ConventionTests.Tests/TypeBasedConventions.cs +++ b/TestStack.ConventionTests.Tests/TypeBasedConventions.cs @@ -1,37 +1,40 @@ namespace TestStack.ConventionTests.Tests { - using System; - using ApprovalTests; using ApprovalTests.Reporters; using NUnit.Framework; using TestAssembly; using TestStack.ConventionTests.Conventions; [TestFixture] - [UseReporter(typeof(DiffReporter))] + [UseReporter(typeof (DiffReporter))] public class TypeBasedConventions { - readonly Type[] itemsToVerify; + readonly Types nhibernateEntities; public TypeBasedConventions() { - itemsToVerify = typeof(SampleDomainClass).Assembly.GetTypes(); + // TODO: This should go to some sort of autodiscovery mechanism so users don't have to see this shit + Convention.Settings.AssertInclunclusive = Assert.Inconclusive; + Convention.Settings.AssertZero = (v, m) => Assert.AreEqual(0, v, m); + + var itemsToVerify = typeof (SampleDomainClass).Assembly.GetTypes(); + nhibernateEntities = new Types + { + ApplicableTypes = itemsToVerify, + HasApprovedExceptions = false + }; } [Test] - public void all_methods_are_virtual() + public void all_classes_have_default_constructor() { - var exception = Assert.Throws(() => Convention.Is(itemsToVerify)); - - Approvals.Verify(exception.Message); + Convention.Is(new AllClassesHaveDefaultConstructor(), nhibernateEntities); } [Test] - public void all_classes_have_default_constructor() + public void all_methods_are_virtual() { - var exception = Assert.Throws(() => Convention.Is(itemsToVerify)); - - Approvals.Verify(exception.Message); + Convention.Is(new AllMethodsAreVirtual(), nhibernateEntities); } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Convention.cs b/TestStack.ConventionTests/Convention.cs index 58ab14a..4744615 100644 --- a/TestStack.ConventionTests/Convention.cs +++ b/TestStack.ConventionTests/Convention.cs @@ -5,9 +5,33 @@ using System.Linq; using System.Reflection; using System.Text; + using ApprovalTests; public static class Convention { + public static readonly ConventionSettings Settings = new ConventionSettings(); + + public static void Is(IConvention convention, TData data) + { + var result = convention.Execute(data); + if (result.IsConclusive == false) + { + Settings.AssertInclunclusive(result.Message); + } + else + { + if (result.HasExceptions) + { + // should we encapsulate Approvals behind Settings? + Approvals.Verify(result.Message); + } + else + { + Settings.AssertZero(result.InvalidResultsCount, result.Message); + } + } + } + public static void Is(IEnumerable itemsToVerify) where T : ConventionData, new() { Is(new T(), itemsToVerify); @@ -95,4 +119,16 @@ public static string Result(TConvention convention, IEnum return Result(convention, itemsToVerify); } } + + public class ConventionSettings + { + public ConventionSettings() + { + // TODO: initialize the type; + } + + public Action AssertInclunclusive; + + public Action AssertZero; + } } \ No newline at end of file diff --git a/TestStack.ConventionTests/ConventionData.cs b/TestStack.ConventionTests/ConventionData.cs deleted file mode 100644 index 95e5aba..0000000 --- a/TestStack.ConventionTests/ConventionData.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace TestStack.ConventionTests -{ - using System; - - /// - /// This is where we set what our convention is all about - /// - public class ConventionData : ConventionData - { - } -} \ No newline at end of file diff --git a/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs b/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs index 4b754ac..4e568f5 100644 --- a/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs +++ b/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs @@ -1,14 +1,34 @@ namespace TestStack.ConventionTests.Conventions { + using System.Linq; using TestStack.ConventionTests.Helpers; + using TestStack.ConventionTests.Internal; - public class AllClassesHaveDefaultConstructor : ConventionData + public class AllClassesHaveDefaultConstructor : IConvention { + public string HeaderMessage { get; set; } + public AllClassesHaveDefaultConstructor() { - Must = type => type.HasDefaultConstructor(); - ItemDescription = (type, builder) => - builder.AppendLine(string.Format("{0} does not have a default constructor", type.FullName)); + HeaderMessage = "The following types do not have default constructor"; + } + + public ConventionResult Execute(Types data) + { + var types = data.ApplicableTypes; + if (types.None()) + { + return ConventionResult.Inconclusive("Put sensible 'inconclusive' message here"); + } + // NOTE: thie bit above is duplicated in both conventions we have, and will likely be duplicated in any other. + // we likely will want to pull that out, leaving perhaps a property like InconclusiveMessage + + var invalid = types.Where(t => t.HasDefaultConstructor() == false); + var result = ConventionResult.For(invalid, HeaderMessage, (t, m) => m.AppendLine("\t" + t)); + + //if we switch conventionData to have an interface and put HasApprovedExceptions on it, we'll be able to pull this out as well. + result.HasExceptions = data.HasApprovedExceptions; + return result; } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs b/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs index b1f2268..03b4d9f 100644 --- a/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs +++ b/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs @@ -1,23 +1,46 @@ namespace TestStack.ConventionTests.Conventions { + using System; + using System.Collections.Generic; using System.Linq; + using System.Reflection; + using System.Text; using TestStack.ConventionTests.Helpers; + using TestStack.ConventionTests.Internal; - public class AllMethodsAreVirtual : ConventionData + public class AllMethodsAreVirtual : IConvention { public AllMethodsAreVirtual() { - Must = t => t.NonVirtualMethods().None(); - ItemDescription = (type, builder) => + HeaderMessage = "The following methods are not virtual."; + } + + public ConventionResult Execute(Types data) + { + var types = data.ApplicableTypes; + if (types.None()) { - builder.Append(type.FullName); - builder.AppendLine(" has non virtual method(s):"); - foreach (var nonVirtual in type.NonVirtualMethods()) - { - builder.Append('\t'); - builder.AppendLine(nonVirtual.Name); - } - }; + return ConventionResult.Inconclusive("Put sensible 'inconclusive' message here"); + } + + // do we want to encapsulate that in some way? + // also notice how data gives us types, yet the convention acts upon methods. + var invalid = types.ToLookup(t => t, t => t.NonVirtualMethods()).Where(l => l.Any()); + var result = ConventionResult.For(invalid, HeaderMessage, DescribeTypeAndMethods); + result.HasExceptions = data.HasApprovedExceptions; + return result; } + + // I like how that's encapsulated in the reusable convention type, whereas previously it was part of the convention/test code + void DescribeTypeAndMethods(IGrouping> item, StringBuilder message) + { + message.AppendLine("\t" + item.Key); + foreach (var method in item) + { + message.AppendLine("\t\t" + method); + } + } + + public string HeaderMessage { get; set; } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/IConvention.cs b/TestStack.ConventionTests/IConvention.cs new file mode 100644 index 0000000..7ee1c33 --- /dev/null +++ b/TestStack.ConventionTests/IConvention.cs @@ -0,0 +1,9 @@ +namespace TestStack.ConventionTests +{ + using TestStack.ConventionTests.Internal; + + public interface IConvention + { + ConventionResult Execute(T data); + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests/Internal/ConventionResult.cs b/TestStack.ConventionTests/Internal/ConventionResult.cs new file mode 100644 index 0000000..5f03faf --- /dev/null +++ b/TestStack.ConventionTests/Internal/ConventionResult.cs @@ -0,0 +1,50 @@ +namespace TestStack.ConventionTests.Internal +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + + public class ConventionResult + { + public string Message { get; set; } + public bool IsConclusive { get; set; } + // TODO: perhaps name it better so that it doesn't get confused with System.Exception and related concepts + public bool HasExceptions { get; set; } + public int InvalidResultsCount { get; set; } + + public static ConventionResult For(IEnumerable items, + string header, + Action itemDescriptor) + { + var array = items.ToArray(); + var result = new ConventionResult + { + InvalidResultsCount = array.Length, + IsConclusive = true + }; + if (array.None()) + { + return result; + } + // NOTE: we might possibly want to abstract the StringBuilder to have more high level construct that would allow us to plug rich reports here... + var message = new StringBuilder(header); + Array.ForEach(array, r => + { + message.AppendLine(); + itemDescriptor(r, message); + }); + result.Message = message.ToString(); + return result; + } + + public static ConventionResult Inconclusive(string message) + { + return new ConventionResult + { + Message = message, + IsConclusive = false + }; + } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests/TestStack.ConventionTests.csproj b/TestStack.ConventionTests/TestStack.ConventionTests.csproj index 1929e87..2807a7b 100644 --- a/TestStack.ConventionTests/TestStack.ConventionTests.csproj +++ b/TestStack.ConventionTests/TestStack.ConventionTests.csproj @@ -32,6 +32,12 @@ true + + ..\packages\ApprovalTests.3.0.01\lib\net40\ApprovalTests.dll + + + ..\packages\ApprovalUtilities.3.0.01\lib\net35\ApprovalUtilities.dll + ..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.dll @@ -53,13 +59,15 @@ + - + + diff --git a/TestStack.ConventionTests/Types.cs b/TestStack.ConventionTests/Types.cs new file mode 100644 index 0000000..3fe8f7f --- /dev/null +++ b/TestStack.ConventionTests/Types.cs @@ -0,0 +1,16 @@ +namespace TestStack.ConventionTests +{ + using System; + + /// + /// This is where we set what our convention is all about. + /// + // NOTE: notice no base type, no interface. Just a POCO DTO + public class Types + { + //NOTE: that's a terrible name + public Type[] ApplicableTypes { get; set; } + + public bool HasApprovedExceptions { get; set; } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests/packages.config b/TestStack.ConventionTests/packages.config index bd56ac0..d6f9755 100644 --- a/TestStack.ConventionTests/packages.config +++ b/TestStack.ConventionTests/packages.config @@ -1,4 +1,6 @@  + + \ No newline at end of file From 3ba784ce742226362418f1bc4cd5043952de2967 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozmic Date: Tue, 30 Jul 2013 20:21:37 +1000 Subject: [PATCH 2/4] moved some common logic out of Convention classes so ConventionData now has an interface, not so POCO anymore, but we get to have 2LOC conventions --- TestStack.ConventionTests/Convention.cs | 24 ++++++++++--------- .../AllClassesHaveDefaultConstructor.cs | 20 ++++------------ .../Conventions/AllMethodsAreVirtual.cs | 16 ++++--------- TestStack.ConventionTests/IConvention.cs | 2 +- TestStack.ConventionTests/IConventionData.cs | 8 +++++++ .../Internal/ConventionResult.cs | 1 - .../TestStack.ConventionTests.csproj | 1 + TestStack.ConventionTests/Types.cs | 9 +++++-- 8 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 TestStack.ConventionTests/IConventionData.cs diff --git a/TestStack.ConventionTests/Convention.cs b/TestStack.ConventionTests/Convention.cs index 4744615..5211a41 100644 --- a/TestStack.ConventionTests/Convention.cs +++ b/TestStack.ConventionTests/Convention.cs @@ -11,25 +11,27 @@ public static class Convention { public static readonly ConventionSettings Settings = new ConventionSettings(); - public static void Is(IConvention convention, TData data) + public static void Is(IConvention convention, TData data) where TData : IConventionData { + if (data.HasValidSource == false) + { + // TODO: this would have to have a more reasonable and helpful message... + Settings.AssertInclunclusive("No valid source in " + data); + return; + } var result = convention.Execute(data); if (result.IsConclusive == false) { Settings.AssertInclunclusive(result.Message); + return; } - else + if (data.HasApprovedExceptions) { - if (result.HasExceptions) - { - // should we encapsulate Approvals behind Settings? - Approvals.Verify(result.Message); - } - else - { - Settings.AssertZero(result.InvalidResultsCount, result.Message); - } + // should we encapsulate Approvals behind Settings? + Approvals.Verify(result.Message); + return; } + Settings.AssertZero(result.InvalidResultsCount, result.Message); } public static void Is(IEnumerable itemsToVerify) where T : ConventionData, new() diff --git a/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs b/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs index 4e568f5..cb1b8c7 100644 --- a/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs +++ b/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs @@ -6,29 +6,17 @@ public class AllClassesHaveDefaultConstructor : IConvention { - public string HeaderMessage { get; set; } - public AllClassesHaveDefaultConstructor() { HeaderMessage = "The following types do not have default constructor"; } + public string HeaderMessage { get; set; } + public ConventionResult Execute(Types data) { - var types = data.ApplicableTypes; - if (types.None()) - { - return ConventionResult.Inconclusive("Put sensible 'inconclusive' message here"); - } - // NOTE: thie bit above is duplicated in both conventions we have, and will likely be duplicated in any other. - // we likely will want to pull that out, leaving perhaps a property like InconclusiveMessage - - var invalid = types.Where(t => t.HasDefaultConstructor() == false); - var result = ConventionResult.For(invalid, HeaderMessage, (t, m) => m.AppendLine("\t" + t)); - - //if we switch conventionData to have an interface and put HasApprovedExceptions on it, we'll be able to pull this out as well. - result.HasExceptions = data.HasApprovedExceptions; - return result; + var invalid = data.ApplicableTypes.Where(t => t.HasDefaultConstructor() == false); + return ConventionResult.For(invalid, HeaderMessage, (t, m) => m.AppendLine("\t" + t)); } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs b/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs index 03b4d9f..8d42fb3 100644 --- a/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs +++ b/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs @@ -15,20 +15,14 @@ public AllMethodsAreVirtual() HeaderMessage = "The following methods are not virtual."; } + public string HeaderMessage { get; set; } + public ConventionResult Execute(Types data) { - var types = data.ApplicableTypes; - if (types.None()) - { - return ConventionResult.Inconclusive("Put sensible 'inconclusive' message here"); - } - // do we want to encapsulate that in some way? // also notice how data gives us types, yet the convention acts upon methods. - var invalid = types.ToLookup(t => t, t => t.NonVirtualMethods()).Where(l => l.Any()); - var result = ConventionResult.For(invalid, HeaderMessage, DescribeTypeAndMethods); - result.HasExceptions = data.HasApprovedExceptions; - return result; + var invalid = data.ApplicableTypes.ToLookup(t => t, t => t.NonVirtualMethods()).Where(l => l.Any()); + return ConventionResult.For(invalid, HeaderMessage, DescribeTypeAndMethods); } // I like how that's encapsulated in the reusable convention type, whereas previously it was part of the convention/test code @@ -40,7 +34,5 @@ void DescribeTypeAndMethods(IGrouping> item, Strin message.AppendLine("\t\t" + method); } } - - public string HeaderMessage { get; set; } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/IConvention.cs b/TestStack.ConventionTests/IConvention.cs index 7ee1c33..186767f 100644 --- a/TestStack.ConventionTests/IConvention.cs +++ b/TestStack.ConventionTests/IConvention.cs @@ -2,7 +2,7 @@ { using TestStack.ConventionTests.Internal; - public interface IConvention + public interface IConvention where T : IConventionData { ConventionResult Execute(T data); } diff --git a/TestStack.ConventionTests/IConventionData.cs b/TestStack.ConventionTests/IConventionData.cs new file mode 100644 index 0000000..5d90db5 --- /dev/null +++ b/TestStack.ConventionTests/IConventionData.cs @@ -0,0 +1,8 @@ +namespace TestStack.ConventionTests +{ + public interface IConventionData + { + bool HasValidSource { get; } + bool HasApprovedExceptions { get; } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests/Internal/ConventionResult.cs b/TestStack.ConventionTests/Internal/ConventionResult.cs index 5f03faf..96ac32c 100644 --- a/TestStack.ConventionTests/Internal/ConventionResult.cs +++ b/TestStack.ConventionTests/Internal/ConventionResult.cs @@ -10,7 +10,6 @@ public class ConventionResult public string Message { get; set; } public bool IsConclusive { get; set; } // TODO: perhaps name it better so that it doesn't get confused with System.Exception and related concepts - public bool HasExceptions { get; set; } public int InvalidResultsCount { get; set; } public static ConventionResult For(IEnumerable items, diff --git a/TestStack.ConventionTests/TestStack.ConventionTests.csproj b/TestStack.ConventionTests/TestStack.ConventionTests.csproj index 2807a7b..4e01ff6 100644 --- a/TestStack.ConventionTests/TestStack.ConventionTests.csproj +++ b/TestStack.ConventionTests/TestStack.ConventionTests.csproj @@ -59,6 +59,7 @@ + diff --git a/TestStack.ConventionTests/Types.cs b/TestStack.ConventionTests/Types.cs index 3fe8f7f..83ec60b 100644 --- a/TestStack.ConventionTests/Types.cs +++ b/TestStack.ConventionTests/Types.cs @@ -1,16 +1,21 @@ namespace TestStack.ConventionTests { using System; + using System.Linq; /// /// This is where we set what our convention is all about. /// - // NOTE: notice no base type, no interface. Just a POCO DTO - public class Types + public class Types : IConventionData { //NOTE: that's a terrible name public Type[] ApplicableTypes { get; set; } public bool HasApprovedExceptions { get; set; } + + public bool HasValidSource + { + get { return ApplicableTypes.Any(); } + } } } \ No newline at end of file From ca40a1bca68e6bba7448c26ae71692ae1206e5c5 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozmic Date: Tue, 30 Jul 2013 21:29:58 +1000 Subject: [PATCH 3/4] migrated the Project file base conventions They are pretty nasty to look at, since we're pretty much dealing with raw XML of the .csproj. We probably want to build some sort of abstraction over that (or use the existing one from Microsoft.MsBuild.something.dll --- .../ProjectBasedConventions.cs | 38 +++++-------- TestStack.ConventionTests/Convention.cs | 42 -------------- .../Conventions/FilesAreEmbeddedResources.cs | 57 ++++--------------- ...NotReferenceDllsFromBinOrObjDirectories.cs | 41 ++++--------- TestStack.ConventionTests/Project.cs | 37 ++++++++++++ .../TestStack.ConventionTests.csproj | 1 + 6 files changed, 75 insertions(+), 141 deletions(-) create mode 100644 TestStack.ConventionTests/Project.cs diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs b/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs index 8ec4418..3276645 100644 --- a/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs @@ -1,7 +1,6 @@ namespace TestStack.ConventionTests.Tests { using System.Xml.Linq; - using ApprovalTests; using ApprovalTests.Reporters; using NSubstitute; using NUnit.Framework; @@ -10,49 +9,42 @@ using TestStack.ConventionTests.Tests.Properties; [TestFixture] - [UseReporter(typeof(DiffReporter))] + [UseReporter(typeof (DiffReporter))] public class ProjectBasedConventions { + public ProjectBasedConventions() + { + Convention.Settings.AssertInclunclusive = Assert.Inconclusive; + Convention.Settings.AssertZero = (v, m) => Assert.AreEqual(0, v, m); + } + [Test] public void ReferencingBinObj() { - // Actual syntax will be (when not testing): - // - // Convention.Is(new[] { typeof(ProjectBasedConventions).Assembly }); - // - var projectProvider = Substitute.For(); var projectLocator = Substitute.For(); projectProvider .LoadProjectDocument(Arg.Any()) .Returns(XDocument.Parse(Resources.ProjectFileWithBinReference)); - var convention = new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(projectLocator, projectProvider); - - var exception = Assert.Throws(() => - Convention.Is(convention, new[] { typeof(ProjectBasedConventions).Assembly })); - Approvals.Verify(exception.Message); + Convention.Is(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), + new Project(typeof (ProjectBasedConventions).Assembly, projectProvider, projectLocator)); } - + [Test] public void ScriptsNotEmbeddedResources() { - // Actual syntax will be (when not testing): - // - // Convention.Is(new[] { typeof(ProjectBasedConventions).Assembly }, i => i.EndsWith(".sql")); - // - var projectProvider = Substitute.For(); var projectLocator = Substitute.For(); projectProvider .LoadProjectDocument(Arg.Any()) .Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile)); - var convention = new FilesAreEmbeddedResources(projectLocator, projectProvider); - - var exception = Assert.Throws(() => - Convention.Is(convention, new[] { typeof(ProjectBasedConventions).Assembly }, i => i.EndsWith(".sql"))); - Approvals.Verify(exception.Message); + Convention.Is(new FilesAreEmbeddedResources(), + new Project(typeof (ProjectBasedConventions).Assembly, projectProvider, projectLocator) + { + Includes = i => i.EndsWith(".sql") + }); } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Convention.cs b/TestStack.ConventionTests/Convention.cs index 5211a41..656adc8 100644 --- a/TestStack.ConventionTests/Convention.cs +++ b/TestStack.ConventionTests/Convention.cs @@ -34,48 +34,6 @@ public static void Is(IConvention convention, TData data) where TD Settings.AssertZero(result.InvalidResultsCount, result.Message); } - public static void Is(IEnumerable itemsToVerify) where T : ConventionData, new() - { - Is(new T(), itemsToVerify); - } - public static void Is(IEnumerable itemsToVerify, Func filter) - where T : ConventionData, IRuntimeFilter, new() - { - Is(new T(), itemsToVerify); - } - public static void Is(IEnumerable itemsToVerify, Func filter) - where T : ConventionData, IRuntimeFilter, new() - { - Is(new T(), itemsToVerify); - } - - //Item.Is> - public static void Is(IEnumerable itemsToVerify) where T : ConventionData, new() - { - Is(new T(), itemsToVerify); - } - public static void Is(IEnumerable itemsToVerify, Func filter) where T : ConventionData, IRuntimeFilter, new() - { - Is(new T(), itemsToVerify, filter); - } - public static void Is(IEnumerable itemsToVerify, Func filter) where T : ConventionData, IRuntimeFilter, new() - { - Is(new T(), itemsToVerify, filter); - } - - //Item.Is> - public static void Is(IEnumerable itemsToVerify) where T : ConventionData, new() - { - Is(new T(), itemsToVerify); - } - public static void Is(IEnumerable itemsToVerify, Func filter) where T : ConventionData, IRuntimeFilter, new() - { - Is(new T(), itemsToVerify, filter); - } - public static void Is(IEnumerable itemsToVerify, Func filter) where T : ConventionData, IRuntimeFilter, new() - { - Is(new T(), itemsToVerify, filter); - } public static void Is(ConventionData convention, IEnumerable itemsToVerify) { diff --git a/TestStack.ConventionTests/Conventions/FilesAreEmbeddedResources.cs b/TestStack.ConventionTests/Conventions/FilesAreEmbeddedResources.cs index c018733..476520f 100644 --- a/TestStack.ConventionTests/Conventions/FilesAreEmbeddedResources.cs +++ b/TestStack.ConventionTests/Conventions/FilesAreEmbeddedResources.cs @@ -3,66 +3,33 @@ using System; using System.Collections.Generic; using System.Linq; - using System.Reflection; using System.Xml.Linq; - using TestStack.ConventionTests.Helpers; + using TestStack.ConventionTests.Internal; - public class FilesAreEmbeddedResources : ConventionData, IRuntimeFilter + public class FilesAreEmbeddedResources : IConvention { - readonly IProjectLocator projectLocator; - readonly IProjectProvider projectProvider; - Func itemFilter; - - public FilesAreEmbeddedResources() : this(new AssemblyProjectLocator(), new ProjectProvider()) { } - public FilesAreEmbeddedResources(IProjectLocator projectLocator, IProjectProvider projectProvider) + public ConventionResult Execute(Project data) { - this.projectLocator = projectLocator; - this.projectProvider = projectProvider; - - Must = assembly => - { - var references = GetProjectFiles(assembly); - - return references.All(s => s.Item1 == "EmbeddedResource"); - }; - ItemDescription = (assembly, builder) => - { - var filesNotEmbedded = GetProjectFiles(assembly) - .Where(r => r.Item1 != "EmbeddedResource"); - - - builder.AppendLine(string.Format("{0} has the following files which should be embedded resources:", - assembly.GetName().Name)); - foreach (var error in filesNotEmbedded.Select(m => m.Item2 + " which currently has a build action of '" + m.Item1 + "'")) - { - builder.Append('\t'); - builder.AppendLine(error); - } - }; + return ConventionResult.For(GetProjectFiles(data).Where(s => s.Item1 != "EmbeddedResource"), + "The following files which should be embedded resources:", + (t, m) => m.AppendLine("\t" + t.Item2)); } - IEnumerable> GetProjectFiles(Assembly assembly) + IEnumerable> GetProjectFiles(Project project) { - //TODO Not sure about filters, we can interate on this... - if (itemFilter == null) - throw new InvalidOperationException("This convention requires you to provide a filter, which is an overload on Convention.Is"); - + if (project.Includes == null) + throw new InvalidOperationException( + "This convention requires you to provide a filter on the convention data"); const string msbuild = "http://schemas.microsoft.com/developer/msbuild/2003"; - var resolveProjectFilePath = projectLocator.ResolveProjectFilePath(assembly); - XDocument projDefinition = projectProvider.LoadProjectDocument(resolveProjectFilePath); + var projDefinition = project.GetProject(); var references = projDefinition .Element(XName.Get("Project", msbuild)) .Elements(XName.Get("ItemGroup", msbuild)) .Elements() .Select(refElem => Tuple.Create(refElem.Name.LocalName, refElem.Attribute("Include").Value)) - .Where(i => itemFilter(i.Item2)); + .Where(i => project.Includes(i.Item2)); return references; } - - public void SetFilter(Func filter) - { - itemFilter = filter; - } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.cs b/TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.cs index d63528c..acfe31a 100644 --- a/TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.cs +++ b/TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.cs @@ -2,51 +2,30 @@ { using System.Collections.Generic; using System.Linq; - using System.Reflection; using System.Text.RegularExpressions; using System.Xml.Linq; - using TestStack.ConventionTests.Helpers; + using TestStack.ConventionTests.Internal; - public class ProjectDoesNotReferenceDllsFromBinOrObjDirectories : ConventionData + public class ProjectDoesNotReferenceDllsFromBinOrObjDirectories : IConvention { const string AssemblyReferencingObjRegex = @"^(?.*?(obj|bin).*?)$"; - public ProjectDoesNotReferenceDllsFromBinOrObjDirectories() - : this(new AssemblyProjectLocator(), new ProjectProvider()) + public ConventionResult Execute(Project data) { + var invalid = AllProjectReferences(data.GetProject()).Where(IsBinOrObjReference); + return ConventionResult.For(invalid, "Some invalid references found.", (r, m) => m.AppendLine("\t" + r)); } - public ProjectDoesNotReferenceDllsFromBinOrObjDirectories(IProjectLocator projectLocator, IProjectProvider projectProvider) - { - Must = assembly => - { - var references = GetProjectReferences(projectLocator, projectProvider, assembly); - - return references.All(s => !Regex.IsMatch(s, AssemblyReferencingObjRegex, RegexOptions.IgnoreCase)); - }; - ItemDescription = (assembly, builder) => - { - var matches = GetProjectReferences(projectLocator, projectProvider, assembly) - .Select(r => Regex.Match(r, AssemblyReferencingObjRegex, RegexOptions.IgnoreCase)) - .Where(r => r.Success); - builder.AppendLine(string.Format("{0} is referencing assemblies in the bin or obj folders:", - assembly.GetName().Name)); - foreach (var match in matches.Select(m=>m.Groups["assembly"].Value)) - { - builder.Append('\t'); - builder.AppendLine(match); - } - }; + static bool IsBinOrObjReference(string reference) + { + return Regex.IsMatch(reference, AssemblyReferencingObjRegex, RegexOptions.IgnoreCase); } - static IEnumerable GetProjectReferences(IProjectLocator projectLocator, IProjectProvider projectProvider, - Assembly assembly) + static IEnumerable AllProjectReferences(XDocument projDefinition) { XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003"; - var resolveProjectFilePath = projectLocator.ResolveProjectFilePath(assembly); - XDocument projDefinition = projectProvider.LoadProjectDocument(resolveProjectFilePath); - IEnumerable references = projDefinition + var references = projDefinition .Element(msbuild + "Project") .Elements(msbuild + "ItemGroup") .Elements(msbuild + "Reference") diff --git a/TestStack.ConventionTests/Project.cs b/TestStack.ConventionTests/Project.cs new file mode 100644 index 0000000..6acb814 --- /dev/null +++ b/TestStack.ConventionTests/Project.cs @@ -0,0 +1,37 @@ +namespace TestStack.ConventionTests +{ + using System; + using System.Reflection; + using System.Xml.Linq; + using TestStack.ConventionTests.Helpers; + + public class Project : IConventionData + { + readonly Assembly assembly; + readonly IProjectLocator projectLocator; + readonly IProjectProvider projectProvider; + + public Project(Assembly assembly, IProjectProvider projectProvider, IProjectLocator projectLocator) + { + this.assembly = assembly; + this.projectProvider = projectProvider; + this.projectLocator = projectLocator; + } + + public bool HasValidSource + { + get { return projectLocator.ResolveProjectFilePath(assembly) != null; } + } + + public bool HasApprovedExceptions { get; set; } + + public XDocument GetProject() + { + var location = projectLocator.ResolveProjectFilePath(assembly); + var project = projectProvider.LoadProjectDocument(location); + return project; + } + + public Func Includes; + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests/TestStack.ConventionTests.csproj b/TestStack.ConventionTests/TestStack.ConventionTests.csproj index 4e01ff6..04cfd0b 100644 --- a/TestStack.ConventionTests/TestStack.ConventionTests.csproj +++ b/TestStack.ConventionTests/TestStack.ConventionTests.csproj @@ -68,6 +68,7 @@ + From ebd2864a9cdcd4d0e54b4fb91e456f7757624a4e Mon Sep 17 00:00:00 2001 From: Krzysztof Kozmic Date: Tue, 30 Jul 2013 21:50:35 +1000 Subject: [PATCH 4/4] project clean up removed non used files/types moved types around project/namespaces to declutter the intellisense experience --- .../ProjectBasedConventions.cs | 2 +- TestStack.ConventionTests/Convention.cs | 59 ++----------------- ...{ConventionData`1.cs => ConventionData.cs} | 18 +++--- .../ConventionFailedException.cs | 15 ----- .../AllClassesHaveDefaultConstructor.cs | 1 - .../Conventions/AllMethodsAreVirtual.cs | 1 - .../Conventions/Project.cs | 39 ++++++++++++ .../{ => Conventions}/Types.cs | 2 +- TestStack.ConventionTests/IConvention.cs | 2 +- TestStack.ConventionTests/IRuntimeFilter.cs | 9 --- .../AssemblyProjectLocator.cs | 4 +- .../{Helpers => Internal}/IProjectLocator.cs | 2 +- .../{Helpers => Internal}/IProjectProvider.cs | 16 ++--- .../{Helpers => Internal}/LinqExtensions.cs | 6 +- .../{Helpers => Internal}/ProjectProvider.cs | 22 +++---- .../ReflectionExtensions.cs | 19 +++--- TestStack.ConventionTests/Project.cs | 37 ------------ .../Properties/AssemblyInfo.cs | 14 +++-- .../TestStack.ConventionTests.csproj | 20 +++---- 19 files changed, 112 insertions(+), 176 deletions(-) rename TestStack.ConventionTests/{ConventionData`1.cs => ConventionData.cs} (86%) delete mode 100644 TestStack.ConventionTests/ConventionFailedException.cs create mode 100644 TestStack.ConventionTests/Conventions/Project.cs rename TestStack.ConventionTests/{ => Conventions}/Types.cs (86%) delete mode 100644 TestStack.ConventionTests/IRuntimeFilter.cs rename TestStack.ConventionTests/{Helpers => Internal}/AssemblyProjectLocator.cs (86%) rename TestStack.ConventionTests/{Helpers => Internal}/IProjectLocator.cs (71%) rename TestStack.ConventionTests/{Helpers => Internal}/IProjectProvider.cs (72%) rename TestStack.ConventionTests/{Helpers => Internal}/LinqExtensions.cs (82%) rename TestStack.ConventionTests/{Helpers => Internal}/ProjectProvider.cs (80%) rename TestStack.ConventionTests/{Helpers => Internal}/ReflectionExtensions.cs (75%) delete mode 100644 TestStack.ConventionTests/Project.cs diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs b/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs index 3276645..b84e12b 100644 --- a/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs @@ -5,7 +5,7 @@ using NSubstitute; using NUnit.Framework; using TestStack.ConventionTests.Conventions; - using TestStack.ConventionTests.Helpers; + using TestStack.ConventionTests.Internal; using TestStack.ConventionTests.Tests.Properties; [TestFixture] diff --git a/TestStack.ConventionTests/Convention.cs b/TestStack.ConventionTests/Convention.cs index 656adc8..24107aa 100644 --- a/TestStack.ConventionTests/Convention.cs +++ b/TestStack.ConventionTests/Convention.cs @@ -1,10 +1,6 @@ namespace TestStack.ConventionTests { using System; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - using System.Text; using ApprovalTests; public static class Convention @@ -34,61 +30,16 @@ public static void Is(IConvention convention, TData data) where TD Settings.AssertZero(result.InvalidResultsCount, result.Message); } - - public static void Is(ConventionData convention, IEnumerable itemsToVerify) - { - var results = Result(convention, itemsToVerify); - if (!string.IsNullOrEmpty(results)) - throw new ConventionFailedException(results); - } - - public static void Is(TConvention convention, IEnumerable itemsToVerify, Func itemFilter) - where TConvention : ConventionData, IRuntimeFilter - { - Is(convention, itemsToVerify, itemFilter); - } - - public static void Is(TConvention convention, IEnumerable itemsToVerify, Func itemFilter) - where TConvention : ConventionData, IRuntimeFilter + public class ConventionSettings { - var results = Result(convention, itemsToVerify, itemFilter); - if (!string.IsNullOrEmpty(results)) - throw new ConventionFailedException(results); - } + public Action AssertInclunclusive; - public static string Result(ConventionData convention, IEnumerable itemsToVerify) - { - var message = new StringBuilder(); - var invalidItems = itemsToVerify.Where(i => !convention.Must(i)).ToArray(); - if (!invalidItems.Any()) return null; + public Action AssertZero; - message.AppendLine(convention.Description ?? "Convention has failing items"); - foreach (var invalidType in invalidItems) + public ConventionSettings() { - message.Append('\t'); - convention.ItemDescription(invalidType, message); + // TODO: initialize the type; } - - return message.ToString(); } - - public static string Result(TConvention convention, IEnumerable itemsToVerify, Func itemFilter) - where TConvention : ConventionData, IRuntimeFilter - { - convention.SetFilter(itemFilter); - return Result(convention, itemsToVerify); - } - } - - public class ConventionSettings - { - public ConventionSettings() - { - // TODO: initialize the type; - } - - public Action AssertInclunclusive; - - public Action AssertZero; } } \ No newline at end of file diff --git a/TestStack.ConventionTests/ConventionData`1.cs b/TestStack.ConventionTests/ConventionData.cs similarity index 86% rename from TestStack.ConventionTests/ConventionData`1.cs rename to TestStack.ConventionTests/ConventionData.cs index b7a5965..363e21b 100644 --- a/TestStack.ConventionTests/ConventionData`1.cs +++ b/TestStack.ConventionTests/ConventionData.cs @@ -8,13 +8,8 @@ /// public class ConventionData { - readonly Action defaultItemDescription = DefaultItemDescriptionMethod; public static readonly Predicate None = _ => false; - - static void DefaultItemDescriptionMethod(TItem item, StringBuilder message) - { - message.AppendLine(ReferenceEquals(item, null) ? "<>" : item.ToString()); - } + readonly Action defaultItemDescription = DefaultItemDescriptionMethod; public ConventionData() { @@ -26,17 +21,24 @@ public ConventionData() public Func OrderBy { get; set; } /// - /// Descriptive text used for failure message in test. Should explan what is wrong, and how to fix it (how to make types that do not conform to the convention do so). + /// Descriptive text used for failure message in test. Should explan what is wrong, and how to fix it (how to make + /// types that do not conform to the convention do so). /// public string Description { get; set; } /// - /// This is the convention. The predicate should return true for types that do conform to the convention, and false otherwise + /// This is the convention. The predicate should return true for types that do conform to the convention, and + /// false otherwise /// public Predicate Must { get; set; } public Action ItemDescription { get; set; } + static void DefaultItemDescriptionMethod(TItem item, StringBuilder message) + { + message.AppendLine(ReferenceEquals(item, null) ? "<>" : item.ToString()); + } + object HashCode(TItem arg) { if (ReferenceEquals(arg, null)) diff --git a/TestStack.ConventionTests/ConventionFailedException.cs b/TestStack.ConventionTests/ConventionFailedException.cs deleted file mode 100644 index 39b1104..0000000 --- a/TestStack.ConventionTests/ConventionFailedException.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace TestStack.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/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs b/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs index cb1b8c7..7eef443 100644 --- a/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs +++ b/TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs @@ -1,7 +1,6 @@ namespace TestStack.ConventionTests.Conventions { using System.Linq; - using TestStack.ConventionTests.Helpers; using TestStack.ConventionTests.Internal; public class AllClassesHaveDefaultConstructor : IConvention diff --git a/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs b/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs index 8d42fb3..015ba8c 100644 --- a/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs +++ b/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Reflection; using System.Text; - using TestStack.ConventionTests.Helpers; using TestStack.ConventionTests.Internal; public class AllMethodsAreVirtual : IConvention diff --git a/TestStack.ConventionTests/Conventions/Project.cs b/TestStack.ConventionTests/Conventions/Project.cs new file mode 100644 index 0000000..b0065d1 --- /dev/null +++ b/TestStack.ConventionTests/Conventions/Project.cs @@ -0,0 +1,39 @@ +namespace TestStack.ConventionTests.Conventions +{ + using System; + using System.Reflection; + using System.Xml.Linq; + using TestStack.ConventionTests.Internal; + + public class Project : IConventionData + { + public Func Includes; + + public Project(Assembly assembly, IProjectProvider projectProvider, IProjectLocator projectLocator) + { + Assembly = assembly; + ProjectProvider = projectProvider; + ProjectLocator = projectLocator; + } + + public Assembly Assembly { get; private set; } + + public IProjectLocator ProjectLocator { get; private set; } + + public IProjectProvider ProjectProvider { get; private set; } + + public bool HasValidSource + { + get { return ProjectLocator.ResolveProjectFilePath(Assembly) != null; } + } + + public bool HasApprovedExceptions { get; set; } + + public XDocument GetProject() + { + var location = ProjectLocator.ResolveProjectFilePath(Assembly); + var project = ProjectProvider.LoadProjectDocument(location); + return project; + } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests/Types.cs b/TestStack.ConventionTests/Conventions/Types.cs similarity index 86% rename from TestStack.ConventionTests/Types.cs rename to TestStack.ConventionTests/Conventions/Types.cs index 83ec60b..1ce6692 100644 --- a/TestStack.ConventionTests/Types.cs +++ b/TestStack.ConventionTests/Conventions/Types.cs @@ -1,4 +1,4 @@ -namespace TestStack.ConventionTests +namespace TestStack.ConventionTests.Conventions { using System; using System.Linq; diff --git a/TestStack.ConventionTests/IConvention.cs b/TestStack.ConventionTests/IConvention.cs index 186767f..82a0908 100644 --- a/TestStack.ConventionTests/IConvention.cs +++ b/TestStack.ConventionTests/IConvention.cs @@ -2,7 +2,7 @@ { using TestStack.ConventionTests.Internal; - public interface IConvention where T : IConventionData + public interface IConvention where T : IConventionData { ConventionResult Execute(T data); } diff --git a/TestStack.ConventionTests/IRuntimeFilter.cs b/TestStack.ConventionTests/IRuntimeFilter.cs deleted file mode 100644 index 94c6778..0000000 --- a/TestStack.ConventionTests/IRuntimeFilter.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace TestStack.ConventionTests -{ - using System; - - public interface IRuntimeFilter - { - void SetFilter(Func predicate); - } -} \ No newline at end of file diff --git a/TestStack.ConventionTests/Helpers/AssemblyProjectLocator.cs b/TestStack.ConventionTests/Internal/AssemblyProjectLocator.cs similarity index 86% rename from TestStack.ConventionTests/Helpers/AssemblyProjectLocator.cs rename to TestStack.ConventionTests/Internal/AssemblyProjectLocator.cs index 174bf7d..2830ce7 100644 --- a/TestStack.ConventionTests/Helpers/AssemblyProjectLocator.cs +++ b/TestStack.ConventionTests/Internal/AssemblyProjectLocator.cs @@ -1,4 +1,4 @@ -namespace TestStack.ConventionTests.Helpers +namespace TestStack.ConventionTests.Internal { using System; using System.Reflection; @@ -9,7 +9,7 @@ public class AssemblyProjectLocator : IProjectLocator { public string ResolveProjectFilePath(Assembly assembly) { - var readerParameters = new ReaderParameters { ReadSymbols = true, ReadingMode = ReadingMode.Deferred }; + var readerParameters = new ReaderParameters {ReadSymbols = true, ReadingMode = ReadingMode.Deferred}; var definition = AssemblyDefinition.ReadAssembly(assembly.Location, readerParameters); var methodDefinition = GetMethodWithBody(definition); var document = GetMethodDocument(methodDefinition); diff --git a/TestStack.ConventionTests/Helpers/IProjectLocator.cs b/TestStack.ConventionTests/Internal/IProjectLocator.cs similarity index 71% rename from TestStack.ConventionTests/Helpers/IProjectLocator.cs rename to TestStack.ConventionTests/Internal/IProjectLocator.cs index 148bc17..12aaafc 100644 --- a/TestStack.ConventionTests/Helpers/IProjectLocator.cs +++ b/TestStack.ConventionTests/Internal/IProjectLocator.cs @@ -1,4 +1,4 @@ -namespace TestStack.ConventionTests.Helpers +namespace TestStack.ConventionTests.Internal { using System.Reflection; diff --git a/TestStack.ConventionTests/Helpers/IProjectProvider.cs b/TestStack.ConventionTests/Internal/IProjectProvider.cs similarity index 72% rename from TestStack.ConventionTests/Helpers/IProjectProvider.cs rename to TestStack.ConventionTests/Internal/IProjectProvider.cs index 1f8c52a..e09da1c 100644 --- a/TestStack.ConventionTests/Helpers/IProjectProvider.cs +++ b/TestStack.ConventionTests/Internal/IProjectProvider.cs @@ -1,9 +1,9 @@ -namespace TestStack.ConventionTests -{ - using System.Xml.Linq; - - public interface IProjectProvider - { - XDocument LoadProjectDocument(string resolveProjectFilePath); - } +namespace TestStack.ConventionTests.Internal +{ + using System.Xml.Linq; + + public interface IProjectProvider + { + XDocument LoadProjectDocument(string resolveProjectFilePath); + } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Helpers/LinqExtensions.cs b/TestStack.ConventionTests/Internal/LinqExtensions.cs similarity index 82% rename from TestStack.ConventionTests/Helpers/LinqExtensions.cs rename to TestStack.ConventionTests/Internal/LinqExtensions.cs index 72c391f..920e4e5 100644 --- a/TestStack.ConventionTests/Helpers/LinqExtensions.cs +++ b/TestStack.ConventionTests/Internal/LinqExtensions.cs @@ -1,8 +1,10 @@ // ReSharper disable once CheckNamespace -namespace System.Linq + +namespace TestStack.ConventionTests.Internal { using System; using System.Collections.Generic; + using System.Linq; public static class LinqExtensions { @@ -10,7 +12,7 @@ public static bool None(this IEnumerable enumerable) { return !enumerable.Any(); } - + public static bool None(this IEnumerable enumerable, Func predicate) { return !enumerable.Any(predicate); diff --git a/TestStack.ConventionTests/Helpers/ProjectProvider.cs b/TestStack.ConventionTests/Internal/ProjectProvider.cs similarity index 80% rename from TestStack.ConventionTests/Helpers/ProjectProvider.cs rename to TestStack.ConventionTests/Internal/ProjectProvider.cs index 3c6c662..994b44b 100644 --- a/TestStack.ConventionTests/Helpers/ProjectProvider.cs +++ b/TestStack.ConventionTests/Internal/ProjectProvider.cs @@ -1,12 +1,12 @@ -namespace TestStack.ConventionTests -{ - using System.Xml.Linq; - - public class ProjectProvider : IProjectProvider - { - public XDocument LoadProjectDocument(string resolveProjectFilePath) - { - return XDocument.Load(resolveProjectFilePath); - } - } +namespace TestStack.ConventionTests.Internal +{ + using System.Xml.Linq; + + public class ProjectProvider : IProjectProvider + { + public XDocument LoadProjectDocument(string resolveProjectFilePath) + { + return XDocument.Load(resolveProjectFilePath); + } + } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Helpers/ReflectionExtensions.cs b/TestStack.ConventionTests/Internal/ReflectionExtensions.cs similarity index 75% rename from TestStack.ConventionTests/Helpers/ReflectionExtensions.cs rename to TestStack.ConventionTests/Internal/ReflectionExtensions.cs index 76a17ac..11eaeb5 100644 --- a/TestStack.ConventionTests/Helpers/ReflectionExtensions.cs +++ b/TestStack.ConventionTests/Internal/ReflectionExtensions.cs @@ -1,4 +1,4 @@ -namespace TestStack.ConventionTests.Helpers +namespace TestStack.ConventionTests.Internal { using System; using System.Collections.Generic; @@ -46,12 +46,12 @@ public static Type[] SafeGetTypes(this Assembly assembly) public static bool IsEnum(this Type type) { - return typeof(Enum).IsAssignableFrom(type); + return typeof (Enum).IsAssignableFrom(type); } public static bool HasAttribute(this Type type, bool inherit = true) where TAttribute : Attribute { - return type.GetCustomAttributes(typeof(TAttribute), inherit).Length > 0; + return type.GetCustomAttributes(typeof (TAttribute), inherit).Length > 0; } public static bool IsStatic(this Type type) @@ -61,7 +61,8 @@ public static bool IsStatic(this Type type) public static bool HasDefaultConstructor(this Type type) { - return type.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly) + return type.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | + BindingFlags.DeclaredOnly) .Any(constructorInfo => constructorInfo.GetParameters().Length == 0 && !constructorInfo.IsPrivate); } @@ -73,7 +74,7 @@ public static bool HasPublicDefaultConstructor(this Type type) public static bool AssignableTo(this Type type) { - return typeof(TAssignableTo).IsAssignableFrom(type); + return typeof (TAssignableTo).IsAssignableFrom(type); } public static IEnumerable ConcreteTypes(this IEnumerable types) @@ -83,9 +84,13 @@ public static IEnumerable ConcreteTypes(this IEnumerable types) public static IEnumerable NonVirtualMethods(this Type type) { - var methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); + var methodInfos = + type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | + BindingFlags.DeclaredOnly); return methodInfos - .Where(methodInfo => !methodInfo.IsPrivate && methodInfo.DeclaringType == type && !methodInfo.Name.StartsWith("<")) + .Where( + methodInfo => + !methodInfo.IsPrivate && methodInfo.DeclaringType == type && !methodInfo.Name.StartsWith("<")) .Where(methodInfo => methodInfo.Name != "Equals") .Where(methodInfo => !methodInfo.IsVirtual || methodInfo.IsFinal); } diff --git a/TestStack.ConventionTests/Project.cs b/TestStack.ConventionTests/Project.cs deleted file mode 100644 index 6acb814..0000000 --- a/TestStack.ConventionTests/Project.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace TestStack.ConventionTests -{ - using System; - using System.Reflection; - using System.Xml.Linq; - using TestStack.ConventionTests.Helpers; - - public class Project : IConventionData - { - readonly Assembly assembly; - readonly IProjectLocator projectLocator; - readonly IProjectProvider projectProvider; - - public Project(Assembly assembly, IProjectProvider projectProvider, IProjectLocator projectLocator) - { - this.assembly = assembly; - this.projectProvider = projectProvider; - this.projectLocator = projectLocator; - } - - public bool HasValidSource - { - get { return projectLocator.ResolveProjectFilePath(assembly) != null; } - } - - public bool HasApprovedExceptions { get; set; } - - public XDocument GetProject() - { - var location = projectLocator.ResolveProjectFilePath(assembly); - var project = projectProvider.LoadProjectDocument(location); - return project; - } - - public Func Includes; - } -} \ No newline at end of file diff --git a/TestStack.ConventionTests/Properties/AssemblyInfo.cs b/TestStack.ConventionTests/Properties/AssemblyInfo.cs index 5f8fb14..74834b6 100644 --- a/TestStack.ConventionTests/Properties/AssemblyInfo.cs +++ b/TestStack.ConventionTests/Properties/AssemblyInfo.cs @@ -1,10 +1,9 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following +// 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. +using System.Reflection; +using System.Runtime.InteropServices; + [assembly: AssemblyTitle("TestStack.ConventionTests")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] @@ -17,9 +16,11 @@ // 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("ae7bce97-3d40-4d7c-932f-37f1c7b041a2")] // Version information for an assembly consists of the following four values: @@ -32,5 +33,6 @@ // 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")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/TestStack.ConventionTests/TestStack.ConventionTests.csproj b/TestStack.ConventionTests/TestStack.ConventionTests.csproj index 04cfd0b..1fed020 100644 --- a/TestStack.ConventionTests/TestStack.ConventionTests.csproj +++ b/TestStack.ConventionTests/TestStack.ConventionTests.csproj @@ -62,23 +62,21 @@ - - + - - - - - - + + + + + + - - + - +