-
Notifications
You must be signed in to change notification settings - Fork 19
Reporting2 #24
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
Closed
Closed
Reporting2 #24
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7774e4e
brought back ConventionResult
kkozmic d5f4e0d
using ConventionResult again
kkozmic c62f0b4
introduced IConventionResult
kkozmic 4633621
added abstract base Convention class
kkozmic 0043906
got symmetric conventions working again
kkozmic 587c68b
moving away from using static state
kkozmic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace TestStack.ConventionTests | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public abstract class Convention<TData> : IConvention<TData> where TData : IConventionData | ||
{ | ||
public abstract string ConventionTitle { get; } | ||
|
||
public virtual void Execute(TData data, IConventionResult result) | ||
{ | ||
result.Is(Execute(data)); | ||
} | ||
|
||
protected virtual IEnumerable<object> Execute(TData data) | ||
{ | ||
throw new NotImplementedException("You need to overwrite the Execute method"); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 20 additions & 33 deletions
53
TestStack.ConventionTests/Conventions/ClassTypeHasSpecificNamespace.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,53 @@ | ||
namespace TestStack.ConventionTests.Conventions | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using TestStack.ConventionTests.ConventionData; | ||
|
||
/// <summary> | ||
/// This convention allows you to enforce a particular type of class is under a namespace, for instance. | ||
/// | ||
/// Dto must be under App.Contracts.Dtos | ||
/// Domain Objects must be under App.Domain | ||
/// Event Handlers must be under App.Handlers | ||
/// | ||
/// This is a Symmetric convention, and will verify all of a Class Type lives in the namespace, but also that only that class type is in that namespace | ||
/// This convention allows you to enforce a particular type of class is under a namespace, for instance. | ||
/// Dto must be under App.Contracts.Dtos | ||
/// Domain Objects must be under App.Domain | ||
/// Event Handlers must be under App.Handlers | ||
/// This is a Symmetric convention, and will verify all of a Class Type lives in the namespace, but also that only that | ||
/// class type is in that namespace | ||
/// </summary> | ||
public class ClassTypeHasSpecificNamespace : ISymmetricConvention<Types> | ||
public class ClassTypeHasSpecificNamespace : IConvention<Types> | ||
{ | ||
readonly Func<Type, bool> classIsApplicable; | ||
readonly string namespaceToCheck; | ||
readonly string classType; | ||
readonly string namespaceToCheck; | ||
|
||
/// <summary> | ||
/// Ctor | ||
/// Ctor | ||
/// </summary> | ||
/// <param name="classIsApplicable">Predicate to verify if the class is the right type</param> | ||
/// <param name="namespaceToCheck"></param> | ||
/// <param name="classType">The class type. ie, Dto, Domain Object, Event Handler</param> | ||
public ClassTypeHasSpecificNamespace(Func<Type, bool> classIsApplicable, string namespaceToCheck, string classType) | ||
public ClassTypeHasSpecificNamespace(Func<Type, bool> classIsApplicable, string namespaceToCheck, | ||
string classType) | ||
{ | ||
this.classIsApplicable = classIsApplicable; | ||
this.namespaceToCheck = namespaceToCheck; | ||
this.classType = classType; | ||
} | ||
|
||
public string ConventionTitle | ||
{ | ||
get | ||
{ | ||
return string.Format("{0}s must be under the '{1}' namespace", classType, namespaceToCheck); | ||
} | ||
} | ||
|
||
public string InverseTitle | ||
{ | ||
get | ||
{ | ||
return string.Format("Non-{0}s must not be under the '{1}' namespace", classType, namespaceToCheck); | ||
} | ||
get { return string.Format("Non-{0}s must not be under the '{1}' namespace", classType, namespaceToCheck); } | ||
} | ||
|
||
public IEnumerable<object> GetFailingData(Types data) | ||
public string ConventionTitle | ||
{ | ||
return data.TypesToVerify | ||
.Where(classIsApplicable) | ||
.Where(t => t.Namespace == null || !t.Namespace.StartsWith(namespaceToCheck)); | ||
get { return string.Format("{0}s must be under the '{1}' namespace", classType, namespaceToCheck); } | ||
} | ||
|
||
public IEnumerable<object> GetFailingInverseData(Types data) | ||
public void Execute(Types data, IConventionResult result) | ||
{ | ||
return data.TypesToVerify | ||
.Where(t => !classIsApplicable(t)) | ||
.Where(t => t.Namespace != null && t.Namespace.StartsWith(namespaceToCheck)); | ||
result.IsSymmetric(data.TypesToVerify, | ||
classIsApplicable, | ||
t => t.Namespace != null && t.Namespace.StartsWith(namespaceToCheck), | ||
ConventionTitle, | ||
InverseTitle); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recon get rid of this, I would prefer that we just use result.Is for all conventions and not try to put this in for compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough