diff --git a/TextEditor/FileManager/ASCIIFileReader.cs b/TextEditor/FileManager/ASCIIFileReader.cs
index ecc6daf..cdcab63 100644
--- a/TextEditor/FileManager/ASCIIFileReader.cs
+++ b/TextEditor/FileManager/ASCIIFileReader.cs
@@ -21,6 +21,10 @@ public ASCIIFileReader(string fileName)
{
}
+ ///
+ /// Reads data from file.
+ ///
+ /// Array of read strings.
public override string[] Read()
{
return File.ReadAllLines(this.FileName, Encoding.ASCII);
diff --git a/TextEditor/FileManager/TextEditorFileManager.cs b/TextEditor/FileManager/TextEditorFileManager.cs
index d9f22db..cf224f4 100644
--- a/TextEditor/FileManager/TextEditorFileManager.cs
+++ b/TextEditor/FileManager/TextEditorFileManager.cs
@@ -51,6 +51,10 @@ public TextEditorDocument OpenFileUsingEncoding(string fileName, Encoding encodi
{
fileReader = new UTF8FileReader(fileName);
}
+ else if (encoding == Encoding.Unicode)
+ {
+ fileReader = new UnicodeFileReader(fileName);
+ }
else
{
fileReader = new DefaultFileReader(fileName);
diff --git a/TextEditor/FileManager/UTF8FileReader.cs b/TextEditor/FileManager/UTF8FileReader.cs
index c807328..5fd214b 100644
--- a/TextEditor/FileManager/UTF8FileReader.cs
+++ b/TextEditor/FileManager/UTF8FileReader.cs
@@ -9,15 +9,23 @@
namespace TextEditor.FileManager
{
///
- /// Provides agorythm to reading UTF-8 encoded file
+ /// Provides algorithm to reading UTF-8 encoded file.
///
public class UTF8FileReader : FileReaderStrategy
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Path to read file.
public UTF8FileReader(string fileName)
: base(fileName)
{
}
+ ///
+ /// Reads data from file.
+ ///
+ /// Array of read strings.
public override string[] Read()
{
return File.ReadAllLines(this.FileName, Encoding.UTF8);
diff --git a/TextEditor/FileManager/UnicodeFileReader.cs b/TextEditor/FileManager/UnicodeFileReader.cs
new file mode 100644
index 0000000..c5bc5dd
--- /dev/null
+++ b/TextEditor/FileManager/UnicodeFileReader.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TextEditor.FileManager
+{
+ ///
+ /// Provides algorithm to reading Unicode encoded file.
+ ///
+ public class UnicodeFileReader : FileReaderStrategy
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Path to read file.
+ public UnicodeFileReader(string fileName)
+ : base(fileName)
+ {
+ }
+
+ ///
+ /// Reads data from file.
+ ///
+ /// Array of read strings.
+ public override string[] Read()
+ {
+ return File.ReadAllLines(this.FileName, Encoding.Unicode);
+ }
+ }
+}
diff --git a/TextEditor/MainWindow.xaml b/TextEditor/MainWindow.xaml
index 38d60e5..009b1b3 100644
--- a/TextEditor/MainWindow.xaml
+++ b/TextEditor/MainWindow.xaml
@@ -50,8 +50,9 @@
diff --git a/TextEditor/MainWindow.xaml.cs b/TextEditor/MainWindow.xaml.cs
index a2a328b..4bd7d2f 100644
--- a/TextEditor/MainWindow.xaml.cs
+++ b/TextEditor/MainWindow.xaml.cs
@@ -102,6 +102,9 @@ private void EncodingMenuItem_Click(object sender, RoutedEventArgs e)
case "ASCII":
encoding = Encoding.ASCII;
break;
+ case "Unicode":
+ encoding = Encoding.Unicode;
+ break;
default:
throw new ArgumentException("Unknown encoding");
}
diff --git a/TextEditor/TextEditor.csproj b/TextEditor/TextEditor.csproj
index aad7c3b..770e4cd 100644
--- a/TextEditor/TextEditor.csproj
+++ b/TextEditor/TextEditor.csproj
@@ -97,6 +97,7 @@
True
+
True
diff --git a/TextEditorTests/FileManagerTests.cs b/TextEditorTests/FileManagerTests.cs
index aa9a297..09f49f3 100644
--- a/TextEditorTests/FileManagerTests.cs
+++ b/TextEditorTests/FileManagerTests.cs
@@ -38,6 +38,12 @@ public void TextEditorFileManager_OpenFileUsingEncoding()
{
this.document = this.fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.Default);
Assert.IsNotNull(this.document, "FileManager couldn't open document");
+ this.document = this.fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.ASCII);
+ Assert.IsNotNull(this.document, "FileManager couldn't open document");
+ this.document = this.fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.Unicode);
+ Assert.IsNotNull(this.document, "FileManager couldn't open document");
+ this.document = this.fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.UTF8);
+ Assert.IsNotNull(this.document, "FileManager couldn't open document");
}
[TestMethod]