Skip to content

Commit

Permalink
Merge branch 'release/0.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Sep 5, 2018
2 parents beb42f5 + 7264a35 commit 389fd31
Show file tree
Hide file tree
Showing 16 changed files with 566 additions and 95 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Issues.Testing.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Common helpers for testing add-ins based on Cake.Issues
<repository type="git" url="https://github.com/cake-contrib/Cake.Issues"/>
<copyright>Copyright © BBT Software AG and contributors</copyright>
<tags>Cake Script Cake-Issues Issues Testing</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues/releases/tag/0.6.1</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues/releases/tag/0.6.2</releaseNotes>
</metadata>
<files>
<file src="netstandard2.0\Cake.Issues.Testing.dll" target="lib\netstandard2.0" />
Expand Down
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Issues.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
<repository type="git" url="https://github.com/cake-contrib/Cake.Issues"/>
<copyright>Copyright © BBT Software AG and contributors</copyright>
<tags>Cake Script Cake-Issues CodeAnalysis Linting Issues</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues/releases/tag/0.6.1</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues/releases/tag/0.6.2</releaseNotes>
</metadata>
<files>
<file src="netstandard2.0\Cake.Issues.dll" target="lib\netstandard2.0" />
Expand Down
15 changes: 13 additions & 2 deletions src/Cake.Issues.Testing/BaseConfigurableIssueProviderFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ public abstract class BaseConfigurableIssueProviderFixture<TIssueProvider, TSett
/// <param name="fileResourceName">Name of the resource to load.</param>
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();
}
Expand Down Expand Up @@ -52,7 +63,7 @@ protected override IList<object> GetCreateIssueProviderArguments()
/// <returns>Instance of the issue provider settings.</returns>
protected virtual IList<object> GetCreateIssueProviderSettingsArguments()
{
if (this.LogFileContent == null || !this.LogFileContent.Any())
if (this.LogFileContent == null)
{
throw new InvalidOperationException("No log content set.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>();
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<byte>();
var format = new FakeLogFileFormat(new FakeLog());

// When
Expand Down
121 changes: 50 additions & 71 deletions src/Cake.Issues.Tests/ByteArrayExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>();

// 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);
}
}

Expand All @@ -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<byte>();
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<byte>();

// When
var result = byteArrayValue.ToStringUsingEncoding(true);

// Then
result.ShouldBe(stringValue);
result.ShouldBe(string.Empty);
}
}

Expand All @@ -141,78 +131,67 @@ public void Should_Throw_If_Value_Is_Null()
}

[Fact]
public void Should_Throw_If_Value_Is_Empty()
{
// Given
byte[] value = Array.Empty<byte>();
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;
var stringValue = "foo🐱bar";
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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Cake.Issues.Tests/Cake.Issues.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

<ItemGroup>
<None Remove="Testfiles\Build.log" />
<None Remove="Testfiles\Empty.log" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Testfiles\Empty.log" />
<EmbeddedResource Include="Testfiles\Build.log" />
</ItemGroup>

Expand Down
12 changes: 6 additions & 6 deletions src/Cake.Issues.Tests/IssueProviderSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>();
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<byte>();

// When
var settings = new IssueProviderSettings(logFileContent);
Expand Down
Empty file.
Loading

0 comments on commit 389fd31

Please sign in to comment.