Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

(GH-4) Add BinaryLogFileFormat #38

Merged
merged 3 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BuildParameters.PrintParameters(Context);

ToolSettings.SetToolSettings(
context: Context,
dupFinderExcludePattern: new string[] { BuildParameters.RootDirectoryPath + "/src/Cake.Issues.MsBuild.Tests/*.cs", BuildParameters.RootDirectoryPath + "/src/Cake.Issues.MsBuild*/**/*.AssemblyInfo.cs" },
dupFinderExcludePattern: new string[] { BuildParameters.RootDirectoryPath + "/src/Cake.Issues.MsBuild.Tests/**/*.cs", BuildParameters.RootDirectoryPath + "/src/Cake.Issues.MsBuild*/**/*.AssemblyInfo.cs" },
testCoverageFilter: "+[*]* -[xunit.*]* -[Cake.Core]* -[Cake.Testing]* -[*.Tests]* -[Cake.Issues]* -[Cake.Issues.Testing]*",
testCoverageExcludeByAttribute: "*.ExcludeFromCodeCoverage*",
testCoverageExcludeByFile: "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs");
Expand Down
2 changes: 2 additions & 0 deletions src/Cake.Issues.MsBuild.Tests.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<RuleSet Name="Ruleset for Cake.Issues.MsBuild test cases" Description="Rules valid for Cake.Issues.MsBuild test cases" ToolsVersion="14.0">
<Include Path="Cake.Issues.MsBuild.ruleset" Action="Default" />
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1118" Action="None" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1652" Action="None" />
</Rules>
</RuleSet>
338 changes: 338 additions & 0 deletions src/Cake.Issues.MsBuild.Tests/BaseMsBuildLogFileFormatTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
namespace Cake.Issues.MsBuild.Tests
{
using Cake.Issues.Testing;
using Cake.Testing;
using Shouldly;
using Xunit;

public sealed class BaseMsBuildLogFileFormatTests
{
public sealed class TheValidateFilePathMethod
{
[Fact]
public void Should_Throw_If_FilePath_Is_Null()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
string filePath = null;
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.ValidateFilePath(filePath, settings));

// Then
result.IsArgumentNullException("filePath");
}

[Fact]
public void Should_Throw_If_FilePath_Is_Empty()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = string.Empty;
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.ValidateFilePath(filePath, settings));

// Then
result.IsArgumentOutOfRangeException("filePath");
}

[Fact]
public void Should_Throw_If_FilePath_Is_WhiteSpace()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = " ";
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.ValidateFilePath(filePath, settings));

// Then
result.IsArgumentOutOfRangeException("filePath");
}

[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = @"c:\repo\foo.ch";
RepositorySettings settings = null;

// When
var result = Record.Exception(() => format.ValidateFilePath(filePath, settings));

// Then
result.IsArgumentNullException("repositorySettings");
}

[Theory]
[InlineData(@"c:\foo\bar.cs", @"c:\foo\", true)]
[InlineData(@"c:\foo\bar.cs", @"c:\foo", true)]
[InlineData(@"c:\foo\bar.cs", @"c:\bar", false)]
public void Should_Return_Correct_Value_For_Valid(
string filePath,
string repoRoot,
bool expectedValue)
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var settings = new RepositorySettings(repoRoot);

// When
var result = format.ValidateFilePath(filePath, settings);

// Then
result.Valid.ShouldBe(expectedValue);
}

[Theory]
[InlineData(@"c:\foo\bar.cs", @"c:\foo\", @"bar.cs")]
[InlineData(@"c:\foo\bar.cs", @"c:\foo", @"bar.cs")]
[InlineData(@"c:\foo\bar.cs", @"c:\bar", @"")]
public void Should_Return_Correct_Value_For_FilePath(
string filePath,
string repoRoot,
string expectedValue)
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var settings = new RepositorySettings(repoRoot);

// When
var result = format.ValidateFilePath(filePath, settings);

// Then
result.FilePath.ShouldBe(expectedValue);
}
}

public sealed class TheCheckIfFileIsInRepositoryMethod
{
[Fact]
public void Should_Throw_If_FilePath_Is_Null()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
string filePath = null;
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.CheckIfFileIsInRepository(filePath, settings));

// Then
result.IsArgumentNullException("filePath");
}

[Fact]
public void Should_Throw_If_FilePath_Is_Empty()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = string.Empty;
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.CheckIfFileIsInRepository(filePath, settings));

// Then
result.IsArgumentOutOfRangeException("filePath");
}

[Fact]
public void Should_Throw_If_FilePath_Is_WhiteSpace()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = " ";
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.CheckIfFileIsInRepository(filePath, settings));

// Then
result.IsArgumentOutOfRangeException("filePath");
}

