diff --git a/nuspec/nuget/Cake.Issues.Testing.nuspec b/nuspec/nuget/Cake.Issues.Testing.nuspec index 9201296c7..99685b5ce 100644 --- a/nuspec/nuget/Cake.Issues.Testing.nuspec +++ b/nuspec/nuget/Cake.Issues.Testing.nuspec @@ -17,7 +17,7 @@ Common helpers for testing add-ins based on Cake.Issues Copyright © BBT Software AG and contributors Cake Script Cake-Issues Issues Testing - https://github.com/cake-contrib/Cake.Issues/releases/tag/0.6.1 + https://github.com/cake-contrib/Cake.Issues/releases/tag/0.6.2 diff --git a/nuspec/nuget/Cake.Issues.nuspec b/nuspec/nuget/Cake.Issues.nuspec index c07df87ae..a4f6c93a1 100644 --- a/nuspec/nuget/Cake.Issues.nuspec +++ b/nuspec/nuget/Cake.Issues.nuspec @@ -24,7 +24,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin Copyright © BBT Software AG and contributors Cake Script Cake-Issues CodeAnalysis Linting Issues - https://github.com/cake-contrib/Cake.Issues/releases/tag/0.6.1 + https://github.com/cake-contrib/Cake.Issues/releases/tag/0.6.2 diff --git a/src/Cake.Issues.Testing/BaseConfigurableIssueProviderFixture.cs b/src/Cake.Issues.Testing/BaseConfigurableIssueProviderFixture.cs index 761d90652..f1bc46d3b 100644 --- a/src/Cake.Issues.Testing/BaseConfigurableIssueProviderFixture.cs +++ b/src/Cake.Issues.Testing/BaseConfigurableIssueProviderFixture.cs @@ -20,9 +20,20 @@ public abstract class BaseConfigurableIssueProviderFixtureName of the resource to load. protected BaseConfigurableIssueProviderFixture(string fileResourceName) { + fileResourceName.NotNullOrWhiteSpace(nameof(fileResourceName)); + + var resourceName = this.FileResourceNamespace + fileResourceName; + using (var ms = new MemoryStream()) - using (var stream = this.GetType().Assembly.GetManifestResourceStream(this.FileResourceNamespace + fileResourceName)) + using (var stream = this.GetType().Assembly.GetManifestResourceStream(resourceName)) { + if (stream == null) + { + throw new ArgumentException( + $"Resource {resourceName} not found", + nameof(fileResourceName)); + } + stream.CopyTo(ms); this.LogFileContent = ms.ToArray(); } @@ -52,7 +63,7 @@ protected override IList GetCreateIssueProviderArguments() /// Instance of the issue provider settings. protected virtual IList GetCreateIssueProviderSettingsArguments() { - if (this.LogFileContent == null || !this.LogFileContent.Any()) + if (this.LogFileContent == null) { throw new InvalidOperationException("No log content set."); } diff --git a/src/Cake.Issues.Tests/BaseMultiFormatIssueProviderSettingsTests.cs b/src/Cake.Issues.Tests/BaseMultiFormatIssueProviderSettingsTests.cs index 1c6dce690..bd68e8d6e 100644 --- a/src/Cake.Issues.Tests/BaseMultiFormatIssueProviderSettingsTests.cs +++ b/src/Cake.Issues.Tests/BaseMultiFormatIssueProviderSettingsTests.cs @@ -40,24 +40,24 @@ public void Should_Throw_If_LogContent_Is_Null() } [Fact] - public void Should_Throw_If_LogContent_Is_Empty() + public void Should_Set_LogContent() { // Given - byte[] logFileContent = Array.Empty(); + var logFileContent = "Foo".ToByteArray(); var format = new FakeLogFileFormat(new FakeLog()); // When - var result = Record.Exception(() => new FakeMultiFormatIssueProviderSettings(logFileContent, format)); + var settings = new FakeMultiFormatIssueProviderSettings(logFileContent, format); // Then - result.IsArgumentException("logFileContent"); + settings.LogFileContent.ShouldBe(logFileContent); } [Fact] - public void Should_Set_LogContent() + public void Should_Set_LogContent_If_Empty() { // Given - var logFileContent = "Foo".ToByteArray(); + byte[] logFileContent = Array.Empty(); var format = new FakeLogFileFormat(new FakeLog()); // When diff --git a/src/Cake.Issues.Tests/ByteArrayExtensionsTests.cs b/src/Cake.Issues.Tests/ByteArrayExtensionsTests.cs index b7b99b630..a072f3a78 100644 --- a/src/Cake.Issues.Tests/ByteArrayExtensionsTests.cs +++ b/src/Cake.Issues.Tests/ByteArrayExtensionsTests.cs @@ -24,31 +24,19 @@ public void Should_Throw_If_Value_Is_Null() result.IsArgumentNullException("value"); } - [Fact] - public void Should_Throw_If_Value_Is_Empty() - { - // Given - byte[] value = Array.Empty(); - - // When - var result = Record.Exception(() => value.ToStringUsingEncoding()); - - // Then - result.IsArgumentException("value"); - } - - [Fact] - public void Should_Return_Correct_Value_Without_Preamble() + [Theory] + [InlineData("foo🐱bar")] + [InlineData("")] + public void Should_Return_Correct_Value_Without_Preamble(string value) { // Given - var stringValue = "foo🐱bar"; - var byteArrayValue = stringValue.ToByteArray(); + var byteArrayValue = value.ToByteArray(); // When var result = byteArrayValue.ToStringUsingEncoding(); // Then - result.ShouldBe(stringValue); + result.ShouldBe(value); } } @@ -68,59 +56,61 @@ public void Should_Throw_If_Value_Is_Null() } [Fact] - public void Should_Throw_If_Value_Is_Empty() + public void Should_Ignore_If_Preamble_Should_Be_Skipped_But_No_Preamble_Passed() { // Given - byte[] value = Array.Empty(); + var stringValue = "foo🐱bar"; + var byteArrayValue = stringValue.ToByteArray(); // When - var result = Record.Exception(() => value.ToStringUsingEncoding(true)); + var result = byteArrayValue.ToStringUsingEncoding(true); // Then - result.IsArgumentException("value"); + result.ShouldBe(stringValue); } - [Fact] - public void Should_Throw_If_Preamble_Should_Be_Skipped_But_No_Preamble_Passed() + [Theory] + [InlineData("foo🐱bar")] + [InlineData("")] + public void Should_Return_Correct_Value_Without_Preamble(string value) { // Given - var stringValue = "foo🐱bar"; - var byteArrayValue = stringValue.ToByteArray(); + var byteArrayValue = value.ToByteArray(); // When - var result = Record.Exception(() => byteArrayValue.ToStringUsingEncoding(true)); + var result = byteArrayValue.ToStringUsingEncoding(false); // Then - result.IsArgumentException("value"); + result.ShouldBe(value); } - [Fact] - public void Should_Return_Correct_Value_Without_Preamble() + [Theory] + [InlineData("foo🐱bar")] + [InlineData("")] + public void Should_Return_Correct_Value_With_Preamble(string value) { // Given - var stringValue = "foo🐱bar"; - var byteArrayValue = stringValue.ToByteArray(); + var preamble = Encoding.UTF8.GetPreamble(); + var byteArrayValue = preamble.Concat(value.ToByteArray()).ToArray(); // When - var result = byteArrayValue.ToStringUsingEncoding(false); + var result = byteArrayValue.ToStringUsingEncoding(true); // Then - result.ShouldBe(stringValue); + result.ShouldBe(value); } [Fact] - public void Should_Return_Correct_Value_With_Preamble() + public void Should_Return_Correct_Value_For_Empty_Byte_Array() { // Given - var stringValue = "foo🐱bar"; - var preamble = Encoding.UTF8.GetPreamble(); - var byteArrayValue = preamble.Concat(stringValue.ToByteArray()).ToArray(); + var byteArrayValue = Array.Empty(); // When var result = byteArrayValue.ToStringUsingEncoding(true); // Then - result.ShouldBe(stringValue); + result.ShouldBe(string.Empty); } } @@ -141,21 +131,7 @@ public void Should_Throw_If_Value_Is_Null() } [Fact] - public void Should_Throw_If_Value_Is_Empty() - { - // Given - byte[] value = Array.Empty(); - var encoding = Encoding.UTF32; - - // When - var result = Record.Exception(() => value.ToStringUsingEncoding(encoding, true)); - - // Then - result.IsArgumentException("value"); - } - - [Fact] - public void Should_Throw_If_Preamble_Should_Be_Skipped_But_No_Preamble_Passed() + public void Should_Ignore_If_Preamble_Should_Be_Skipped_But_No_Preamble_Passed() { // Given var encoding = Encoding.UTF32; @@ -163,56 +139,59 @@ public void Should_Throw_If_Preamble_Should_Be_Skipped_But_No_Preamble_Passed() var byteArrayValue = stringValue.ToByteArray(encoding); // When - var result = Record.Exception(() => byteArrayValue.ToStringUsingEncoding(encoding, true)); + var result = byteArrayValue.ToStringUsingEncoding(encoding, true); // Then - result.IsArgumentException("value"); + result.ShouldBe(stringValue); } - [Fact] - public void Should_Return_Value_If_Preamble_Should_Be_Skipped_But_Encoding_Does_Not_Have_Preamble() + [Theory] + [InlineData("foo")] + [InlineData("")] + public void Should_Return_Value_If_Preamble_Should_Be_Skipped_But_Encoding_Does_Not_Have_Preamble(string value) { // Given - var stringValue = "foo"; - var byteArrayValue = stringValue.ToByteArray(); + var byteArrayValue = value.ToByteArray(); var encoding = Encoding.ASCII; // When var result = byteArrayValue.ToStringUsingEncoding(encoding, true); // Then - result.ShouldBe(stringValue); + result.ShouldBe(value); } - [Fact] - public void Should_Return_Correct_Value_Without_Preamble() + [Theory] + [InlineData("foo🐱bar")] + [InlineData("")] + public void Should_Return_Correct_Value_Without_Preamble(string value) { // Given var encoding = Encoding.UTF32; - var stringValue = "foo🐱bar"; - var byteArrayValue = stringValue.ToByteArray(encoding); + var byteArrayValue = value.ToByteArray(encoding); // When var result = byteArrayValue.ToStringUsingEncoding(encoding, false); // Then - result.ShouldBe(stringValue); + result.ShouldBe(value); } - [Fact] - public void Should_Return_Correct_Value_With_Preamble() + [Theory] + [InlineData("foo🐱bar")] + [InlineData("")] + public void Should_Return_Correct_Value_With_Preamble(string value) { // Given var encoding = Encoding.UTF32; - var stringValue = "foo🐱bar"; var preamble = encoding.GetPreamble(); - var byteArrayValue = preamble.Concat(stringValue.ToByteArray(encoding)).ToArray(); + var byteArrayValue = preamble.Concat(value.ToByteArray(encoding)).ToArray(); // When var result = byteArrayValue.ToStringUsingEncoding(encoding, true); // Then - result.ShouldBe(stringValue); + result.ShouldBe(value); } } diff --git a/src/Cake.Issues.Tests/Cake.Issues.Tests.csproj b/src/Cake.Issues.Tests/Cake.Issues.Tests.csproj index a919e94d6..53c3f92ad 100644 --- a/src/Cake.Issues.Tests/Cake.Issues.Tests.csproj +++ b/src/Cake.Issues.Tests/Cake.Issues.Tests.csproj @@ -16,9 +16,11 @@ + + diff --git a/src/Cake.Issues.Tests/IssueProviderSettingsTests.cs b/src/Cake.Issues.Tests/IssueProviderSettingsTests.cs index 12e88dfb9..fe31054e4 100644 --- a/src/Cake.Issues.Tests/IssueProviderSettingsTests.cs +++ b/src/Cake.Issues.Tests/IssueProviderSettingsTests.cs @@ -39,23 +39,23 @@ public void Should_Throw_If_LogContent_Is_Null() } [Fact] - public void Should_Throw_If_LogContent_Is_Empty() + public void Should_Set_LogContent() { // Given - byte[] logFileContent = Array.Empty(); + var logFileContent = "Foo".ToByteArray(); // When - var result = Record.Exception(() => new IssueProviderSettings(logFileContent)); + var settings = new IssueProviderSettings(logFileContent); // Then - result.IsArgumentException("logFileContent"); + settings.LogFileContent.ShouldBe(logFileContent); } [Fact] - public void Should_Set_LogContent() + public void Should_Set_If_LogContent_If_Empty() { // Given - var logFileContent = "Foo".ToByteArray(); + byte[] logFileContent = Array.Empty(); // When var settings = new IssueProviderSettings(logFileContent); diff --git a/src/Cake.Issues.Tests/Testfiles/Empty.log b/src/Cake.Issues.Tests/Testfiles/Empty.log new file mode 100644 index 000000000..e69de29bb diff --git a/src/Cake.Issues.Tests/Testing/BaseConfigurableIssueProviderFixtureTests.cs b/src/Cake.Issues.Tests/Testing/BaseConfigurableIssueProviderFixtureTests.cs new file mode 100644 index 000000000..119d339fc --- /dev/null +++ b/src/Cake.Issues.Tests/Testing/BaseConfigurableIssueProviderFixtureTests.cs @@ -0,0 +1,164 @@ +namespace Cake.Issues.Tests.Testing +{ + using System.Linq; + using Cake.Issues.Testing; + using Shouldly; + using Xunit; + + public sealed class BaseConfigurableIssueProviderFixtureTests + { + public sealed class TheCtor + { + [Fact] + public void Should_Throw_If_FileResourceName_Is_Null() + { + // Given + string fileResourceName = null; + + // When + var result = Record.Exception(() => new FakeConfigurableIssueProviderFixture(fileResourceName)); + + // Then + result.IsArgumentNullException("fileResourceName"); + } + + [Fact] + public void Should_Throw_If_FileResourceName_Is_Empty() + { + // Given + var fileResourceName = string.Empty; + + // When + var result = Record.Exception(() => new FakeConfigurableIssueProviderFixture(fileResourceName)); + + // Then + result.IsArgumentOutOfRangeException("fileResourceName"); + } + + [Fact] + public void Should_Throw_If_FileResourceName_Is_WhiteSpace() + { + // Given + var fileResourceName = " "; + + // When + var result = Record.Exception(() => new FakeConfigurableIssueProviderFixture(fileResourceName)); + + // Then + result.IsArgumentOutOfRangeException("fileResourceName"); + } + + [Fact] + public void Should_Throw_If_File_Resource_Does_Not_Exist() + { + // Given + var fileResourceName = "foo"; + + // When + var result = Record.Exception(() => new FakeConfigurableIssueProviderFixture(fileResourceName)); + + // Then + result.IsArgumentException("fileResourceName"); + } + + [Fact] + public void Should_Set_Log() + { + // Given + + // When + var result = new FakeConfigurableIssueProviderFixture("Build.log"); + + // Then + result.Log.ShouldNotBeNull(); + } + + [Fact] + public void Should_Set_RepositorySettings() + { + // Given + + // When + var result = new FakeConfigurableIssueProviderFixture("Build.log"); + + // Then + result.RepositorySettings.ShouldNotBeNull(); + } + + [Fact] + public void Should_Set_LogFileContent() + { + // Given + + // When + var result = new FakeConfigurableIssueProviderFixture("Build.log"); + + // Then + result.LogFileContent.ShouldNotBeNull(); + result.LogFileContent.ShouldNotBeEmpty(); + } + + [Fact] + public void Should_Set_LogFileContent_For_Empty_File() + { + // Given + + // When + var result = new FakeConfigurableIssueProviderFixture("Empty.log"); + + // Then + result.LogFileContent.ShouldNotBeNull(); + result.LogFileContent.ShouldBeEmpty(); + } + } + + public sealed class TheReadIssuesMethod + { + [Fact] + public void Should_Throw_If_Log_Is_Null() + { + // Given + var fixture = new FakeConfigurableIssueProviderFixture("Build.log") + { + Log = null + }; + + // When + var result = Record.Exception(() => fixture.ReadIssues()); + + // Then + result.IsInvalidOperationException("No log instance set."); + } + + [Fact] + public void Should_Throw_If_RepositorySettings_Are_Null() + { + // Given + var fixture = new FakeConfigurableIssueProviderFixture("Build.log") + { + RepositorySettings = null + }; + + // When + var result = Record.Exception(() => fixture.ReadIssues()); + + // Then + result.IsInvalidOperationException("No repository settings set."); + } + + [Fact] + public void Should_Return_Empty_List_For_Empty_File() + { + // Given + var fixture = + new FakeConfigurableIssueProviderFixture("Empty.log"); + + // When + var result = fixture.ReadIssues(); + + // Then + result.ShouldBeEmpty(); + } + } + } +} diff --git a/src/Cake.Issues.Tests/Testing/BaseIssueProviderFixtureTests.cs b/src/Cake.Issues.Tests/Testing/BaseIssueProviderFixtureTests.cs new file mode 100644 index 000000000..82098d7cd --- /dev/null +++ b/src/Cake.Issues.Tests/Testing/BaseIssueProviderFixtureTests.cs @@ -0,0 +1,91 @@ +namespace Cake.Issues.Tests.Testing +{ + using System.Collections.Generic; + using System.Linq; + using Cake.Issues.Testing; + using Shouldly; + using Xunit; + + public sealed class BaseIssueProviderFixtureTests + { + public sealed class TheCtor + { + [Fact] + public void Should_Set_Log() + { + // Given + + // When + var result = new FakeIssueProviderFixture(); + + // Then + result.Log.ShouldNotBeNull(); + } + + [Fact] + public void Should_Set_RepositorySettings() + { + // Given + + // When + var result = new FakeIssueProviderFixture(); + + // Then + result.RepositorySettings.ShouldNotBeNull(); + } + } + + public sealed class TheReadIssuesMethod + { + [Fact] + public void Should_Throw_If_Log_Is_Null() + { + // Given + var fixture = new FakeIssueProviderFixture + { + Log = null + }; + + // When + var result = Record.Exception(() => fixture.ReadIssues()); + + // Then + result.IsInvalidOperationException("No log instance set."); + } + + [Fact] + public void Should_Throw_If_RepositorySettings_Are_Null() + { + // Given + var fixture = new FakeIssueProviderFixture + { + RepositorySettings = null + }; + + // When + var result = Record.Exception(() => fixture.ReadIssues()); + + // Then + result.IsInvalidOperationException("No repository settings set."); + } + + [Fact] + public void Should_Return_Issues() + { + // Given + var issue = + IssueBuilder + .NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo") + .Create(); + var fixture = new FakeIssueProviderFixture(new List { issue }); + + // When + var result = fixture.ReadIssues(); + + // Then + result.Count().ShouldBe(1); + result.ShouldContain(issue); + } + } + } +} diff --git a/src/Cake.Issues.Tests/Testing/BaseMultiFormatIssueProviderFixtureTests.cs b/src/Cake.Issues.Tests/Testing/BaseMultiFormatIssueProviderFixtureTests.cs new file mode 100644 index 000000000..e7d2dfc8f --- /dev/null +++ b/src/Cake.Issues.Tests/Testing/BaseMultiFormatIssueProviderFixtureTests.cs @@ -0,0 +1,164 @@ +namespace Cake.Issues.Tests.Testing +{ + using System.Linq; + using Cake.Issues.Testing; + using Shouldly; + using Xunit; + + public sealed class BaseMultiFormatIssueProviderFixtureTests + { + public sealed class TheCtor + { + [Fact] + public void Should_Throw_If_FileResourceName_Is_Null() + { + // Given + string fileResourceName = null; + + // When + var result = Record.Exception(() => new FakeMultiFormatIssueProviderFixture(fileResourceName)); + + // Then + result.IsArgumentNullException("fileResourceName"); + } + + [Fact] + public void Should_Throw_If_FileResourceName_Is_Empty() + { + // Given + var fileResourceName = string.Empty; + + // When + var result = Record.Exception(() => new FakeMultiFormatIssueProviderFixture(fileResourceName)); + + // Then + result.IsArgumentOutOfRangeException("fileResourceName"); + } + + [Fact] + public void Should_Throw_If_FileResourceName_Is_WhiteSpace() + { + // Given + var fileResourceName = " "; + + // When + var result = Record.Exception(() => new FakeMultiFormatIssueProviderFixture(fileResourceName)); + + // Then + result.IsArgumentOutOfRangeException("fileResourceName"); + } + + [Fact] + public void Should_Throw_If_File_Resource_Does_Not_Exist() + { + // Given + var fileResourceName = "foo"; + + // When + var result = Record.Exception(() => new FakeMultiFormatIssueProviderFixture(fileResourceName)); + + // Then + result.IsArgumentException("fileResourceName"); + } + + [Fact] + public void Should_Set_Log() + { + // Given + + // When + var result = new FakeMultiFormatIssueProviderFixture("Build.log"); + + // Then + result.Log.ShouldNotBeNull(); + } + + [Fact] + public void Should_Set_RepositorySettings() + { + // Given + + // When + var result = new FakeMultiFormatIssueProviderFixture("Build.log"); + + // Then + result.RepositorySettings.ShouldNotBeNull(); + } + + [Fact] + public void Should_Set_LogFileContent() + { + // Given + + // When + var result = new FakeMultiFormatIssueProviderFixture("Build.log"); + + // Then + result.LogFileContent.ShouldNotBeNull(); + result.LogFileContent.ShouldNotBeEmpty(); + } + + [Fact] + public void Should_Set_LogFileContent_For_Empty_File() + { + // Given + + // When + var result = new FakeMultiFormatIssueProviderFixture("Empty.log"); + + // Then + result.LogFileContent.ShouldNotBeNull(); + result.LogFileContent.ShouldBeEmpty(); + } + } + + public sealed class TheReadIssuesMethod + { + [Fact] + public void Should_Throw_If_Log_Is_Null() + { + // Given + var fixture = new FakeMultiFormatIssueProviderFixture("Build.log") + { + Log = null + }; + + // When + var result = Record.Exception(() => fixture.ReadIssues()); + + // Then + result.IsInvalidOperationException("No log instance set."); + } + + [Fact] + public void Should_Throw_If_RepositorySettings_Are_Null() + { + // Given + var fixture = new FakeMultiFormatIssueProviderFixture("Build.log") + { + RepositorySettings = null + }; + + // When + var result = Record.Exception(() => fixture.ReadIssues()); + + // Then + result.IsInvalidOperationException("No repository settings set."); + } + + [Fact] + public void Should_Return_Empty_List_For_Empty_File() + { + // Given + var fixture = + new FakeMultiFormatIssueProviderFixture("Empty.log"); + + // When + var result = fixture.ReadIssues(); + + // Then + result.ShouldBeEmpty(); + } + } + } +} diff --git a/src/Cake.Issues.Tests/Testing/FakeConfigurableIssueProviderFixture.cs b/src/Cake.Issues.Tests/Testing/FakeConfigurableIssueProviderFixture.cs new file mode 100644 index 000000000..60722d2ff --- /dev/null +++ b/src/Cake.Issues.Tests/Testing/FakeConfigurableIssueProviderFixture.cs @@ -0,0 +1,15 @@ +namespace Cake.Issues.Tests.Testing +{ + using Cake.Issues.Testing; + + internal sealed class FakeConfigurableIssueProviderFixture + : BaseConfigurableIssueProviderFixture + { + public FakeConfigurableIssueProviderFixture(string fileResourceName) + : base(fileResourceName) + { + } + + protected override string FileResourceNamespace => "Cake.Issues.Tests.Testfiles."; + } +} diff --git a/src/Cake.Issues.Tests/Testing/FakeIssueProviderFixture.cs b/src/Cake.Issues.Tests/Testing/FakeIssueProviderFixture.cs new file mode 100644 index 000000000..35406df52 --- /dev/null +++ b/src/Cake.Issues.Tests/Testing/FakeIssueProviderFixture.cs @@ -0,0 +1,30 @@ +namespace Cake.Issues.Tests.Testing +{ + using System.Collections.Generic; + using Cake.Issues.Testing; + + internal sealed class FakeIssueProviderFixture : BaseIssueProviderFixture + { + private readonly List issues = new List(); + + public FakeIssueProviderFixture() + { + } + + public FakeIssueProviderFixture(IEnumerable issues) + { + // ReSharper disable once PossibleMultipleEnumeration + issues.NotNull(nameof(issues)); + + // ReSharper disable once PossibleMultipleEnumeration + this.issues.AddRange(issues); + } + + protected override IList GetCreateIssueProviderArguments() + { + var result = base.GetCreateIssueProviderArguments(); + result.Add(this.issues); + return result; + } + } +} diff --git a/src/Cake.Issues.Tests/Testing/FakeMultiFormatIssueProviderFixture.cs b/src/Cake.Issues.Tests/Testing/FakeMultiFormatIssueProviderFixture.cs new file mode 100644 index 000000000..96c6fc060 --- /dev/null +++ b/src/Cake.Issues.Tests/Testing/FakeMultiFormatIssueProviderFixture.cs @@ -0,0 +1,15 @@ +namespace Cake.Issues.Tests.Testing +{ + using Cake.Issues.Testing; + + internal sealed class FakeMultiFormatIssueProviderFixture + : BaseMultiFormatIssueProviderFixture + { + public FakeMultiFormatIssueProviderFixture(string fileResourceName) + : base(fileResourceName) + { + } + + protected override string FileResourceNamespace => "Cake.Issues.Tests.Testfiles."; + } +} diff --git a/src/Cake.Issues/ByteArrayExtensions.cs b/src/Cake.Issues/ByteArrayExtensions.cs index f71db8078..946c31e67 100644 --- a/src/Cake.Issues/ByteArrayExtensions.cs +++ b/src/Cake.Issues/ByteArrayExtensions.cs @@ -16,7 +16,7 @@ public static class ByteArrayExtensions /// Converted string. public static string ToStringUsingEncoding(this byte[] value) { - value.NotNullOrEmpty(nameof(value)); + value.NotNull(nameof(value)); return value.ToStringUsingEncoding(false); } @@ -29,6 +29,8 @@ public static string ToStringUsingEncoding(this byte[] value) /// Converted string. public static string ToStringUsingEncoding(this byte[] value, bool skipPreamble) { + value.NotNull(nameof(value)); + return value.ToStringUsingEncoding(Encoding.UTF8, skipPreamble); } @@ -41,18 +43,16 @@ public static string ToStringUsingEncoding(this byte[] value, bool skipPreamble) /// Converted string. public static string ToStringUsingEncoding(this byte[] value, Encoding encoding, bool skipPreamble) { - value.NotNullOrEmpty(nameof(value)); + value.NotNull(nameof(value)); - if (skipPreamble) + if (value.Any() && skipPreamble) { var preamble = encoding.GetPreamble(); - if (preamble.Where((p, i) => p != value[i]).Any()) + if (value.Zip(preamble, (x, y) => x == y).All(x => x)) { - throw new ArgumentException("Value contains no preamble.", nameof(value)); + value = value.Skip(preamble.Length).ToArray(); } - - value = value.Skip(preamble.Length).ToArray(); } return encoding.GetString(value); diff --git a/src/Cake.Issues/IssueProviderSettings.cs b/src/Cake.Issues/IssueProviderSettings.cs index f1b4fa92e..688a0977e 100644 --- a/src/Cake.Issues/IssueProviderSettings.cs +++ b/src/Cake.Issues/IssueProviderSettings.cs @@ -27,7 +27,7 @@ public IssueProviderSettings(FilePath logFilePath) /// Content of the log file. public IssueProviderSettings(byte[] logFileContent) { - logFileContent.NotNullOrEmpty(nameof(logFileContent)); + logFileContent.NotNull(nameof(logFileContent)); this.LogFileContent = logFileContent; }