andrewabest / Conventional

A suite of convention specifications for enforcing type and style conventions in your codebase
Microsoft Public License
97 stars 29 forks source link

Support a 'for all assemblies' syntax #41

Closed JackUkleja closed 7 years ago

JackUkleja commented 7 years ago

I want to apply the same assembly convention to all projects in my solution.

Currently the TheAssembly static helper method only supports returning a single Assembly, and in fact throws an exception if you put a wildcard it because it recognises multiple matches.

My current solution was to write code like this:

public void ProjectsMustNotReferenceDllsFromBinOrObjDirectories()
{
    var candidates = Directory.GetFiles(KnownPaths.SolutionRoot, "*.csproj", SearchOption.AllDirectories)
                                        .Select(path => new AssemblySpecimen(path));

    if (candidates.Any() == false)
    {
        throw new ConventionException("Could not locate a project file matching the pattern *.csproj");
    }

    foreach (var asm  in candidates)
    {        
        asm.MustConformTo(Convention.MustNotReferenceDllsFromBinOrObjDirectories).WithFailureAssertion(Assert.Fail);
    }
}

In general it would be great to apply conventions to collections of things.