-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed up some bugs found while testing. Added UTF32 Big Endian
- Loading branch information
Showing
3 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
Source/MoreDotNet.Test/Extensions/Common/ByteArrayExtensions/GetStringTests.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,119 @@ | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace MoreDotNet.Tests.Extensions.Common.ByteArrayExtensions | ||
{ | ||
using MoreDotNet.Extensions.Common; | ||
using Xunit; | ||
|
||
public class GetStringTests | ||
{ | ||
[Fact] | ||
public void GetString_NullBuffer_ShouldReturnEmptyString() | ||
{ | ||
byte[] buffer = null; | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(string.Empty, result); | ||
} | ||
|
||
[Fact] | ||
public void GetString_ZeroLengthBuffer_ShouldReturnEmptyString() | ||
{ | ||
var buffer = new byte[] { }; | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(string.Empty, result); | ||
} | ||
|
||
[Fact] | ||
public void GetString_UTF8_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net", Encoding.UTF8); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
|
||
[Fact] | ||
public void GetString_Unicode_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net", Encoding.Unicode); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
|
||
[Fact] | ||
public void GetString_BigEndianUnicode_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net", Encoding.BigEndianUnicode); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
|
||
[Fact] | ||
public void GetString_UTF32_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net", Encoding.UTF32); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
|
||
[Fact] | ||
public void GetString_UTF32BigEndian_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net", new UTF32Encoding(true, true)); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
|
||
[Fact] | ||
public void GetString_UTF7_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net", Encoding.UTF7); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
|
||
[Fact] | ||
public void GetString_ANSI_Specified_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net", Encoding.Default); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
|
||
[Fact] | ||
public void GetString_NoEncodingSpecified_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net"); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
|
||
[Fact] | ||
public void GetString_ASCII_ShouldReturnProperString() | ||
{ | ||
File.WriteAllText("temp.txt", "More Dot Net", Encoding.ASCII); | ||
var buffer = File.ReadAllBytes("temp.txt"); | ||
var result = buffer.GetString(); | ||
|
||
Assert.Equal(result, "More Dot Net"); | ||
} | ||
} | ||
} |
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
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