Skip to content

Fixed issue #38 - should detect when result not set #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions TestStack.ConventionTests.Tests/ConventionFixture.cs
Original file line number Diff line number Diff line change
@@ -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<ResultNotSetException>(() =>
Convention.Is(new CustomConventionWhichDoesNothing(), Types.InAssemblyOf<ConventionFixture>()));
}

// ReSharper disable once UnusedVariable
class CustomConventionWhichDoesNothing : IConvention<Types>
{
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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="Autofac\TestTypes\IBar.cs" />
<Compile Include="Autofac\TestTypes\IFoo.cs" />
<Compile Include="ConventionAssertionClassTests.cs" />
<Compile Include="ConventionFixture.cs" />
<Compile Include="CsvReportTests.cs" />
<Compile Include="MvcConventions.cs" />
<Compile Include="ProjectBasedConventions.cs" />
Expand Down
6 changes: 6 additions & 0 deletions TestStack.ConventionTests/Internal/ConventionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ConventionContext : IConventionResultContext, IConventionFormatCont
readonly IList<IResultsProcessor> processors;
readonly ITestResultProcessor testResultProcessor;
readonly IList<ConventionResult> results = new List<ConventionResult>();
bool resultSet;

public ConventionContext(string dataDescription, IList<IReportDataFormatter> formatters,
IList<IResultsProcessor> processors, ITestResultProcessor testResultProcessor)
Expand Down Expand Up @@ -59,6 +60,7 @@ IReportDataFormatter GetReportDataFormatterFor(object data)

void IConventionResultContext.Is<TResult>(string resultTitle, IEnumerable<TResult> failingData)
{
resultSet = true;
// ReSharper disable PossibleMultipleEnumeration
results.Add(new ConventionResult(
typeof (TResult),
Expand All @@ -71,6 +73,7 @@ void IConventionResultContext.IsSymmetric<TResult>(
string firstSetFailureTitle, IEnumerable<TResult> firstSetFailureData,
string secondSetFailureTitle, IEnumerable<TResult> secondSetFailureData)
{
resultSet = true;
results.Add(new ConventionResult(
typeof (TResult), firstSetFailureTitle,
dataDescription,
Expand Down Expand Up @@ -103,6 +106,9 @@ public void Execute<TDataSource>(IConvention<TDataSource> 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);
Expand Down
20 changes: 20 additions & 0 deletions TestStack.ConventionTests/Internal/ResultNotSetException.cs
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
}
1 change: 1 addition & 0 deletions TestStack.ConventionTests/TestStack.ConventionTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<Compile Include="Reporting\TestResult.cs" />
<Compile Include="Reporting\StringDataFormatter.cs" />
<Compile Include="Reporting\TypeDataFormatter.cs" />
<Compile Include="Internal\ResultNotSetException.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down