-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ottorinobruni/add-base64
Add base64
- Loading branch information
Showing
9 changed files
with
260 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Buffers.Text; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using TextCase.Converters; | ||
using TextCase.Extensions; | ||
using Xunit; | ||
|
||
namespace TextCase.UnitTests | ||
{ | ||
public class Base64DecodeCaseConverterTest | ||
{ | ||
[Theory] | ||
[InlineData("SGVsbG8gV29ybGQ=", "Hello World")] | ||
[InlineData("SEVMTE8gV09STEQ=", "HELLO WORLD")] | ||
[InlineData("SUNIIEJJTiBHTMOcQ0tMSUNI", "ICH BIN GLÜCKLICH")] | ||
[InlineData("ICBDaGUgT3JlIFNvbm8/IA==", " Che Ore Sono? ")] | ||
public void ToBase64DecodeCase_WhenValidInput_ShouldReturnDecodedString(string input, string expected) | ||
{ | ||
// Setup | ||
var service = new Base64DecodeCaseConverter(); | ||
|
||
// Execute | ||
var actual = service.Convert(input); | ||
|
||
// Assert | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData("SGVsbG8gV29ybGQ=", "Hello World")] | ||
[InlineData("SEVMTE8gV09STEQ=", "HELLO WORLD")] | ||
[InlineData("SUNIIEJJTiBHTMOcQ0tMSUNI", "ICH BIN GLÜCKLICH")] | ||
[InlineData("ICBDaGUgT3JlIFNvbm8/IA==", " Che Ore Sono? ")] | ||
public void ToBase64DecodeCase_WhenBase64DecodeCase_TextShouldBeBase64DecodeCase(string input, string output) | ||
{ | ||
// Execute | ||
var convertedText = input.ToBase64DecodeCase(); | ||
|
||
// Assert | ||
var expected = output; | ||
var actual = convertedText; | ||
Assert.Equal(expected, actual); | ||
} | ||
} | ||
} |
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,48 @@ | ||
using System; | ||
using System.Buffers.Text; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using TextCase.Converters; | ||
using TextCase.Extensions; | ||
using Xunit; | ||
|
||
namespace TextCase.UnitTests | ||
{ | ||
public class Base64EncodeCaseConverterTest | ||
{ | ||
[Theory] | ||
[InlineData("Hello World", "SGVsbG8gV29ybGQ=")] | ||
[InlineData("HELLO WORLD", "SEVMTE8gV09STEQ=")] | ||
[InlineData("ICH BIN GLÜCKLICH", "SUNIIEJJTiBHTMOcQ0tMSUNI")] | ||
[InlineData(" Che Ore Sono? ", "ICBDaGUgT3JlIFNvbm8/IA==")] | ||
public void ToBase64EncodeCase_WhenValidInput_ShouldReturnBase64EncodedString(string input, string expected) | ||
{ | ||
// Setup | ||
var service = new Base64EncodeCaseConverter(); | ||
|
||
// Execute | ||
var actual = service.Convert(input); | ||
|
||
// Assert | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello World", "SGVsbG8gV29ybGQ=")] | ||
[InlineData("HELLO WORLD", "SEVMTE8gV09STEQ=")] | ||
[InlineData("ICH BIN GLÜCKLICH", "SUNIIEJJTiBHTMOcQ0tMSUNI")] | ||
[InlineData(" Che Ore Sono? ", "ICBDaGUgT3JlIFNvbm8/IA==")] | ||
public void ToBase64EncodeCase_WhenBase64EncodeCase_TextShouldBeBase64EncodeCase(string input, string output) | ||
{ | ||
// Execute | ||
var convertedText = input.ToBase64EncodeCase(); | ||
|
||
// Assert | ||
var expected = output; | ||
var actual = convertedText; | ||
Assert.Equal(expected, actual); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace TextCase.Converters | ||
{ | ||
/// <summary> | ||
/// Represents a base64 decode converter. | ||
/// </summary> | ||
public class Base64DecodeCaseConverter : ICaseConverter | ||
{ | ||
/// <summary> | ||
/// Converts the specified text to base64 decode. | ||
/// </summary> | ||
/// <param name="text">The string to convert to base64 decode.</param> | ||
/// <returns>The specified text converted to base64 decode.</returns> | ||
public string Convert(string text) | ||
{ | ||
if (string.IsNullOrEmpty(text)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
try | ||
{ | ||
return Encoding.UTF8.GetString(System.Convert.FromBase64String(text)); | ||
} | ||
catch (FormatException) | ||
{ | ||
return text; | ||
} | ||
} | ||
} | ||
|
||
} |
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,23 @@ | ||
using System.Text; | ||
|
||
namespace TextCase.Converters | ||
{ | ||
/// <summary> | ||
/// Represents a base64 encode converter. | ||
/// </summary> | ||
public class Base64EncodeCaseConverter : ICaseConverter | ||
{ | ||
/// <summary> | ||
/// Converts the specified text to base64 encode. | ||
/// </summary> | ||
/// <param name="text">The string to convert to base64 encode.</param> | ||
/// <returns>The specified text converted to base64 encode.</returns> | ||
public string Convert(string text) | ||
{ | ||
return string.IsNullOrWhiteSpace(text) ? | ||
string.Empty : | ||
System.Convert.ToBase64String(Encoding.UTF8.GetBytes(text)); | ||
} | ||
} | ||
|
||
} |
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
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