Skip to content

Commit

Permalink
(cake-contribGH-25) Update to Cake.Issues 0.5.0-beta.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Aug 7, 2018
1 parent 7a44d31 commit dc0ac62
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 179 deletions.
8 changes: 4 additions & 4 deletions src/Cake.Issues.DocFx.Tests/Cake.Issues.DocFx.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
<Reference Include="Cake.Core, Version=0.28.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Core.0.28.0\lib\net46\Cake.Core.dll</HintPath>
</Reference>
<Reference Include="Cake.Issues, Version=0.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Issues.0.4.0\lib\netstandard2.0\Cake.Issues.dll</HintPath>
<Reference Include="Cake.Issues, Version=0.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Issues.0.5.0-beta0002\lib\netstandard2.0\Cake.Issues.dll</HintPath>
</Reference>
<Reference Include="Cake.Issues.Testing, Version=0.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Issues.Testing.0.4.0\lib\netstandard2.0\Cake.Issues.Testing.dll</HintPath>
<Reference Include="Cake.Issues.Testing, Version=0.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Issues.Testing.0.5.0-beta0002\lib\netstandard2.0\Cake.Issues.Testing.dll</HintPath>
</Reference>
<Reference Include="Cake.Testing, Version=0.28.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Testing.0.28.0\lib\net46\Cake.Testing.dll</HintPath>
Expand Down
45 changes: 13 additions & 32 deletions src/Cake.Issues.DocFx.Tests/DocFxProviderFixture.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,30 @@
namespace Cake.Issues.DocFx.Tests
{
using System.Collections.Generic;
using System.IO;
using Cake.Testing;
using Core.Diagnostics;
using Core.IO;
using Cake.Core.IO;
using Cake.Issues.Testing;

internal class DocFxProviderFixture
internal class DocFxProviderFixture : BaseConfigurableIssueProviderFixture<DocFxIssuesProvider, DocFxIssuesSettings>
{
private readonly DirectoryPath docRootPath;

public DocFxProviderFixture(string fileResourceName, DirectoryPath docRootPath)
: base(fileResourceName)
{
this.Log = new FakeLog { Verbosity = Verbosity.Normal };

using (var stream = this.GetType().Assembly.GetManifestResourceStream("Cake.Issues.DocFx.Tests.Testfiles." + fileResourceName))
{
using (var sr = new StreamReader(stream))
{
this.DocFxIssuesSettings =
DocFxIssuesSettings.FromContent(
sr.ReadToEnd(),
docRootPath);
}
}
docRootPath.NotNull(nameof(docRootPath));

this.docRootPath = docRootPath;
this.RepositorySettings =
new RepositorySettings(@"c:\Source\Cake.Issues");
}

public FakeLog Log { get; set; }

public DocFxIssuesSettings DocFxIssuesSettings { get; set; }

public RepositorySettings RepositorySettings { get; set; }

public DocFxIssuesProvider Create()
{
var provider = new DocFxIssuesProvider(this.Log, this.DocFxIssuesSettings);
provider.Initialize(this.RepositorySettings);
return provider;
}
protected override string FileResourceNamespace => "Cake.Issues.DocFx.Tests.Testfiles.";

public IEnumerable<IIssue> ReadIssues()
protected override IList<object> GetCreateIssueProviderSettingsArguments()
{
var issueProvider = this.Create();
return issueProvider.ReadIssues(IssueCommentFormat.PlainText);
var result = base.GetCreateIssueProviderSettingsArguments();
result.Add(this.docRootPath);
return result;
}
}
}
8 changes: 4 additions & 4 deletions src/Cake.Issues.DocFx.Tests/DocFxProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Cake.Issues.DocFx.Tests
{
using System.Linq;
using Cake.Core.IO;
using Cake.Testing;
using Core.IO;
using Shouldly;
using Testing;
using Xunit;
Expand All @@ -18,22 +18,22 @@ public void Should_Throw_If_Log_Is_Null()
var result = Record.Exception(() =>
new DocFxIssuesProvider(
null,
DocFxIssuesSettings.FromContent("Foo", @"c:\Source\Cake.Issues")));
new DocFxIssuesSettings("Foo".ToByteArray(), @"c:\Source\Cake.Issues")));

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

[Fact]
public void Should_Throw_If_Settings_Are_Null()
public void Should_Throw_If_IssueProviderSettings_Are_Null()
{
var result = Record.Exception(() =>
new DocFxIssuesProvider(
new FakeLog(),
null));

// Then
result.IsArgumentNullException("settings");
result.IsArgumentNullException("issueProviderSettings");
}
}

