Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Passed: 'Header' for 'Fake data'
--------------------------------
'Header' for 'Fake data'
------------------------

With approved exceptions:
Approved Exception
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
collection,item,can add,can remove
TestAssembly.Collections.Branch,TestAssembly.Collections.Leaf,False,False
TestAssembly.Collections.Forest,TestAssembly.Collections.Tree,True,True
TestAssembly.Collections.Tree,TestAssembly.Collections.Branch,True,False
TestAssembly.Collections.Tree,TestAssembly.Collections.Leaf,False,False
4 changes: 2 additions & 2 deletions TestStack.ConventionTests.Tests/CsvReportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
using NUnit.Framework;
using TestAssembly.Collections;
using TestStack.ConventionTests.ConventionData;
using TestStack.ConventionTests.Reporting;
using TestStack.ConventionTests.Tests.TestConventions;

[UseReporter(typeof(DiffReporter))]
public class CsvReportTests
{
[Test]
[Explicit("This is work in progress so ignoring for now")]
public void Can_run_convention_with_simple_reporter()
{
Convention.IsWithApprovedExeptions(new CollectionsRelationsConvention(), new Types("Entities")
{
TypesToVerify =
typeof (Leaf).Assembly.GetExportedTypes()
.Where(t => t.Namespace == typeof (Leaf).Namespace).ToArray()
});
}, new CsvReporter());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Failed: 'Project must not reference dlls from bin or obj directories' for 'TestStack.ConventionTests.Tests'
-----------------------------------------------------------------------------------------------------------
'Project must not reference dlls from bin or obj directories' for 'TestStack.ConventionTests.Tests'
---------------------------------------------------------------------------------------------------

bin\Debug\ApprovalTests.dll
bin\Debug\ApprovalTests.dll
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Passed: 'Project must not reference dlls from bin or obj directories' for 'TestStack.ConventionTests.Tests'
-----------------------------------------------------------------------------------------------------------
'Project must not reference dlls from bin or obj directories' for 'TestStack.ConventionTests.Tests'
---------------------------------------------------------------------------------------------------

With approved exceptions:
bin\Debug\ApprovalTests.dll
bin\Debug\ApprovalTests.dll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Failed: '.sql Files must be embedded resources' for 'TestStack.ConventionTests.Tests'
-------------------------------------------------------------------------------------
'.sql Files must be embedded resources' for 'TestStack.ConventionTests.Tests'
-----------------------------------------------------------------------------

Scripts\Script2.sql
Scripts\Script2.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Passed: '.sql Files must be embedded resources' for 'TestStack.ConventionTests.Tests'
-------------------------------------------------------------------------------------
'.sql Files must be embedded resources' for 'TestStack.ConventionTests.Tests'
-----------------------------------------------------------------------------

With approved exceptions:
Scripts\Script2.sql
Scripts\Script2.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Failed: 'Types must have a default constructor' for 'nHibernate Entitites'
--------------------------------------------------------------------------
'Types must have a default constructor' for 'nHibernate Entitites'
------------------------------------------------------------------

TestAssembly.ClassWithNoDefaultCtor
TestAssembly.ClassWithPrivateDefaultCtor
TestAssembly.ClassWithPrivateDefaultCtor
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Passed: 'Types must have a default constructor' for 'nHibernate Entitites'
--------------------------------------------------------------------------
'Types must have a default constructor' for 'nHibernate Entitites'
------------------------------------------------------------------

With approved exceptions:
TestAssembly.ClassWithNoDefaultCtor
TestAssembly.ClassWithPrivateDefaultCtor
TestAssembly.ClassWithPrivateDefaultCtor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Failed: 'Methods must be virtual' for 'nHibernate Entitites'
------------------------------------------------------------
'Methods must be virtual' for 'nHibernate Entitites'
----------------------------------------------------

TestAssembly.SampleDomainClass.TestNonVirtual
TestAssembly.SampleDomainClass.TestNonVirtual
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Passed: 'Methods must be virtual' for 'nHibernate Entitites'
------------------------------------------------------------
'Methods must be virtual' for 'nHibernate Entitites'
----------------------------------------------------

With approved exceptions:
TestAssembly.SampleDomainClass.TestNonVirtual
TestAssembly.SampleDomainClass.TestNonVirtual
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Failed: 'Dtos must be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
---------------------------------------------------------------------------------------
'Dtos must be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
-------------------------------------------------------------------------------

TestAssembly.SomeDto

'Non-Dtos must not be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
---------------------------------------------------------------------------------------

Failed: 'Non-Dtos must not be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
-----------------------------------------------------------------------------------------------

TestAssembly.Dtos.AnotherClass
TestAssembly.Dtos.AnotherClass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'Non-Dtos must not be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
---------------------------------------------------------------------------------------

