diff --git a/TestStack.ConventionTests.Tests/ConventionAssertionClassTests.approval_mismatch.approved.txt b/TestStack.ConventionTests.Tests/ConventionAssertionClassTests.approval_mismatch.approved.txt new file mode 100644 index 0000000..f44578a --- /dev/null +++ b/TestStack.ConventionTests.Tests/ConventionAssertionClassTests.approval_mismatch.approved.txt @@ -0,0 +1,3 @@ +Header + +Approved Exception diff --git a/TestStack.ConventionTests.Tests/ConventionAssertionClassTests.cs b/TestStack.ConventionTests.Tests/ConventionAssertionClassTests.cs new file mode 100644 index 0000000..fe76a7b --- /dev/null +++ b/TestStack.ConventionTests.Tests/ConventionAssertionClassTests.cs @@ -0,0 +1,37 @@ +namespace TestStack.ConventionTests.Tests +{ + using ApprovalTests.Reporters; + using NUnit.Framework; + using TestStack.ConventionTests.Internal; + + [TestFixture] + [UseReporter(typeof(DiffReporter))] //NOTE: Can we take care of this in IsWithApprovedExceptions? + public class ConventionAssertionClassTests + { + [Test] + public void approval_mismatch() + { + //NOTE Do not approve any changes to this test + var ex = Assert.Throws(() => Convention.IsWithApprovedExeptions(new FailingConvention(), new FakeData())); + + StringAssert.Contains("Approved exceptions for convention differs", ex.Message); + StringAssert.Contains("Failed Approval: Received file ", ex.Message); + StringAssert.Contains("does not match approved file", ex.Message); + } + + public class FakeData : IConventionData + { + public void ThrowIfHasInvalidSource() + { + } + } + + public class FailingConvention : IConvention + { + public ConventionResult Execute(FakeData data) + { + return ConventionResult.For(new[] { "" }, "Header", (s, builder) => builder.AppendLine("Different")); + } + } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.BrokenReferences.received.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.BrokenReferences.received.txt deleted file mode 100644 index c8df625..0000000 --- a/TestStack.ConventionTests.Tests/ProjectBasedConventions.BrokenReferences.received.txt +++ /dev/null @@ -1,2 +0,0 @@ -Convention has failing items - TestStack.ConventionTests.Tests is referencing assemblies in the bin or obj folders, bin\Debug\ApprovalTests.dll diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.ReferencingBinObj.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.ReferencingBinObj.approved.txt deleted file mode 100644 index 5036566..0000000 --- a/TestStack.ConventionTests.Tests/ProjectBasedConventions.ReferencingBinObj.approved.txt +++ /dev/null @@ -1,3 +0,0 @@ -Convention has failing items - TestStack.ConventionTests.Tests is referencing assemblies in the bin or obj folders: - bin\Debug\ApprovalTests.dll diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.ScriptsNotEmbeddedResources.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.ScriptsNotEmbeddedResources.approved.txt deleted file mode 100644 index 4592f26..0000000 --- a/TestStack.ConventionTests.Tests/ProjectBasedConventions.ScriptsNotEmbeddedResources.approved.txt +++ /dev/null @@ -1,3 +0,0 @@ -Convention has failing items - TestStack.ConventionTests.Tests has the following files which should be embedded resources: - Scripts\Script2.sql which currently has a build action of 'None' diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.ScriptsNotEmbeddedResources.approved.txt.orig b/TestStack.ConventionTests.Tests/ProjectBasedConventions.ScriptsNotEmbeddedResources.approved.txt.orig deleted file mode 100644 index 19a76f1..0000000 --- a/TestStack.ConventionTests.Tests/ProjectBasedConventions.ScriptsNotEmbeddedResources.approved.txt.orig +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.assemblies_referencing_bin_obj.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.assemblies_referencing_bin_obj.approved.txt new file mode 100644 index 0000000..9a4fc80 --- /dev/null +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.assemblies_referencing_bin_obj.approved.txt @@ -0,0 +1,3 @@ +Some invalid assembly references found in TestStack.ConventionTests.Tests + + bin\Debug\ApprovalTests.dll diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.assemblies_referencing_bin_obj_with_approved_exceptions.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.assemblies_referencing_bin_obj_with_approved_exceptions.approved.txt new file mode 100644 index 0000000..9a4fc80 --- /dev/null +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.assemblies_referencing_bin_obj_with_approved_exceptions.approved.txt @@ -0,0 +1,3 @@ +Some invalid assembly references found in TestStack.ConventionTests.Tests + + bin\Debug\ApprovalTests.dll diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs b/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs index b84e12b..e1f4572 100644 --- a/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.cs @@ -1,6 +1,7 @@ namespace TestStack.ConventionTests.Tests { using System.Xml.Linq; + using ApprovalTests; using ApprovalTests.Reporters; using NSubstitute; using NUnit.Framework; @@ -9,42 +10,64 @@ using TestStack.ConventionTests.Tests.Properties; [TestFixture] - [UseReporter(typeof (DiffReporter))] + [UseReporter(typeof(DiffReporter))] public class ProjectBasedConventions { - public ProjectBasedConventions() + Project project; + IProjectProvider projectProvider; + + [SetUp] + public void Setup() { - Convention.Settings.AssertInclunclusive = Assert.Inconclusive; - Convention.Settings.AssertZero = (v, m) => Assert.AreEqual(0, v, m); + projectProvider = Substitute.For(); + var projectLocator = Substitute.For(); + project = new Project(typeof(ProjectBasedConventions).Assembly, projectProvider, projectLocator); } [Test] - public void ReferencingBinObj() + public void assemblies_referencing_bin_obj() { - var projectProvider = Substitute.For(); - var projectLocator = Substitute.For(); projectProvider .LoadProjectDocument(Arg.Any()) .Returns(XDocument.Parse(Resources.ProjectFileWithBinReference)); - Convention.Is(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), - new Project(typeof (ProjectBasedConventions).Assembly, projectProvider, projectLocator)); + var ex = Assert.Throws(() => Convention.Is(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project)); + + Approvals.Verify(ex.Message); } - + [Test] - public void ScriptsNotEmbeddedResources() + public void assemblies_referencing_bin_obj_with_approved_exceptions() { - var projectProvider = Substitute.For(); - var projectLocator = Substitute.For(); + projectProvider + .LoadProjectDocument(Arg.Any()) + .Returns(XDocument.Parse(Resources.ProjectFileWithBinReference)); + + Convention.IsWithApprovedExeptions(new ProjectDoesNotReferenceDllsFromBinOrObjDirectories(), project); + } + + [Test] + public void scripts_not_embedded_resources() + { + project.Includes = i => i.EndsWith(".sql"); + projectProvider + .LoadProjectDocument(Arg.Any()) + .Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile)); + + var ex = Assert.Throws(() => Convention.Is(new FilesAreEmbeddedResources(), project)); + + Approvals.Verify(ex.Message); + } + + [Test] + public void scripts_not_embedded_resources_with_approved_exceptions() + { + project.Includes = i => i.EndsWith(".sql"); projectProvider .LoadProjectDocument(Arg.Any()) .Returns(XDocument.Parse(Resources.ProjectFileWithInvalidSqlScriptFile)); - Convention.Is(new FilesAreEmbeddedResources(), - new Project(typeof (ProjectBasedConventions).Assembly, projectProvider, projectLocator) - { - Includes = i => i.EndsWith(".sql") - }); + Convention.IsWithApprovedExeptions(new FilesAreEmbeddedResources(), project); } } } \ No newline at end of file diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.scripts_not_embedded_resources.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.scripts_not_embedded_resources.approved.txt new file mode 100644 index 0000000..49e8531 --- /dev/null +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.scripts_not_embedded_resources.approved.txt @@ -0,0 +1,3 @@ +The following files which should be embedded resources: + + Scripts\Script2.sql diff --git a/TestStack.ConventionTests.Tests/ProjectBasedConventions.scripts_not_embedded_resources_with_approved_exceptions.approved.txt b/TestStack.ConventionTests.Tests/ProjectBasedConventions.scripts_not_embedded_resources_with_approved_exceptions.approved.txt new file mode 100644 index 0000000..49e8531 --- /dev/null +++ b/TestStack.ConventionTests.Tests/ProjectBasedConventions.scripts_not_embedded_resources_with_approved_exceptions.approved.txt @@ -0,0 +1,3 @@ +The following files which should be embedded resources: + + Scripts\Script2.sql diff --git a/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj b/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj index d3ce552..5736818 100644 --- a/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj +++ b/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj @@ -51,6 +51,7 @@ + diff --git a/TestStack.ConventionTests.Tests/TypeBasedConventions.all_classes_have_default_constructor.approved.txt b/TestStack.ConventionTests.Tests/TypeBasedConventions.all_classes_have_default_constructor.approved.txt index fc698c4..f6ad07e 100644 --- a/TestStack.ConventionTests.Tests/TypeBasedConventions.all_classes_have_default_constructor.approved.txt +++ b/TestStack.ConventionTests.Tests/TypeBasedConventions.all_classes_have_default_constructor.approved.txt @@ -1,3 +1,4 @@ -Convention has failing items - TestAssembly.ClassWithNoDefaultCtor does not have a default constructor - TestAssembly.ClassWithPrivateDefaultCtor does not have a default constructor +The following types do not have default constructor + + TestAssembly.ClassWithNoDefaultCtor + TestAssembly.ClassWithPrivateDefaultCtor diff --git a/TestStack.ConventionTests.Tests/TypeBasedConventions.all_classes_have_default_constructor_wth_approved_exceptions.approved.txt b/TestStack.ConventionTests.Tests/TypeBasedConventions.all_classes_have_default_constructor_wth_approved_exceptions.approved.txt new file mode 100644 index 0000000..f6ad07e --- /dev/null +++ b/TestStack.ConventionTests.Tests/TypeBasedConventions.all_classes_have_default_constructor_wth_approved_exceptions.approved.txt @@ -0,0 +1,4 @@ +The following types do not have default constructor + + TestAssembly.ClassWithNoDefaultCtor + TestAssembly.ClassWithPrivateDefaultCtor diff --git a/TestStack.ConventionTests.Tests/TypeBasedConventions.all_methods_are_virtual.approved.txt b/TestStack.ConventionTests.Tests/TypeBasedConventions.all_methods_are_virtual.approved.txt index 4d8baa2..0197e7c 100644 --- a/TestStack.ConventionTests.Tests/TypeBasedConventions.all_methods_are_virtual.approved.txt +++ b/TestStack.ConventionTests.Tests/TypeBasedConventions.all_methods_are_virtual.approved.txt @@ -1,3 +1,3 @@ -Convention has failing items - TestAssembly.SampleDomainClass has non virtual method(s): - TestNonVirtual +The following methods are not virtual. + + TestAssembly.SampleDomainClass.TestNonVirtual diff --git a/TestStack.ConventionTests.Tests/TypeBasedConventions.all_methods_are_virtual_wth_approved_exceptions.approved.txt b/TestStack.ConventionTests.Tests/TypeBasedConventions.all_methods_are_virtual_wth_approved_exceptions.approved.txt new file mode 100644 index 0000000..0197e7c --- /dev/null +++ b/TestStack.ConventionTests.Tests/TypeBasedConventions.all_methods_are_virtual_wth_approved_exceptions.approved.txt @@ -0,0 +1,3 @@ +The following methods are not virtual. + + TestAssembly.SampleDomainClass.TestNonVirtual diff --git a/TestStack.ConventionTests.Tests/TypeBasedConventions.cs b/TestStack.ConventionTests.Tests/TypeBasedConventions.cs index e5a2faa..fa8f432 100644 --- a/TestStack.ConventionTests.Tests/TypeBasedConventions.cs +++ b/TestStack.ConventionTests.Tests/TypeBasedConventions.cs @@ -1,5 +1,6 @@ namespace TestStack.ConventionTests.Tests { + using ApprovalTests; using ApprovalTests.Reporters; using NUnit.Framework; using TestAssembly; @@ -13,28 +14,39 @@ public class TypeBasedConventions public TypeBasedConventions() { - // 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 + ApplicableTypes = itemsToVerify }; } [Test] public void all_classes_have_default_constructor() { - Convention.Is(new AllClassesHaveDefaultConstructor(), nhibernateEntities); + var ex = Assert.Throws(()=>Convention.Is(new AllClassesHaveDefaultConstructor(), nhibernateEntities)); + + Approvals.Verify(ex.Message); + } + + [Test] + public void all_classes_have_default_constructor_wth_approved_exceptions() + { + Convention.IsWithApprovedExeptions(new AllClassesHaveDefaultConstructor(), nhibernateEntities); } [Test] public void all_methods_are_virtual() { - Convention.Is(new AllMethodsAreVirtual(), nhibernateEntities); + var ex = Assert.Throws(()=>Convention.Is(new AllMethodsAreVirtual(), nhibernateEntities)); + + Approvals.Verify(ex.Message); + } + + [Test] + public void all_methods_are_virtual_wth_approved_exceptions() + { + Convention.IsWithApprovedExeptions(new AllMethodsAreVirtual(), nhibernateEntities); } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Convention.cs b/TestStack.ConventionTests/Convention.cs index 24107aa..b38f0b9 100644 --- a/TestStack.ConventionTests/Convention.cs +++ b/TestStack.ConventionTests/Convention.cs @@ -1,44 +1,35 @@ namespace TestStack.ConventionTests { - using System; + using System.Diagnostics; using ApprovalTests; + using ApprovalTests.Core.Exceptions; public static class Convention { - public static readonly ConventionSettings Settings = new ConventionSettings(); - 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; - } + data.ThrowIfHasInvalidSource(); var result = convention.Execute(data); - if (result.IsConclusive == false) - { - Settings.AssertInclunclusive(result.Message); - return; - } - if (data.HasApprovedExceptions) - { - // should we encapsulate Approvals behind Settings? - Approvals.Verify(result.Message); - return; - } - Settings.AssertZero(result.InvalidResultsCount, result.Message); + + if (result.Failed) + throw new ConventionFailedException(result.Message); } - public class ConventionSettings + public static void IsWithApprovedExeptions(IConvention convention, TData data) where TData : IConventionData { - public Action AssertInclunclusive; + data.ThrowIfHasInvalidSource(); + var result = convention.Execute(data); - public Action AssertZero; + // should we encapsulate Approvals behind Settings? + try + { + Approvals.Verify(result.Message); - public ConventionSettings() + Trace.WriteLine(string.Format("{0} has approved exceptions:\r\n\r\n{1}", convention.GetType().Name, result.Message)); + } + catch (ApprovalException ex) { - // TODO: initialize the type; + throw new ConventionFailedException("Approved exceptions for convention differs\r\n\r\n"+ex.Message, ex); } } } diff --git a/TestStack.ConventionTests/ConventionFailedException.cs b/TestStack.ConventionTests/ConventionFailedException.cs new file mode 100644 index 0000000..f4a7ffe --- /dev/null +++ b/TestStack.ConventionTests/ConventionFailedException.cs @@ -0,0 +1,15 @@ +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/AllMethodsAreVirtual.cs b/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs index 015ba8c..9b8e218 100644 --- a/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs +++ b/TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs @@ -20,17 +20,23 @@ public ConventionResult Execute(Types data) { // do we want to encapsulate that in some way? // also notice how data gives us types, yet the convention acts upon methods. - var invalid = data.ApplicableTypes.ToLookup(t => t, t => t.NonVirtualMethods()).Where(l => l.Any()); - return ConventionResult.For(invalid, HeaderMessage, DescribeTypeAndMethods); + var items = from applicableType in data.ApplicableTypes + let nonVirtuals = applicableType.NonVirtualMethods() + where nonVirtuals.Any() + select Tuple.Create(applicableType, nonVirtuals); + return ConventionResult.For(items, HeaderMessage, DescribeTypeAndMethods); } // 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) + void DescribeTypeAndMethods(Tuple> item, StringBuilder message) { - message.AppendLine("\t" + item.Key); - foreach (var method in item) + foreach (var method in item.Item2) { - message.AppendLine("\t\t" + method); + message.Append("\t"); + message.Append(item.Item1); + message.Append("."); + message.Append(method.Name); + message.AppendLine(); } } } diff --git a/TestStack.ConventionTests/Conventions/ConventionSourceInvalidException.cs b/TestStack.ConventionTests/Conventions/ConventionSourceInvalidException.cs new file mode 100644 index 0000000..e7f0d9f --- /dev/null +++ b/TestStack.ConventionTests/Conventions/ConventionSourceInvalidException.cs @@ -0,0 +1,17 @@ +namespace TestStack.ConventionTests.Conventions +{ + using System; + using System.Runtime.Serialization; + + [Serializable] + public class ConventionSourceInvalidException : Exception + { + public ConventionSourceInvalidException() { } + public ConventionSourceInvalidException(string message) : base(message) { } + public ConventionSourceInvalidException(string message, Exception inner) : base(message, inner) { } + protected ConventionSourceInvalidException( + SerializationInfo info, + StreamingContext context) + : base(info, context) { } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests/Conventions/Project.cs b/TestStack.ConventionTests/Conventions/Project.cs index b0065d1..e265170 100644 --- a/TestStack.ConventionTests/Conventions/Project.cs +++ b/TestStack.ConventionTests/Conventions/Project.cs @@ -22,9 +22,10 @@ public Project(Assembly assembly, IProjectProvider projectProvider, IProjectLoca public IProjectProvider ProjectProvider { get; private set; } - public bool HasValidSource + public void ThrowIfHasInvalidSource() { - get { return ProjectLocator.ResolveProjectFilePath(Assembly) != null; } + if (ProjectLocator.ResolveProjectFilePath(Assembly) == null) + throw new ConventionSourceInvalidException("Cannot resolve project file for assembly {0}"); } public bool HasApprovedExceptions { get; set; } diff --git a/TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.cs b/TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.cs index acfe31a..f773d95 100644 --- a/TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.cs +++ b/TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.cs @@ -2,6 +2,7 @@ { using System.Collections.Generic; using System.Linq; + using System.Text; using System.Text.RegularExpressions; using System.Xml.Linq; using TestStack.ConventionTests.Internal; @@ -12,10 +13,16 @@ public class ProjectDoesNotReferenceDllsFromBinOrObjDirectories : IConvention m.AppendLine("\t" + r)); + var projDefinition = data.GetProject(); + var invalid = AllProjectReferences(projDefinition).Where(IsBinOrObjReference); + var header = string.Format("Some invalid assembly references found in {0}", data.Assembly.GetName().Name); + return ConventionResult.For(invalid, header, FormatLine); } + void FormatLine(string assemblyReference, StringBuilder m) + { + m.AppendLine("\t" + assemblyReference); + } static bool IsBinOrObjReference(string reference) { diff --git a/TestStack.ConventionTests/Conventions/Types.cs b/TestStack.ConventionTests/Conventions/Types.cs index 1ce6692..eca2dd8 100644 --- a/TestStack.ConventionTests/Conventions/Types.cs +++ b/TestStack.ConventionTests/Conventions/Types.cs @@ -1,7 +1,7 @@ namespace TestStack.ConventionTests.Conventions { using System; - using System.Linq; + using TestStack.ConventionTests.Internal; /// /// This is where we set what our convention is all about. @@ -13,9 +13,10 @@ public class Types : IConventionData public bool HasApprovedExceptions { get; set; } - public bool HasValidSource + public void ThrowIfHasInvalidSource() { - get { return ApplicableTypes.Any(); } + if (ApplicableTypes.None()) + throw new ConventionSourceInvalidException("You must supply types to verify"); } } } \ No newline at end of file diff --git a/TestStack.ConventionTests/IConventionData.cs b/TestStack.ConventionTests/IConventionData.cs index 5d90db5..a289f10 100644 --- a/TestStack.ConventionTests/IConventionData.cs +++ b/TestStack.ConventionTests/IConventionData.cs @@ -2,7 +2,6 @@ { public interface IConventionData { - bool HasValidSource { get; } - bool HasApprovedExceptions { get; } + void ThrowIfHasInvalidSource(); } } \ No newline at end of file diff --git a/TestStack.ConventionTests/Internal/ConventionResult.cs b/TestStack.ConventionTests/Internal/ConventionResult.cs index 96ac32c..4886444 100644 --- a/TestStack.ConventionTests/Internal/ConventionResult.cs +++ b/TestStack.ConventionTests/Internal/ConventionResult.cs @@ -7,43 +7,30 @@ 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 int InvalidResultsCount { get; set; } + ConventionResult() { } - public static ConventionResult For(IEnumerable items, + public string Message { get; private set; } + public bool Failed { get { return !string.IsNullOrEmpty(Message); }} + + public static ConventionResult For( + IEnumerable items, string header, Action itemDescriptor) { var array = items.ToArray(); - var result = new ConventionResult - { - InvalidResultsCount = array.Length, - IsConclusive = true - }; + var result = new ConventionResult(); 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); - }); + message.AppendLine(); + message.AppendLine(); + Array.ForEach(array, r => 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/Internal/ReflectionExtensions.cs b/TestStack.ConventionTests/Internal/ReflectionExtensions.cs index 11eaeb5..f078c18 100644 --- a/TestStack.ConventionTests/Internal/ReflectionExtensions.cs +++ b/TestStack.ConventionTests/Internal/ReflectionExtensions.cs @@ -87,10 +87,10 @@ public static IEnumerable NonVirtualMethods(this Type type) var methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); - return methodInfos - .Where( - methodInfo => - !methodInfo.IsPrivate && methodInfo.DeclaringType == type && !methodInfo.Name.StartsWith("<")) + return methodInfos .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/TestStack.ConventionTests.csproj b/TestStack.ConventionTests/TestStack.ConventionTests.csproj index 1fed020..0e9444d 100644 --- a/TestStack.ConventionTests/TestStack.ConventionTests.csproj +++ b/TestStack.ConventionTests/TestStack.ConventionTests.csproj @@ -59,6 +59,8 @@ + +