Expand Down
139 changes: 71 additions & 68 deletions src/Cake.Issues.DocFx.Tests/DocFxSettingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
namespace Cake.Issues.DocFx.Tests
{
using System;
using System.IO;
using System.Linq;
using System.Text;
using Core.IO;
using Cake.Core.IO;
using Shouldly;
using Testing;
using Xunit;
Expand All @@ -16,58 +13,87 @@ public sealed class TheCtor
[Fact]
public void Should_Throw_If_LogFilePath_Is_Null()
{
// Given / When
// Given
FilePath logFilePath = null;
var docRootPath = @"c:\Source\Cake.Issues\docs";

// When
var result = Record.Exception(() =>
DocFxIssuesSettings.FromFilePath(null, @"c:\Source\Cake.Issues\docs"));
new DocFxIssuesSettings(logFilePath, docRootPath));

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

[Fact]
public void Should_Throw_If_LogFileContent_Is_Null()
public void Should_Throw_If_DocRootPath_For_LogFilePath_Is_Null()
{
// Given / When
var result = Record.Exception(() =>
DocFxIssuesSettings.FromContent(null, @"c:\Source\Cake.Issues\docs"));
// Given
DirectoryPath docRootPath = null;

using (var tempFile = new ResourceTempFile("Cake.Issues.DocFx.Tests.Testfiles.docfx.json"))
{
// When
var result = Record.Exception(() =>
new DocFxIssuesSettings(tempFile.FileName, docRootPath));

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

[Fact]
public void Should_Throw_If_LogContent_Is_Null()
{
// Given
byte[] logFileContent = null;
var docRootPath = @"c:\Source\Cake.Issues\docs";

// When
var result = Record.Exception(() => new DocFxIssuesSettings(logFileContent, docRootPath));

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

[Fact]
public void Should_Throw_If_LogFileContent_Is_Empty()
public void Should_Throw_If_LogContent_Is_Empty()
{
// Given / When
var result = Record.Exception(() =>
DocFxIssuesSettings.FromContent(string.Empty, @"c:\Source\Cake.Issues\docs"));
// Given
byte[] logFileContent = Array.Empty<byte>();
var docRootPath = @"c:\Source\Cake.Issues\docs";

// When
var result = Record.Exception(() => new DocFxIssuesSettings(logFileContent, docRootPath));

// Then
result.IsArgumentOutOfRangeException("logFileContent");
result.IsArgumentException("logFileContent");
}

[Fact]
public void Should_Throw_If_LogFileContent_Is_WhiteSpace()
public void Should_Throw_If_DocRootPath_For_LogFileContent_Is_Null()
{
// Given / When
// Given
var logFileContent = "foo".ToByteArray();
DirectoryPath docRootPath = null;

// When
var result = Record.Exception(() =>
DocFxIssuesSettings.FromContent(" ", @"c:\Source\Cake.Issues\docs"));
new DocFxIssuesSettings(logFileContent, docRootPath));

// Then
result.IsArgumentOutOfRangeException("logFileContent");
result.IsArgumentNullException("docRootPath");
}

[Fact]
public void Should_Set_LogFileContent()
public void Should_Set_LogContent()
{
// Given
const string logFileContent = "foo";
var logFileContent = "Foo".ToByteArray();
var docRootPath = @"c:\Source\Cake.Issues\docs";

// When
var settings =
DocFxIssuesSettings.FromContent(
logFileContent,
@"c:\Source\Cake.Issues\docs");
var settings = new DocFxIssuesSettings(logFileContent, docRootPath);

// Then
settings.LogFileContent.ShouldBe(logFileContent);
Expand All @@ -77,67 +103,44 @@ public void Should_Set_LogFileContent()
public void Should_Set_DocRootPath()
{
// Given
DirectoryPath docRootPath = @"c:\Source\Cake.Issues\docs";
var logFileContent = "Foo".ToByteArray();
var docRootPath = @"c:/Source/Cake.Issues/docs";

// When
var settings =
DocFxIssuesSettings.FromContent(
"foo",
docRootPath);
var settings = new DocFxIssuesSettings(logFileContent, docRootPath);

// Then
settings.DocRootPath.ShouldBe(docRootPath);
settings.DocRootPath.ToString().ShouldBe(docRootPath);
}

[Fact]
public void Should_Read_File_From_Disk()
public void Should_Set_LogContent_From_LogFilePath()
{
var fileName = System.IO.Path.GetTempFileName();
try
// Given
var docRootPath = @"c:\Source\Cake.Issues\docs";
using (var tempFile = new ResourceTempFile("Cake.Issues.DocFx.Tests.Testfiles.docfx.json"))
{
// Given
string expected;
using (var ms = new MemoryStream())
using (var stream = this.GetType().Assembly.GetManifestResourceStream("Cake.Issues.DocFx.Tests.Testfiles.docfx.json"))
{
stream.CopyTo(ms);
var data = ms.ToArray();

using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
file.Write(data, 0, data.Length);
}

expected = ConvertFromUtf8(data);
}

// When
var settings =
DocFxIssuesSettings.FromFilePath(fileName, @"c:\Source\Cake.Issues\docs");
var settings = new DocFxIssuesSettings(tempFile.FileName, docRootPath);

// Then
settings.LogFileContent.ShouldBe(expected);
}
finally
{
if (File.Exists(fileName))
{
File.Delete(fileName);
}
settings.LogFileContent.ShouldBe(tempFile.Content);
}
}

private static string ConvertFromUtf8(byte[] bytes)
[Fact]
public void Should_Set_DocRootPath_From_LogFilePath()
{
var enc = new UTF8Encoding(true);
var preamble = enc.GetPreamble();

if (preamble.Where((p, i) => p != bytes[i]).Any())
// Given
var docRootPath = @"c:/Source/Cake.Issues/docs";
using (var tempFile = new ResourceTempFile("Cake.Issues.DocFx.Tests.Testfiles.docfx.json"))
{
throw new ArgumentException("Not utf8-BOM");
}
// When
var settings = new DocFxIssuesSettings(tempFile.FileName, docRootPath);

return enc.GetString(bytes.Skip(preamble.Length).ToArray());
// Then
settings.DocRootPath.ToString().ShouldBe(docRootPath);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Issues.DocFx.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake.Core" version="0.28.0" targetFramework="net461" />
<package id="Cake.Issues" version="0.4.0" targetFramework="net461" />
<package id="Cake.Issues.Testing" version="0.4.0" targetFramework="net461" />
<package id="Cake.Issues" version="0.5.0-beta0002" targetFramework="net461" />
<package id="Cake.Issues.Testing" version="0.5.0-beta0002" targetFramework="net461" />
<package id="Cake.Testing" version="0.28.0" targetFramework="net461" />
<package id="Shouldly" version="3.0.0" targetFramework="net46" />
<package id="StyleCop.Analyzers" version="1.0.2" targetFramework="net46" developmentDependency="true" />
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Issues.DocFx/Cake.Issues.DocFx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<Reference Include="Cake.Core, Version=0.28.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Core.0.28.0\lib\net46\Cake.Core.dll</HintPath>
</Reference>
<Reference Include="Cake.Issues, Version=0.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Issues.0.4.0\lib\netstandard2.0\Cake.Issues.dll</HintPath>
<Reference Include="Cake.Issues, Version=0.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cake.Issues.0.5.0-beta0002\lib\netstandard2.0\Cake.Issues.dll</HintPath>
</Reference>
<Reference Include="Costura, Version=1.6.2.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll</HintPath>
Expand Down
14 changes: 7 additions & 7 deletions src/Cake.Issues.DocFx/DocFxIssuesAliases.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Cake.Issues.DocFx
{
using Core;
using Core.Annotations;
using Core.IO;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.IO;

/// <summary>
/// Contains functionality related to read warnings from DocFx log files.
Expand Down Expand Up @@ -88,7 +88,7 @@ public static IIssueProvider DocFxIssuesFromFilePath(
logFilePath.NotNull(nameof(logFilePath));
docRootPath.NotNull(nameof(docRootPath));

return context.DocFxIssues(DocFxIssuesSettings.FromFilePath(logFilePath, docRootPath));
return context.DocFxIssues(new DocFxIssuesSettings(logFilePath, docRootPath));
}

/// <summary>
Expand Down Expand Up @@ -118,7 +118,7 @@ public static IIssueProvider DocFxIssuesFromContent(
context.NotNull(nameof(context));
logFileContent.NotNullOrWhiteSpace(nameof(logFileContent));

return context.DocFxIssues(DocFxIssuesSettings.FromContent(logFileContent, "/"));
return context.DocFxIssues(new DocFxIssuesSettings(logFileContent.ToByteArray(), "/"));
}

/// <summary>
Expand Down Expand Up @@ -153,7 +153,7 @@ public static IIssueProvider DocFxIssuesFromContent(
logFileContent.NotNullOrWhiteSpace(nameof(logFileContent));
docRootPath.NotNull(nameof(docRootPath));

return context.DocFxIssues(DocFxIssuesSettings.FromContent(logFileContent, docRootPath));
return context.DocFxIssues(new DocFxIssuesSettings(logFileContent.ToByteArray(), docRootPath));
}

/// <summary>
Expand All @@ -167,7 +167,7 @@ public static IIssueProvider DocFxIssuesFromContent(
/// <code>
/// <![CDATA[
/// var settings =
/// DocFxIssuesSettings(@"c:\build\docfx.log");
/// new DocFxIssuesSettings(@"c:\build\docfx.log");
///
/// var issues =
/// ReadIssues(
Expand Down
Loading

0 comments on commit dc0ac62

Please sign in to comment.