TestAssembly.Dtos.AnotherClass
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
Passed: 'Dtos must be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
---------------------------------------------------------------------------------------
'Dtos must be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
-------------------------------------------------------------------------------

With approved exceptions:
TestAssembly.SomeDto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have lost the reporting of the second convention failing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. It's split into a second file now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice





Passed: 'Non-Dtos must not be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
-----------------------------------------------------------------------------------------------

With approved exceptions:
TestAssembly.Dtos.AnotherClass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'Non-Dtos must not be under the 'TestAssembly.Dtos' namespace' for 'TestAssembly types'
---------------------------------------------------------------------------------------

TestAssembly.Dtos.AnotherClass
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the second file :)

87 changes: 36 additions & 51 deletions TestStack.ConventionTests/Convention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using ApprovalTests;
using ApprovalTests.Core.Exceptions;
using TestStack.ConventionTests.Internal;
using TestStack.ConventionTests.Reporting;

public static class Convention
{
static readonly HtmlReportRenderer HtmlRenderer = new HtmlReportRenderer(AssemblyDirectory);
static readonly List<ConventionResult> Reports = new List<ConventionResult>();

static Convention()
{
Expand All @@ -22,72 +19,60 @@ static Convention()
new ProjectReferenceFormatter(),
new ProjectFileFormatter(),
new MethodInfoDataFormatter(),
new StringDataFormatter()
new StringDataFormatter(),
new ConvertibleFormatter(),
new FallbackFormatter()
};
}

public static IEnumerable<ConventionResult> ConventionReports { get { return Reports; } }
public static IList<IReportDataFormatter> Formatters { get; set; }
public static IList<IReportDataFormatter> Formatters { get; set; }

public static void Is<TDataSource>(IConvention<TDataSource> convention, TDataSource data)
where TDataSource : IConventionData
static string AssemblyDirectory
{
Is(convention, data, new ConventionResultExceptionReporter());
get
{
// http://stackoverflow.com/questions/52797/c-how-do-i-get-the-path-of-the-assembly-the-code-is-in#answer-283917
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
var path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}

public static void Is<TDataSource>(IConvention<TDataSource> convention, TDataSource data, IConventionReportRenderer reporter)
public static void Is<TDataSource>(IConvention<TDataSource> convention, TDataSource data,
params IResultsProcessor[] extraResultProcessors)
where TDataSource : IConventionData
{
try
var processors = new List<IResultsProcessor>(extraResultProcessors)
{
var context = new ConventionContext(data.Description, Formatters);
var conventionResult = context.GetConventionResults(convention, data);
Reports.AddRange(conventionResult);

new ConventionReportTraceRenderer().Render(conventionResult);
reporter.Render(conventionResult);
}
finally
{
HtmlRenderer.Render(Reports.ToArray());
}
new ConventionReportTextRenderer(),
HtmlRenderer,
new ConventionReportTraceRenderer(),
new ThrowOnFailureResultsProcessor()
};
Execute(convention, data, processors.ToArray());
}

public static void IsWithApprovedExeptions<TDataSource>(IConvention<TDataSource> convention, TDataSource data)
static void Execute<TDataSource>(IConvention<TDataSource> convention, TDataSource data,
IResultsProcessor[] processors)
where TDataSource : IConventionData
{
var context = new ConventionContext(data.Description, Formatters);
var conventionResult = context.GetConventionResultsWithApprovedExeptions(convention, data);
Reports.AddRange(conventionResult);

try
{
var conventionReportTextRenderer = new ConventionReportTextRenderer();
conventionReportTextRenderer.Render(conventionResult);
Approvals.Verify(conventionReportTextRenderer.Output);

new ConventionReportTraceRenderer().Render(conventionResult);
}
catch (ApprovalException ex)
{
throw new ConventionFailedException("Approved exceptions for convention differs\r\n\r\n"+ex.Message, ex);
}
finally
{
HtmlRenderer.Render(Reports.ToArray());
}
var context = new ConventionContext(data.Description, Formatters, processors);
context.Execute(convention, data);
}

// http://stackoverflow.com/questions/52797/c-how-do-i-get-the-path-of-the-assembly-the-code-is-in#answer-283917
static string AssemblyDirectory
public static void IsWithApprovedExeptions<TDataSource>(IConvention<TDataSource> convention, TDataSource data,
params IResultsProcessor[] extraResultProcessors)
where TDataSource : IConventionData
{
get
var processors = new List<IResultsProcessor>(extraResultProcessors)
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
new ConventionReportTextRenderer(),
HtmlRenderer,
new ConventionReportTraceRenderer(),
new ApproveResultsProcessor()
};
Execute(convention, data, processors.ToArray());
}
}
}
Loading