-
Notifications
You must be signed in to change notification settings - Fork 19
Api v2 spike #19
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
Api v2 spike #19
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
28 changes: 4 additions & 24 deletions
28
TestStack.ConventionTests/Conventions/FilesAreEmbeddedResources.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,35 +1,15 @@ | ||
namespace TestStack.ConventionTests.Conventions | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
using TestStack.ConventionTests.Internal; | ||
|
||
public class FilesAreEmbeddedResources : IConvention<Project> | ||
public class FilesAreEmbeddedResources : IConvention<ProjectFiles> | ||
{ | ||
public ConventionResult Execute(Project data) | ||
public ConventionResult Execute(ProjectFiles data) | ||
{ | ||
return ConventionResult.For(GetProjectFiles(data).Where(s => s.Item1 != "EmbeddedResource"), | ||
return ConventionResult.For(data.Files.Where(s => s.ReferenceType != "EmbeddedResource"), | ||
"The following files which should be embedded resources:", | ||
(t, m) => m.AppendLine("\t" + t.Item2)); | ||
} | ||
|
||
IEnumerable<Tuple<string, string>> GetProjectFiles(Project project) | ||
{ | ||
if (project.Includes == null) | ||
throw new InvalidOperationException( | ||
"This convention requires you to provide a filter on the convention data"); | ||
const string msbuild = "http://schemas.microsoft.com/developer/msbuild/2003"; | ||
var projDefinition = project.GetProject(); | ||
var references = projDefinition | ||
.Element(XName.Get("Project", msbuild)) | ||
.Elements(XName.Get("ItemGroup", msbuild)) | ||
.Elements() | ||
.Select(refElem => Tuple.Create(refElem.Name.LocalName, refElem.Attribute("Include").Value)) | ||
.Where(i => project.Includes(i.Item2)); | ||
|
||
return references; | ||
(t, m) => m.AppendLine("\t" + t.FilePath)); | ||
} | ||
} | ||
} |
29 changes: 7 additions & 22 deletions
29
TestStack.ConventionTests/Conventions/ProjectDoesNotReferenceDllsFromBinOrObjDirectories.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,44 +1,29 @@ | ||
namespace TestStack.ConventionTests.Conventions | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Linq; | ||
using TestStack.ConventionTests.Internal; | ||
|
||
public class ProjectDoesNotReferenceDllsFromBinOrObjDirectories : IConvention<Project> | ||
public class ProjectDoesNotReferenceDllsFromBinOrObjDirectories : IConvention<ProjectReferences> | ||
{ | ||
const string AssemblyReferencingObjRegex = @"^(?<assembly>.*?(obj|bin).*?)$"; | ||
|
||
public ConventionResult Execute(Project data) | ||
public ConventionResult Execute(ProjectReferences data) | ||
{ | ||
var projDefinition = data.GetProject(); | ||
var invalid = AllProjectReferences(projDefinition).Where(IsBinOrObjReference); | ||
var invalid = data.References.Where(IsBinOrObjReference); | ||
var header = string.Format("Some invalid assembly references found in {0}", data.Assembly.GetName().Name); | ||
return ConventionResult.For(invalid, header, FormatLine); | ||
} | ||
|
||
void FormatLine(string assemblyReference, StringBuilder m) | ||
void FormatLine(ProjectReference assemblyReference, StringBuilder m) | ||
{ | ||
m.AppendLine("\t" + assemblyReference); | ||
m.AppendLine("\t" + assemblyReference.ReferencedPath); | ||
} | ||
|
||
static bool IsBinOrObjReference(string reference) | ||
static bool IsBinOrObjReference(ProjectReference reference) | ||
{ | ||
return Regex.IsMatch(reference, AssemblyReferencingObjRegex, RegexOptions.IgnoreCase); | ||
} | ||
|
||
static IEnumerable<string> AllProjectReferences(XDocument projDefinition) | ||
{ | ||
XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003"; | ||
var references = projDefinition | ||
.Element(msbuild + "Project") | ||
.Elements(msbuild + "ItemGroup") | ||
.Elements(msbuild + "Reference") | ||
.Elements(msbuild + "HintPath") | ||
.Select(refElem => refElem.Value); | ||
return references; | ||
return Regex.IsMatch(reference.ReferencedPath, AssemblyReferencingObjRegex, RegexOptions.IgnoreCase); | ||
} | ||
} | ||
} |
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,8 @@ | ||
namespace TestStack.ConventionTests.Conventions | ||
{ | ||
public class ProjectFile | ||
{ | ||
public string FilePath { get; set; } | ||
public string ReferenceType { get; set; } | ||
} | ||
} |
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,41 @@ | ||
namespace TestStack.ConventionTests.Conventions | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Xml.Linq; | ||
using TestStack.ConventionTests.Internal; | ||
|
||
public class ProjectFiles : AbstractProjectData | ||
{ | ||
public ProjectFiles(Assembly assembly, IProjectProvider projectProvider, IProjectLocator projectLocator) | ||
: base(assembly, projectProvider, projectLocator) | ||
{ | ||
Items = PredicateHelpers.All<ProjectFile>(); | ||
} | ||
|
||
|
||
public ProjectFile[] Files | ||
{ | ||
get | ||
{ | ||
var project = GetProject(); | ||
const string msbuild = "http://schemas.microsoft.com/developer/msbuild/2003"; | ||
return project | ||
.Element(XName.Get("Project", msbuild)) | ||
.Elements(XName.Get("ItemGroup", msbuild)) | ||
.Elements() | ||
.Select(refElem => | ||
new ProjectFile | ||
{ | ||
ReferenceType = refElem.Name.LocalName, | ||
FilePath = refElem.Attribute("Include").Value | ||
}) | ||
.Where(Items) | ||
.ToArray(); | ||
} | ||
} | ||
|
||
public Func<ProjectFile, bool> Items { get; set; } | ||
} | ||
} |
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,7 @@ | ||
namespace TestStack.ConventionTests.Conventions | ||
{ | ||
public class ProjectReference | ||
{ | ||
public string ReferencedPath { get; set; } | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
TestStack.ConventionTests/Conventions/ProjectReferences.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace TestStack.ConventionTests.Conventions | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Xml.Linq; | ||
using TestStack.ConventionTests.Internal; | ||
|
||
public class ProjectReferences : AbstractProjectData | ||
{ | ||
public ProjectReferences(Assembly assembly, IProjectProvider projectProvider, IProjectLocator projectLocator) | ||
: base(assembly, projectProvider, projectLocator) | ||
{ | ||
Items = PredicateHelpers.All<ProjectReference>(); | ||
} | ||
|
||
public ProjectReference[] References | ||
{ | ||
get | ||
{ | ||
var project = GetProject(); | ||
return AllProjectReferences(project) | ||
.Select(r => new ProjectReference | ||
{ | ||
ReferencedPath = r | ||
}) | ||
.Where(Items) | ||
.ToArray(); | ||
} | ||
} | ||
|
||
static IEnumerable<string> AllProjectReferences(XDocument projDefinition) | ||
{ | ||
XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003"; | ||
var references = projDefinition | ||
.Element(msbuild + "Project") | ||
.Elements(msbuild + "ItemGroup") | ||
.Elements(msbuild + "Reference") | ||
.Elements(msbuild + "HintPath") | ||
.Select(refElem => refElem.Value); | ||
return references; | ||
} | ||
|
||
public Func<ProjectReference, bool> Items { get; set; } | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
{ | ||
public interface IConventionData | ||
{ | ||
void ThrowIfHasInvalidSource(); | ||
void EnsureHasNonEmptySource(); | ||
} | ||
} |
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,17 @@ | ||
namespace TestStack.ConventionTests.Internal | ||
{ | ||
using System; | ||
|
||
public static class PredicateHelpers | ||
{ | ||
public static Func<T, bool> All<T>() | ||
{ | ||
return _ => true; | ||
} | ||
|
||
public static Func<T, bool> None<T>() | ||
{ | ||
return _ => false; | ||
} | ||
} | ||
} |
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
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.
Maybe ItemFilter?
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.
more like
ItemsWhere
...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.
or perhaps just
.Where
...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.
the last one would probably resonate with anyone who has ever written a LINQ query...