-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added IsBinary extension method for determining whether a given FileI…
…nfo contains binary or text data
- Loading branch information
Showing
2 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
Easy.Common.Tests.Unit/FileAndDirectoryExtensions/FileIsBinaryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
namespace Easy.Common.Tests.Unit.FileAndDirectoryExtensions | ||
{ | ||
using System.IO; | ||
using Easy.Common.Extensions; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
[TestFixture] | ||
internal sealed class FileIsBinaryTests | ||
{ | ||
[Test] | ||
public void When_checking_an_empty_file() | ||
{ | ||
var tmpFile = new FileInfo(Path.GetTempFileName()); | ||
try | ||
{ | ||
tmpFile.IsBinary().ShouldBeFalse(); | ||
} finally | ||
{ | ||
tmpFile.Delete(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void When_checking_a_non_empty_text_file() | ||
{ | ||
var tmpFile = new FileInfo(Path.GetTempFileName()); | ||
try | ||
{ | ||
File.WriteAllText(tmpFile.FullName, "Foo"); | ||
tmpFile.IsBinary().ShouldBeFalse(); | ||
} finally | ||
{ | ||
tmpFile.Delete(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void When_checking_a_text_file_with_tab_only() | ||
{ | ||
var tmpFile = new FileInfo(Path.GetTempFileName()); | ||
try | ||
{ | ||
File.WriteAllText(tmpFile.FullName, new string('\t', 1)); | ||
tmpFile.IsBinary().ShouldBeFalse(); | ||
} finally | ||
{ | ||
tmpFile.Delete(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void When_checking_a_text_file_with_carriange_return_only() | ||
{ | ||
var tmpFile = new FileInfo(Path.GetTempFileName()); | ||
try | ||
{ | ||
File.WriteAllText(tmpFile.FullName, new string('\r', 1)); | ||
tmpFile.IsBinary().ShouldBeFalse(); | ||
} finally | ||
{ | ||
tmpFile.Delete(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void When_checking_a_text_file_with_newline_only() | ||
{ | ||
var tmpFile = new FileInfo(Path.GetTempFileName()); | ||
try | ||
{ | ||
File.WriteAllText(tmpFile.FullName, new string('\n', 1)); | ||
tmpFile.IsBinary().ShouldBeFalse(); | ||
} finally | ||
{ | ||
tmpFile.Delete(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void When_checking_an_empty_binary_file() | ||
{ | ||
var tmpFile = new FileInfo(Path.GetTempFileName()); | ||
try | ||
{ | ||
File.WriteAllBytes(tmpFile.FullName, new byte[0]); | ||
tmpFile.IsBinary().ShouldBeFalse(); | ||
} finally | ||
{ | ||
tmpFile.Delete(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void When_checking_a_non_empty_binary_file() | ||
{ | ||
var tmpFile = new FileInfo(Path.GetTempFileName()); | ||
try | ||
{ | ||
File.WriteAllBytes(tmpFile.FullName, new byte[] {1}); | ||
tmpFile.IsBinary().ShouldBeTrue(); | ||
} finally | ||
{ | ||
tmpFile.Delete(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters