Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischu committed Jun 5, 2016
2 parents d933fdf + b3e8d5e commit 74b2025
Show file tree
Hide file tree
Showing 45 changed files with 649 additions and 272 deletions.
8 changes: 7 additions & 1 deletion src/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ BuildTask Push-Packages {

BuildTask Create-Archives {
$archivePath = Join-Path $BuildOutputDirectory "SolutionInspector-$AssemblyInformationalVersion.zip"
$sourceDirectory = Join-Path $SolutionDirectory "SolutionInspector\bin\$Configuration"

$buildDirectory = Join-Path $SolutionDirectory "SolutionInspector\bin\$Configuration"
$sourceDirectory = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
New-Item -ItemType Directory -Path $sourceDirectory
Copy-Item -Path "${buildDirectory}\*" -Destination $sourceDirectory -Exclude "Microsoft.Build*.dll","*CodeAnalysisLog.xml","*.lastcodeanalysissucceeded"
Zip-Directory -ZipFilePath $archivePath -SourceDirectory $sourceDirectory
Remove-Item $sourceDirectory -Recurse

Report-Archive $archivePath
}

Expand Down
180 changes: 137 additions & 43 deletions src/SolutionInspector.Api.Tests/Commands/InspectCommandSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#region R# preamble for Machine.Specifications files

#pragma warning disable 414

// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ClassNeverInstantiated.Local
// ReSharper disable InconsistentNaming
Expand All @@ -42,7 +44,8 @@ class InspectCommandSpec

static ISolutionLoader SolutionLoader;
static IRuleCollectionBuilder RuleCollectionBuilder;
static IViolationReporterProxy ViolationReporterProxy;
static IViolationReporter ViolationReporter;
static IViolationReporterFactory ViolationReporterFactory;

static ISolutionInspectorConfiguration Configuration;
static IRulesConfiguration RulesConfiguration;
Expand All @@ -51,6 +54,8 @@ class InspectCommandSpec
static IProjectRule ProjectRule;
static IProjectItemRule ProjectItemRule;

static TextWriter TextWriter;

static InspectCommand SUT;

Establish ctx = () =>
Expand All @@ -77,17 +82,23 @@ class InspectCommandSpec
RulesConfiguration = A.Fake<IRulesConfiguration>();
A.CallTo(() => Configuration.Rules).Returns(RulesConfiguration);

ViolationReporterProxy = A.Fake<IViolationReporterProxy>();
ViolationReporterFactory = A.Fake<IViolationReporterFactory>();

ViolationReporter = A.Fake<IViolationReporter>();
A.CallTo(() => ViolationReporterFactory.CreateConsoleReporter(A<ViolationReportFormat>._)).Returns(ViolationReporter);
A.CallTo(() => ViolationReporterFactory.CreateFileReporter(A<ViolationReportFormat>._, A<string>._)).Returns(ViolationReporter);

TextWriter = new StringWriter();

SUT = new InspectCommand(Configuration, SolutionLoader, RuleCollectionBuilder, ViolationReporterProxy);
SUT = new InspectCommand(Configuration, SolutionLoader, RuleCollectionBuilder, ViolationReporterFactory);
};

class when_running_without_violations
{
Because of = () => Result = RunCommand(SUT, "solution");

Behaves_like<it_executes_the_command_correctly> _;
Behaves_like<it_does_not_call_the_violation_reporter> __;
Behaves_like<it_does_not_create_a_violation_reporter> __;

It returns_exit_code = () =>
Result.Should().Be(0);
Expand All @@ -100,86 +111,143 @@ class when_running_with_violations_without_specifying_report
{
Establish ctx = () =>
{
A.CallTo(() => SolutionRule.Evaluate(A<ISolution>._)).Returns(new[] { new RuleViolation(SolutionRule, Solution, Some.String()) });
A.CallTo(() => ProjectRule.Evaluate(A<IProject>._)).Returns(new[] { new RuleViolation(ProjectRule, Project, Some.String()) });
ExpectedReportFormat = ViolationReportFormat.Xml;
ExpectedViolations = SetupSomeViolations();
};

Because of = () => Result = RunCommand(SUT, "solution");

Behaves_like<it_executes_the_command_correctly> _;
Behaves_like<it_does_not_call_the_violation_reporter> __;
Behaves_like<it_creates_and_calls_a_console_violation_reporter_with_the_expected_format> __;

It returns_exit_code = () =>
Result.Should().Be(1);

protected static string ExpectedConfigurationFile;
protected static ViolationReportFormat ExpectedReportFormat;
protected static IEnumerable<IRuleViolation> ExpectedViolations;
static int Result;
}

class when_running_with_violations_with_table_report
class when_running_with_violations_with_table_report_to_console
{
Establish ctx = () =>
{
SolutionRuleViolation = new RuleViolation(SolutionRule, Solution, Some.String());
A.CallTo(() => SolutionRule.Evaluate(A<ISolution>._)).Returns(new[] { SolutionRuleViolation });

ProjectRuleViolation = new RuleViolation(ProjectRule, Project, Some.String());
A.CallTo(() => ProjectRule.Evaluate(A<IProject>._)).Returns(new[] { ProjectRuleViolation });
ExpectedReportFormat = ViolationReportFormat.Table;
ExpectedViolations = SetupSomeViolations();
};

Because of = () => Result = RunCommand(SUT, "--report=Table", "solution");
Because of = () => Result = RunCommand(SUT, $"--reportFormat={ExpectedReportFormat}", "solution");

Behaves_like<it_executes_the_command_correctly> _;

It calls_the_violation_reporter = () =>
A.CallTo(
() =>
ViolationReporterProxy.Report(
ViolationReportFormat.Table,
A<IEnumerable<IRuleViolation>>.That.IsSameSequenceAs(new[] { SolutionRuleViolation, ProjectRuleViolation })))
.MustHaveHappened();
Behaves_like<it_creates_and_calls_a_console_violation_reporter_with_the_expected_format> __;

It returns_exit_code = () =>
Result.Should().Be(1);

protected static string ExpectedConfigurationFile;
static RuleViolation SolutionRuleViolation;
static RuleViolation ProjectRuleViolation;
protected static ViolationReportFormat ExpectedReportFormat;
protected static IEnumerable<IRuleViolation> ExpectedViolations;
static int Result;
}

class when_running_with_violations_with_xml_report
class when_running_with_violations_with_table_report_to_file
{
Establish ctx = () =>
{
SolutionRuleViolation = new RuleViolation(SolutionRule, Solution, Some.String());
A.CallTo(() => SolutionRule.Evaluate(A<ISolution>._)).Returns(new[] { SolutionRuleViolation });
ExpectedReportFormat = ViolationReportFormat.Table;
ExpectedFilePath = "SomeFile.log";
ExpectedViolations = SetupSomeViolations();
};

Because of = () => Result = RunCommand(SUT, $"--reportFormat={ExpectedReportFormat}", $"--reportOutputFile={ExpectedFilePath}", "solution");

Behaves_like<it_executes_the_command_correctly> _;
Behaves_like<it_creates_and_calls_a_file_violation_reporter_with_the_expected_format> __;

It returns_exit_code = () =>
Result.Should().Be(1);

protected static string ExpectedConfigurationFile;
protected static ViolationReportFormat ExpectedReportFormat;
protected static string ExpectedFilePath;
protected static IEnumerable<IRuleViolation> ExpectedViolations;
static int Result;
}

ProjectRuleViolation = new RuleViolation(ProjectRule, Project, Some.String());
A.CallTo(() => ProjectRule.Evaluate(A<IProject>._)).Returns(new[] { ProjectRuleViolation });
class when_running_with_violations_with_xml_report_to_console
{
Establish ctx = () =>
{
ExpectedReportFormat = ViolationReportFormat.Xml;
ExpectedViolations = SetupSomeViolations();
};

Because of = () => Result = RunCommand(SUT, "--report=Xml", "solution");
Because of = () => Result = RunCommand(SUT, $"-f {ExpectedReportFormat}", "solution");

Behaves_like<it_executes_the_command_correctly> _;
Behaves_like<it_creates_and_calls_a_console_violation_reporter_with_the_expected_format> __;

It returns_exit_code = () =>
Result.Should().Be(1);

protected static string ExpectedConfigurationFile;
protected static ViolationReportFormat ExpectedReportFormat;
protected static IEnumerable<IRuleViolation> ExpectedViolations;
static int Result;
}

class when_running_with_violations_with_xml_report_to_file
{
Establish ctx = () =>
{
ExpectedReportFormat = ViolationReportFormat.Xml;
ExpectedFilePath = "SomeFile.log";
ExpectedViolations = SetupSomeViolations();
};

It calls_the_violation_reporter = () =>
A.CallTo(
() =>
ViolationReporterProxy.Report(
ViolationReportFormat.Xml,
A<IEnumerable<IRuleViolation>>.That.IsSameSequenceAs(new[] { SolutionRuleViolation, ProjectRuleViolation })))
.MustHaveHappened();
Because of = () => Result = RunCommand(SUT, $"--reportFormat={ExpectedReportFormat}", $"-o {ExpectedFilePath}", "solution");

Behaves_like<it_executes_the_command_correctly> _;
Behaves_like<it_creates_and_calls_a_file_violation_reporter_with_the_expected_format> __;

It returns_exit_code = () =>
Result.Should().Be(1);

protected static string ExpectedConfigurationFile;
static RuleViolation SolutionRuleViolation;
static RuleViolation ProjectRuleViolation;
protected static ViolationReportFormat ExpectedReportFormat;
protected static string ExpectedFilePath;
protected static IEnumerable<IRuleViolation> ExpectedViolations;
static int Result;
}

class when_running_with_invalid_report_format
{
Because of = () => Result = RunCommand(SUT, "--reportFormat=DOES_NOT_EXIST");

It shows_error = () =>
TextWriter.ToString().Should().Contain("Could not convert string `DOES_NOT_EXIST' to type ViolationReportFormat");

It returns_exit_code = () =>
Result.Should().Be(-1);

static int Result;
}

static IEnumerable<IRuleViolation> SetupSomeViolations ()
{
var solutionRuleViolation = new RuleViolation(SolutionRule, Solution, Some.String());
A.CallTo(() => SolutionRule.Evaluate(A<ISolution>._)).Returns(new[] { solutionRuleViolation });

var projectRuleViolation = new RuleViolation(ProjectRule, Project, Some.String());
A.CallTo(() => ProjectRule.Evaluate(A<IProject>._)).Returns(new[] { projectRuleViolation });

var projectItemRuleViolation = new RuleViolation(ProjectItemRule, ProjectItem, Some.String());
A.CallTo(() => ProjectItemRule.Evaluate(A<IProjectItem>._)).Returns(new[] { projectItemRuleViolation });

return new[] { solutionRuleViolation, projectRuleViolation, projectItemRuleViolation };
}

[Behaviors]
class it_executes_the_command_correctly
{
Expand All @@ -202,15 +270,41 @@ class it_executes_the_command_correctly
}

[Behaviors]
class it_does_not_call_the_violation_reporter
class it_does_not_create_a_violation_reporter
{
It does_not_create_a_violation_reporter = () => A.CallTo(ViolationReporterFactory).MustNotHaveHappened();
}

[Behaviors]
class it_creates_and_calls_a_file_violation_reporter_with_the_expected_format
{
It does_not_call_the_violation_reporter = () =>
A.CallTo(() => ViolationReporterProxy.Report(A<ViolationReportFormat>._, A<IEnumerable<RuleViolation>>._)).MustNotHaveHappened();
It creates_a_file_violation_reporter_with_the_expected_format = () =>
A.CallTo(() => ViolationReporterFactory.CreateFileReporter(ExpectedReportFormat, ExpectedFilePath)).MustHaveHappened();

It calls_the_file_violation_reporter = () =>
A.CallTo(() => ViolationReporter.Report(A<IEnumerable<IRuleViolation>>.That.IsSameSequenceAs(ExpectedViolations))).MustHaveHappened();

protected static ViolationReportFormat ExpectedReportFormat;
protected static string ExpectedFilePath;
protected static IEnumerable<IRuleViolation> ExpectedViolations;
}

[Behaviors]
class it_creates_and_calls_a_console_violation_reporter_with_the_expected_format
{
It creates_a_file_violation_reporter_with_the_expected_format = () =>
A.CallTo(() => ViolationReporterFactory.CreateConsoleReporter(ExpectedReportFormat)).MustHaveHappened();

It calls_the_file_violation_reporter = () =>
A.CallTo(() => ViolationReporter.Report(A<IEnumerable<IRuleViolation>>.That.IsSameSequenceAs(ExpectedViolations))).MustHaveHappened();

protected static ViolationReportFormat ExpectedReportFormat;
protected static IEnumerable<IRuleViolation> ExpectedViolations;
}

static int RunCommand (ConsoleCommand command, params string[] arguments)
{
return ConsoleCommandDispatcher.DispatchCommand(command, arguments, TextWriter.Null);
return ConsoleCommandDispatcher.DispatchCommand(command, arguments, TextWriter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Machine.Specifications;
using SolutionInspector.Api.ObjectModel;
using SolutionInspector.Api.Rules;
using SolutionInspector.TestInfrastructure.AssertionExtensions;

#region R# preamble for Machine.Specifications files

Expand Down Expand Up @@ -72,8 +73,7 @@ class when_evaluating_a_project_without_configuration_and_reportViolationOnMissi
() => Result = SUT.Evaluate(Project);

It returns_violation = () =>
Result.ShouldAllBeEquivalentTo(
new RuleViolation(SUT, Project, "For the project 'Project' no configuration file could be found."));
Result.ShouldAllBeLike(new RuleViolation(SUT, Project, "For the project 'Project' no configuration file could be found."));

static IEnumerable<IRuleViolation> Result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/SolutionInspector.Api.Tests/ObjectModel/ProjectSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class when_loading_empty_project
Result.TargetFrameworkVersion.Should().Be(Version.Parse("4.6.1"));
Result.Identifier.Should().Be($"{ProjectName}.csproj");
Result.FullPath.Should().Be(projectPath);
Result.BuildConfigurations.ShouldAllBeEquivalentTo(new BuildConfiguration("Debug", "AnyCPU"), new BuildConfiguration("Release", "AnyCPU"));
Result.BuildConfigurations.ShouldAllBeLike(new BuildConfiguration("Debug", "AnyCPU"), new BuildConfiguration("Release", "AnyCPU"));
};

It parses_unconditional_properties = () =>
Expand Down Expand Up @@ -259,7 +259,7 @@ class when_loading_project_with_references
var packagesConfigPath = Path.Combine(Path.GetDirectoryName(projectPath).AssertNotNull(), "packages.config");
Result.NuGetPackagesFile.FullName.Should().Be(packagesConfigPath);

Result.NuGetPackages.ShouldAllBeEquivalentTo(ReferencedNuGetPackage1, ReferencedNuGetPackage2);
Result.NuGetPackages.ShouldAllBeLike(ReferencedNuGetPackage1, ReferencedNuGetPackage2);
};

It parses_project_references = () =>
Expand Down
8 changes: 2 additions & 6 deletions src/SolutionInspector.Api.Tests/ObjectModel/SolutionSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using SolutionInspector.Api.Configuration.MsBuildParsing;
using SolutionInspector.Api.Extensions;
using SolutionInspector.Api.ObjectModel;
using SolutionInspector.TestInfrastructure.AssertionExtensions;

#region R# preamble for Machine.Specifications files

Expand Down Expand Up @@ -50,12 +51,7 @@ class when_loading
{
Result.Name.Should().Be("TestSolution");
Result.SolutionDirectory.FullName.Should().Be(Path.GetDirectoryName(SolutionPath));
Result.BuildConfigurations.ShouldAllBeEquivalentTo(
new[]
{
new BuildConfiguration("Debug", "Any CPU"),
new BuildConfiguration("Release", "Any CPU")
});
Result.BuildConfigurations.ShouldAllBeLike(new BuildConfiguration("Debug", "Any CPU"), new BuildConfiguration("Release", "Any CPU"));
Result.Projects.Single().Name.Should().Be("EmptyProject");
Result.Identifier.Should().Be("TestSolution.sln");
Result.FullPath.Should().Be(SolutionPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<HintPath>..\packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.4\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NullGuard, Version=1.4.6.0, Culture=neutral, PublicKeyToken=1958ac8092168428, processorArchitecture=MSIL">
<HintPath>..\packages\NullGuard.Fody.1.4.6\lib\dotnet\NullGuard.dll</HintPath>
<Private>False</Private>
Expand Down
1 change: 1 addition & 0 deletions src/SolutionInspector.Api.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<package id="Machine.Specifications" version="0.9.3" targetFramework="net452" />
<package id="ManyConsole" version="0.4.2.19" targetFramework="net452" />
<package id="NDesk.Options" version="0.2.1" targetFramework="net452" />
<package id="NLog" version="4.3.4" targetFramework="net452" />
<package id="NullGuard.Fody" version="1.4.6" targetFramework="net452" developmentDependency="true" />
<package id="System.Runtime" version="4.0.0" targetFramework="net452" />
<package id="SystemWrapper.Interfaces" version="0.11.0.49" targetFramework="net452" />
Expand Down
2 changes: 2 additions & 0 deletions src/SolutionInspector.Api/App.config.install.xdt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<!-- Example: <import path="Directory" /> -->
</ruleAssemblyImports>
<msBuildParsing>
<!-- Since MSBuild does provide no way to identify actual project items from references it is necessary to list the types of project items
here. In most cases this configuration does not have to be changed. -->
<projectBuildActions>
<projectBuildAction name="None" />
<projectBuildAction name="Compile" />
Expand Down
Loading

0 comments on commit 74b2025

Please sign in to comment.