Skip to content

Commit

Permalink
Improved documentation on FileReader
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-here committed Oct 12, 2015
1 parent 6ed5eae commit b059a7d
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 2 deletions.
4 changes: 4 additions & 0 deletions TextEditor/FileManager/ASCIIFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public ASCIIFileReader(string fileName)
{
}

/// <summary>
/// Reads data from file.
/// </summary>
/// <returns>Array of read strings.</returns>
public override string[] Read()
{
return File.ReadAllLines(this.FileName, Encoding.ASCII);
Expand Down
4 changes: 4 additions & 0 deletions TextEditor/FileManager/TextEditorFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion TextEditor/FileManager/UTF8FileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@
namespace TextEditor.FileManager
{
/// <summary>
/// Provides agorythm to reading UTF-8 encoded file
/// Provides algorithm to reading UTF-8 encoded file.
/// </summary>
public class UTF8FileReader : FileReaderStrategy
{
/// <summary>
/// Initializes a new instance of the <see cref="UTF8FileReader"/> class.
/// </summary>
/// <param name="fileName">Path to read file.</param>
public UTF8FileReader(string fileName)
: base(fileName)
{
}

/// <summary>
/// Reads data from file.
/// </summary>
/// <returns>Array of read strings.</returns>
public override string[] Read()
{
return File.ReadAllLines(this.FileName, Encoding.UTF8);
Expand Down
33 changes: 33 additions & 0 deletions TextEditor/FileManager/UnicodeFileReader.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Provides algorithm to reading Unicode encoded file.
/// </summary>
public class UnicodeFileReader : FileReaderStrategy
{
/// <summary>
/// Initializes a new instance of the <see cref="UnicodeFileReader"/> class.
/// </summary>
/// <param name="fileName">Path to read file.</param>
public UnicodeFileReader(string fileName)
: base(fileName)
{
}

/// <summary>
/// Reads data from file.
/// </summary>
/// <returns>Array of read strings.</returns>
public override string[] Read()
{
return File.ReadAllLines(this.FileName, Encoding.Unicode);
}
}
}
3 changes: 2 additions & 1 deletion TextEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
</MenuItem.Header>
<MenuItem Header="Encoding" Background="#FF2A2F3A" HorizontalAlignment="Left" Width="145">
<MenuItem Header="Auto" Background="#FF2A2F3A" HorizontalAlignment="Left" Width="145" Click="EncodingMenuItem_Click"/>
<MenuItem Header="UTF8" Background="#FF2A2F3A" HorizontalAlignment="Left" Width="145" Click="EncodingMenuItem_Click"/>
<MenuItem Header="ASCII" Background="#FF2A2F3A" HorizontalAlignment="Left" Width="145" Click="EncodingMenuItem_Click"/>
<MenuItem Header="Unicode" Background="#FF2A2F3A" HorizontalAlignment="Left" Width="145" Click="EncodingMenuItem_Click"/>
<MenuItem Header="UTF8" Background="#FF2A2F3A" HorizontalAlignment="Left" Width="145" Click="EncodingMenuItem_Click"/>
</MenuItem>
</MenuItem>
</Menu>
Expand Down
3 changes: 3 additions & 0 deletions TextEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
1 change: 1 addition & 0 deletions TextEditor/TextEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</Compile>
<Compile Include="FileManager\DefaultFileReader.cs" />
<Compile Include="FileManager\UnicodeFileReader.cs" />
<Compile Include="FileManager\UTF8FileReader.cs">
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</Compile>
Expand Down
6 changes: 6 additions & 0 deletions TextEditorTests/FileManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b059a7d

Please sign in to comment.