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

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Aug 17, 2018
2 parents 980a003 + 1518139 commit cc3a398
Show file tree
Hide file tree
Showing 18 changed files with 361 additions and 487 deletions.
3 changes: 2 additions & 1 deletion nuspec/nuget/Cake.Issues.EsLint.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
<projectUrl>https://github.com/cake-contrib/Cake.Issues.EsLint</projectUrl>
<iconUrl>https://cdn.rawgit.com/cake-contrib/graphics/a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<repository type="git" url="https://github.com/cake-contrib/Cake.Issues.ESLint"/>
<copyright>Copyright © BBT Software AG and contributors</copyright>
<tags>Cake Script Cake-Issues Cake-IssueProvider CodeAnalysis JavaScript Linting ESLint</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.ESLint/releases/tag/0.4.0</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.ESLint/releases/tag/0.5.0</releaseNotes>
</metadata>
<files>
<file src="netstandard2.0\Cake.Issues.EsLint.dll" target="lib\netstandard2.0" />
Expand Down
6 changes: 3 additions & 3 deletions src/Cake.Issues.EsLint.Tests/Cake.Issues.EsLint.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@


<ItemGroup>
<EmbeddedResource Include="Testfiles\jsonFormatWindows.json" />
<EmbeddedResource Include="Testfiles\JsonLogFileFormat\jsonFormatWindows.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Testing" Version="0.28.0" />
<PackageReference Include="Cake.Issues" Version="0.4.0" />
<PackageReference Include="Cake.Issues.Testing" Version="0.4.0" />
<PackageReference Include="Cake.Issues" Version="0.5.0" />
<PackageReference Include="Cake.Issues.Testing" Version="0.5.0" />
<PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
42 changes: 6 additions & 36 deletions src/Cake.Issues.EsLint.Tests/EsLintIssuesProviderFixture.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,18 @@
namespace Cake.Issues.EsLint.Tests
{
using System.Collections.Generic;
using System.IO;
using Cake.Testing;
using Core.Diagnostics;
using Cake.Issues.Testing;

public class EsLintIssuesProviderFixture
public class EsLintIssuesProviderFixture<T>
: BaseMultiFormatIssueProviderFixture<EsLintIssuesProvider, EsLintIssuesSettings, T>
where T : BaseEsLintLogFileFormat
{
public EsLintIssuesProviderFixture(string fileResourceName)
: base(fileResourceName)
{
this.Log = new FakeLog { Verbosity = Verbosity.Normal };

using (var stream = this.GetType().Assembly.GetManifestResourceStream("Cake.Issues.EsLint.Tests.Testfiles." + fileResourceName))
{
using (var sr = new StreamReader(stream))
{
this.Settings =
EsLintIssuesSettings.FromContent(
sr.ReadToEnd(),
new JsonFormat(this.Log));
}
}

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

public FakeLog Log { get; set; }

public EsLintIssuesSettings Settings { get; set; }

public RepositorySettings RepositorySettings { get; set; }

internal EsLintIssuesProvider Create()
{
var provider = new EsLintIssuesProvider(this.Log, this.Settings);
provider.Initialize(this.RepositorySettings);
return provider;
}

internal IEnumerable<IIssue> ReadIssues()
{
var issueProvider = this.Create();
return issueProvider.ReadIssues(IssueCommentFormat.PlainText);
}
protected override string FileResourceNamespace => "Cake.Issues.EsLint.Tests.Testfiles." + typeof(T).Name + ".";
}
}
35 changes: 21 additions & 14 deletions src/Cake.Issues.EsLint.Tests/EsLintIssuesProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
namespace Cake.Issues.EsLint.Tests
{
using System.Text;
using Cake.Core.Diagnostics;
using Cake.Issues.EsLint.LogFileFormat;
using Cake.Testing;
using Xunit;

public sealed class EsLintIssuesProviderTests
{
public sealed class TheEsLintIssuesProviderCtor
public sealed class TheCtor
{
[Fact]
public void Should_Throw_If_Log_Is_Null()
{
// Given / When
var result = Record.Exception(() =>
new EsLintIssuesProvider(
null,
EsLintIssuesSettings.FromContent(
"Foo",
new JsonFormat(new FakeLog()))));
// Given
ICakeLog log = null;
var settings =
new EsLintIssuesSettings(
"Foo".ToByteArray(),
new JsonLogFileFormat(new FakeLog()));

// When
var result = Record.Exception(() => new EsLintIssuesProvider(log, settings));

// 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 EsLintIssuesProvider(
new FakeLog(),
null));
// Given
var log = new FakeLog();
EsLintIssuesSettings settings = null;

// When
var result = Record.Exception(() => new EsLintIssuesProvider(log, settings));

// Then
result.IsArgumentNullException("settings");
result.IsArgumentNullException("issueProviderSettings");
}
}
}
Expand Down
145 changes: 51 additions & 94 deletions src/Cake.Issues.EsLint.Tests/EsLintIssuesSettingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Cake.Issues.EsLint.Tests
{
using System;
using System.IO;
using System.Linq;
using System.Text;
using Cake.Core.IO;
using Cake.Issues.EsLint.LogFileFormat;
using Cake.Issues.Testing;
using Cake.Testing;
using Shouldly;
using Xunit;
Expand All @@ -15,11 +15,12 @@ public sealed class TheEsLintIssuesSettingsCtor
[Fact]
public void Should_Throw_If_LogFilePath_Is_Null()
{
// Given / When
var result = Record.Exception(() =>
EsLintIssuesSettings.FromFilePath(
null,
new JsonFormat(new FakeLog())));
// Given
FilePath logFilePath = null;
var format = new JsonLogFileFormat(new FakeLog());

// When
var result = Record.Exception(() => new EsLintIssuesSettings(logFilePath, format));

// Then
result.IsArgumentNullException("logFilePath");
Expand All @@ -28,135 +29,91 @@ public void Should_Throw_If_LogFilePath_Is_Null()
[Fact]
public void Should_Throw_If_Format_For_LogFilePath_Is_Null()
{
// Given / When
var result = Record.Exception(() =>
EsLintIssuesSettings.FromFilePath(
@"C:\foo.log",
null));
// Given
BaseEsLintLogFileFormat format = null;

// Then
result.IsArgumentNullException("format");
using (var tempFile = new ResourceTempFile("Cake.Issues.EsLint.Tests.Testfiles.JsonLogFileFormat.jsonFormatWindows.json"))
{
// When
var result = Record.Exception(() =>
new EsLintIssuesSettings(tempFile.FileName, format));

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

[Fact]
public void Should_Throw_If_LogFileContent_Is_Null()
public void Should_Throw_If_LogContent_Is_Null()
{
// Given / When
var result = Record.Exception(() =>
EsLintIssuesSettings.FromContent(
null,
new JsonFormat(new FakeLog())));
// Given
byte[] logFileContent = null;
var format = new JsonLogFileFormat(new FakeLog());

// When
var result = Record.Exception(() => new EsLintIssuesSettings(logFileContent, format));

// 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(() =>
EsLintIssuesSettings.FromContent(
string.Empty,
new JsonFormat(new FakeLog())));

// Then
result.IsArgumentOutOfRangeException("logFileContent");
}
// Given
byte[] logFileContent = Array.Empty<byte>();
var format = new JsonLogFileFormat(new FakeLog());

[Fact]
public void Should_Throw_If_LogFileContent_Is_WhiteSpace()
{
// Given / When
var result = Record.Exception(() =>
EsLintIssuesSettings.FromContent(
" ",
new JsonFormat(new FakeLog())));
// When
var result = Record.Exception(() => new EsLintIssuesSettings(logFileContent, format));

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

[Fact]
public void Should_Throw_If_Format_For_LogFileContent_Is_Null()
{
// Given / When
// Given
var logFileContent = "foo".ToByteArray();
BaseEsLintLogFileFormat format = null;

// When
var result = Record.Exception(() =>
EsLintIssuesSettings.FromContent(
"foo",
null));
new EsLintIssuesSettings(logFileContent, format));

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

[Fact]
public void Should_Set_Property_Values_Passed_To_Constructor()
public void Should_Set_LogContent()
{
// Given
const string logFileContent = "foo";
var format = new JsonFormat(new FakeLog());
var logFileContent = "Foo".ToByteArray();
var format = new JsonLogFileFormat(new FakeLog());

// When
var settings = EsLintIssuesSettings.FromContent(logFileContent, format);
var settings = new EsLintIssuesSettings(logFileContent, format);

// Then
settings.LogFileContent.ShouldBe(logFileContent);
settings.Format.ShouldBe(format);
}

[Fact]
public void Should_Read_File_From_Disk()
public void Should_Set_LogContent_From_LogFilePath()
{
var fileName = Path.GetTempFileName();
try
// Given
var format = new JsonLogFileFormat(new FakeLog());
using (var tempFile = new ResourceTempFile("Cake.Issues.EsLint.Tests.Testfiles.JsonLogFileFormat.jsonFormatWindows.json"))
{
// Given
string expected;
using (var ms = new MemoryStream())
using (var stream = this.GetType().Assembly.GetManifestResourceStream("Cake.Issues.EsLint.Tests.Testfiles.jsonFormatWindows.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 =
EsLintIssuesSettings.FromFilePath(
fileName,
new JsonFormat(new FakeLog()));
var settings = new EsLintIssuesSettings(tempFile.FileName, format);

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

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

if (preamble.Where((p, i) => p != bytes[i]).Any())
{
throw new ArgumentException("Not utf8-BOM");
settings.LogFileContent.ShouldBe(tempFile.Content);
}

return enc.GetString(bytes.Skip(preamble.Length).ToArray());
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
namespace Cake.Issues.EsLint.Tests
namespace Cake.Issues.EsLint.Tests.LogFileFormat
{
using System.Linq;
using Core.IO;
using Cake.Core.IO;
using Cake.Issues.EsLint.LogFileFormat;
using Shouldly;
using Xunit;

public sealed class JsonFormatTests
public sealed class JsonLogFileFormatTests
{
public sealed class TheJsonFormatCtor
{
[Fact]
public void Should_Throw_If_Log_Is_Null()
{
// Given / When
var result = Record.Exception(() => new JsonFormat(null));
var result = Record.Exception(() => new JsonLogFileFormat(null));

// Then
result.IsArgumentNullException("log");
Expand All @@ -26,7 +27,7 @@ public sealed class TheReadIssuesMethod
public void Should_Read_Issue_Correct()
{
// Given
var fixture = new EsLintIssuesProviderFixture("jsonFormatWindows.json");
var fixture = new EsLintIssuesProviderFixture<JsonLogFileFormat>("jsonFormatWindows.json");

// When
var issues = fixture.ReadIssues().ToList();
Expand Down
Loading

0 comments on commit cc3a398

Please sign in to comment.