[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = @"c:\repo\foo.ch";
RepositorySettings settings = null;

// When
var result = Record.Exception(() => format.CheckIfFileIsInRepository(filePath, settings));

// Then
result.IsArgumentNullException("repositorySettings");
}

[Theory]
[InlineData(@"c:\foo\bar.cs", @"c:\foo\", true)]
[InlineData(@"c:\foo\bar.cs", @"c:\foo", true)]
[InlineData(@"c:\foo\bar.cs", @"c:\bar", false)]
public void Should_Check_If_File_Is_In_Repository(
string filePath,
string repoRoot,
bool expectedValue)
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var settings = new RepositorySettings(repoRoot);

// When
var result = format.CheckIfFileIsInRepository(filePath, settings);

// Then
result.ShouldBe(expectedValue);
}
}

public sealed class TheMakeFilePathRelativeToRepositoryRootMethod
{
[Fact]
public void Should_Throw_If_FilePath_Is_Null()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
string filePath = null;
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.MakeFilePathRelativeToRepositoryRoot(filePath, settings));

// Then
result.IsArgumentNullException("filePath");
}

[Fact]
public void Should_Throw_If_FilePath_Is_Empty()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = string.Empty;
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.MakeFilePathRelativeToRepositoryRoot(filePath, settings));

// Then
result.IsArgumentOutOfRangeException("filePath");
}

[Fact]
public void Should_Throw_If_FilePath_Is_WhiteSpace()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = " ";
var settings = new RepositorySettings(@"c:\repo");

// When
var result = Record.Exception(() => format.MakeFilePathRelativeToRepositoryRoot(filePath, settings));

// Then
result.IsArgumentOutOfRangeException("filePath");
}

[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = @"c:\repo\foo.ch";
RepositorySettings settings = null;

// When
var result = Record.Exception(() => format.MakeFilePathRelativeToRepositoryRoot(filePath, settings));

// Then
result.IsArgumentNullException("repositorySettings");
}

[Theory]
[InlineData(@"c:\foo\bar.cs", @"c:\foo\", @"\bar.cs")]
[InlineData(@"c:\foo\bar.cs", @"c:\foo", @"\bar.cs")]
public void Should_Make_FilePath_Relative_To_Repository_Root(
string filePath,
string repoRoot,
string expectedValue)
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var settings = new RepositorySettings(repoRoot);

// When
var result = format.MakeFilePathRelativeToRepositoryRoot(filePath, settings);

// Then
result.ShouldBe(expectedValue);
}
}

public sealed class TheRemoveLeadingDirectorySeparatorMethod
{
[Fact]
public void Should_Throw_If_FilePath_Is_Null()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
string filePath = null;

// When
var result = Record.Exception(() => format.RemoveLeadingDirectorySeparator(filePath));

// Then
result.IsArgumentNullException("filePath");
}

[Fact]
public void Should_Throw_If_FilePath_Is_Empty()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = string.Empty;

// When
var result = Record.Exception(() => format.RemoveLeadingDirectorySeparator(filePath));

// Then
result.IsArgumentOutOfRangeException("filePath");
}

[Fact]
public void Should_Throw_If_FilePath_Is_WhiteSpace()
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());
var filePath = " ";

// When
var result = Record.Exception(() => format.RemoveLeadingDirectorySeparator(filePath));

// Then
result.IsArgumentOutOfRangeException("filePath");
}

[Theory]
[InlineData(@"\foo\bar.cs", @"foo\bar.cs")]
[InlineData(@"foo\bar.cs", @"foo\bar.cs")]
public void Should_Remove_Leading_Directory_Separator(string filePath, string expectedValue)
{
// Given
var format = new FakeMsBuildLogFileFormat(new FakeLog());

// When
var result = format.RemoveLeadingDirectorySeparator(filePath);

// Then
result.ShouldBe(expectedValue);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Testfiles\FullLog.binlog" />
<None Remove="Testfiles\FullLog.xml" />
<None Remove="Testfiles\IssueWithFile.xml" />
<None Remove="Testfiles\IssueWithLineZero.xml" />
Expand All @@ -24,6 +25,7 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Testfiles\BinaryLogFileFormat\FullLog.binlog" />
<EmbeddedResource Include="Testfiles\XmlFileLoggerLogFileFormat\FullLog.xml" />
<EmbeddedResource Include="Testfiles\XmlFileLoggerLogFileFormat\IssueWithoutCode.xml" />
<EmbeddedResource Include="Testfiles\XmlFileLoggerLogFileFormat\IssueWithFile.xml" />
Expand All @@ -39,7 +41,7 @@
<PackageReference Include="Cake.Issues" Version="0.6.0" />
<PackageReference Include="Cake.Issues.Testing" Version="0.6.0" />
<PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta009" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.2" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
Expand Down
Loading