diff --git a/TestStack.ConventionTests.Tests/ConventionFixture.cs b/TestStack.ConventionTests.Tests/ConventionFixture.cs new file mode 100644 index 0000000..e28b262 --- /dev/null +++ b/TestStack.ConventionTests.Tests/ConventionFixture.cs @@ -0,0 +1,34 @@ +namespace TestStack.ConventionTests.Tests +{ + using System; + using System.Linq; + using NUnit.Framework; + using TestStack.ConventionTests.ConventionData; + using TestStack.ConventionTests.Internal; + + [TestFixture] + public class ConventionFixture + { + [Test] + public void ShouldThrowWhenConventionDoesNotSetResult() + { + Assert.Throws(() => + Convention.Is(new CustomConventionWhichDoesNothing(), Types.InAssemblyOf())); + } + + // ReSharper disable once UnusedVariable + class CustomConventionWhichDoesNothing : IConvention + { + public void Execute(Types data, IConventionResultContext result) + { + var failingTypes = data.TypesToVerify.Where(IsBroken); + // Oops, I forgot to set the result + } + + bool IsBroken(Type type) + { + return true; + } + } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj b/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj index 3f7bfd3..b63dd36 100644 --- a/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj +++ b/TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj @@ -61,6 +61,7 @@ + diff --git a/TestStack.ConventionTests/Internal/ConventionContext.cs b/TestStack.ConventionTests/Internal/ConventionContext.cs index 4a13938..e14d395 100644 --- a/TestStack.ConventionTests/Internal/ConventionContext.cs +++ b/TestStack.ConventionTests/Internal/ConventionContext.cs @@ -13,6 +13,7 @@ public class ConventionContext : IConventionResultContext, IConventionFormatCont readonly IList processors; readonly ITestResultProcessor testResultProcessor; readonly IList results = new List(); + bool resultSet; public ConventionContext(string dataDescription, IList formatters, IList processors, ITestResultProcessor testResultProcessor) @@ -59,6 +60,7 @@ IReportDataFormatter GetReportDataFormatterFor(object data) void IConventionResultContext.Is(string resultTitle, IEnumerable failingData) { + resultSet = true; // ReSharper disable PossibleMultipleEnumeration results.Add(new ConventionResult( typeof (TResult), @@ -71,6 +73,7 @@ void IConventionResultContext.IsSymmetric( string firstSetFailureTitle, IEnumerable firstSetFailureData, string secondSetFailureTitle, IEnumerable secondSetFailureData) { + resultSet = true; results.Add(new ConventionResult( typeof (TResult), firstSetFailureTitle, dataDescription, @@ -103,6 +106,9 @@ public void Execute(IConvention convention, TDataSourc throw new ConventionSourceInvalidException(String.Format("{0} has no data", data.Description)); convention.Execute(data, this); + if (!resultSet) + throw new ResultNotSetException("{0} did not set a result, conventions must always set a result"); + foreach (IResultsProcessor resultsProcessor in processors) { resultsProcessor.Process(this, ConventionResults); diff --git a/TestStack.ConventionTests/Internal/ResultNotSetException.cs b/TestStack.ConventionTests/Internal/ResultNotSetException.cs new file mode 100644 index 0000000..bbdd762 --- /dev/null +++ b/TestStack.ConventionTests/Internal/ResultNotSetException.cs @@ -0,0 +1,20 @@ +namespace TestStack.ConventionTests.Internal +{ + using System; + using System.Runtime.Serialization; + + [Serializable] + public class ResultNotSetException : Exception + { + public ResultNotSetException() { } + public ResultNotSetException(string message) : base(message) { } + public ResultNotSetException(string message, Exception inner) : base(message, inner) { } + + protected ResultNotSetException( + SerializationInfo info, + StreamingContext context) + : base(info, context) + { + } + } +} \ No newline at end of file diff --git a/TestStack.ConventionTests/TestStack.ConventionTests.csproj b/TestStack.ConventionTests/TestStack.ConventionTests.csproj index 2d6a1b3..9606618 100644 --- a/TestStack.ConventionTests/TestStack.ConventionTests.csproj +++ b/TestStack.ConventionTests/TestStack.ConventionTests.csproj @@ -115,6 +115,7 @@ +