Skip to content

Commit dfcec58

Browse files
committed
Merge pull request #46 from JakeGinnivan/AddedConventionReason
Adds convention reason to conventions, useful for the living documentati...
2 parents 1caea05 + d6ecde1 commit dfcec58

18 files changed

+77
-11
lines changed

TestStack.ConventionTests.Autofac/CanResolveAllRegisteredServices.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace TestStack.ConventionTests.Autofac
22
{
3+
using global::Autofac;
4+
using global::Autofac.Core;
35
using System;
46
using System.Collections.Generic;
57
using System.Linq;
6-
using global::Autofac;
7-
using global::Autofac.Core;
88

99
public class CanResolveAllRegisteredServices : IConvention<AutofacRegistrations>
1010
{
@@ -37,6 +37,14 @@ public void Execute(AutofacRegistrations data, IConventionResultContext result)
3737
result.Is("Can resolve all types registered with Autofac", failingTypes);
3838
}
3939

40+
public string ConventionReason
41+
{
42+
get
43+
{
44+
return "Container resolution failings are runtime exceptions, this convention allows you to detect missing registrations faster!";
45+
}
46+
}
47+
4048
private IEnumerable<Type> GetGenericFactoryTypes(AutofacRegistrations data, IComponentRegistration componentRegistration)
4149
{
4250
return from ctorParameter in data.GetRegistrationCtorParameters(componentRegistration)

TestStack.ConventionTests.Autofac/ServicesShouldOnlyHaveDependenciesWithLesserLifetime.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace TestStack.ConventionTests.Autofac
22
{
3-
using System.Collections.Generic;
43
using global::Autofac.Core;
4+
using System.Collections.Generic;
55
using TestStack.ConventionTests.ConventionData;
66

77
public class ServicesShouldOnlyHaveDependenciesWithLesserLifetime : IConvention<AutofacRegistrations>
@@ -37,5 +37,10 @@ public void Execute(AutofacRegistrations data, IConventionResultContext result)
3737

3838
result.Is("Components should not depend on with greater lifetimes", exceptions);
3939
}
40+
41+
public string ConventionReason
42+
{
43+
get { return @"When classes with larger lifetimes depend on classes with smaller lifetimes this often indicates an error and can lead to subtle bugs"; }
44+
}
4045
}
4146
}

TestStack.ConventionTests.Tests/ConventionAssertionClassTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public void Execute(FakeData data, IConventionResultContext result)
3131
{
3232
result.Is("Header", new[] {"Different"});
3333
}
34+
35+
public string ConventionReason
36+
{
37+
get { return "Because fail.."; }
38+
}
3439
}
3540
}
3641
}

TestStack.ConventionTests.Tests/ConventionFixture.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public void Execute(Types data, IConventionResultContext result)
2525
// Oops, I forgot to set the result
2626
}
2727

28+
public string ConventionReason { get { return "Convention does not set result for testing"; } }
29+
2830
bool IsBroken(Type type)
2931
{
3032
return true;

TestStack.ConventionTests.Tests/TestConventions/CollectionsRelationsConvention.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ from item in GetItemTypes(collection)
2929
result.Is("Some title", collectionToItemLookup);
3030
}
3131

32+
public string ConventionReason
33+
{
34+
get { return "Test convention"; }
35+
}
36+
3237
IEnumerable<Type> GetItemTypes(Type type)
3338
{
3439
return from @interface in type.GetInterfaces()

TestStack.ConventionTests/Convention.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Reflection;
6-
using System.Text.RegularExpressions;
76
using TestStack.ConventionTests.ConventionData;
87
using TestStack.ConventionTests.Internal;
98
using TestStack.ConventionTests.Reporting;

TestStack.ConventionTests/Conventions/AllClassesHaveDefaultConstructor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ public void Execute(Types data, IConventionResultContext result)
1010
result.Is("Types must have a default constructor",
1111
data.TypesToVerify.Where(t => t.HasDefaultConstructor() == false));
1212
}
13+
14+
public string ConventionReason
15+
{
16+
get { return "This convention is useful when classes need to be proxied (nHibernate/Entity Framework entities), which need a public or protected constructor"; }
17+
}
1318
}
1419
}

TestStack.ConventionTests/Conventions/AllMethodsAreVirtual.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ public void Execute(Types data, IConventionResultContext result)
99
{
1010
result.Is("Methods must be virtual", data.TypesToVerify.SelectMany(t => t.NonVirtualMethods()));
1111
}
12+
13+
public string ConventionReason
14+
{
15+
get { return "This convention is useful when classes need to be proxied (nHibernate entities), which need members to be virtual"; }
16+
}
1217
}
1318
}

TestStack.ConventionTests/Conventions/ClassTypeHasSpecificNamespace.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public void Execute(Types data, IConventionResultContext result)
4141
data.TypesToVerify);
4242
}
4343

44+
public string ConventionReason
45+
{
46+
get { return "To simplify project structure and allow developers to know where this type of class should live in the project"; }
47+
}
48+
4449
bool TypeLivesInSpecifiedNamespace(Type t)
4550
{
4651
return t.Namespace == null || t.Namespace.StartsWith(namespaceToCheck);

TestStack.ConventionTests/Conventions/FilesAreEmbeddedResources.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ public void Execute(ProjectFileItems data, IConventionResultContext result)
1818
string.Format("{0} Files must be embedded resources", FileExtension),
1919
data.Items.Where(s => s.FilePath.EndsWith(FileExtension) && s.ReferenceType != "EmbeddedResource"));
2020
}
21+
22+
public string ConventionReason { get { return "Many files are added as 'Content' to visual studio projects, this convention enforces files with an extension are correctly set as Embedded Resources"; } }
2123
}
2224
}

0 commit comments

Comments
 (0)