Skip to content
Browse files

added Serialization support and associated test to MockFileSystem hel…

…pers.
  • Loading branch information...
1 parent 6576089 commit 2a6ab578c4fe66ad490d8f73619aa7233ce14c32 @ericnewton76 ericnewton76 committed
View
1 System.IO.Abstractions/DirectoryBase.cs
@@ -2,6 +2,7 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public abstract class DirectoryBase
{
public abstract DirectoryInfoBase CreateDirectory(string path);
View
1 System.IO.Abstractions/DirectoryInfoBase.cs
@@ -2,6 +2,7 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public abstract class DirectoryInfoBase : FileSystemInfoBase
{
public abstract void Create();
View
1 System.IO.Abstractions/DirectoryInfoFactory.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions
{
+ [Serializable]
internal class DirectoryInfoFactory : IDirectoryInfoFactory
{
public DirectoryInfoBase FromDirectoryName(string directoryName)
View
1 System.IO.Abstractions/DirectoryInfoWrapper.cs
@@ -2,6 +2,7 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public class DirectoryInfoWrapper : DirectoryInfoBase
{
readonly DirectoryInfo instance;
View
1 System.IO.Abstractions/DirectoryWrapper.cs
@@ -2,6 +2,7 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public class DirectoryWrapper : DirectoryBase
{
public override DirectoryInfoBase CreateDirectory(string path)
View
1 System.IO.Abstractions/FileBase.cs
@@ -3,6 +3,7 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public abstract class FileBase
{
public abstract void AppendAllText(string path, string contents);
View
1 System.IO.Abstractions/FileInfoBase.cs
@@ -2,6 +2,7 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public abstract class FileInfoBase : FileSystemInfoBase
{
public abstract StreamWriter AppendText();
View
1 System.IO.Abstractions/FileInfoFactory.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions
{
+ [Serializable]
internal class FileInfoFactory : IFileInfoFactory
{
public FileInfoBase FromFileName(string fileName)
View
1 System.IO.Abstractions/FileInfoWrapper.cs
@@ -2,6 +2,7 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public class FileInfoWrapper : FileInfoBase
{
readonly FileInfo instance;
View
1 System.IO.Abstractions/FileSystem.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public class FileSystem : IFileSystem
{
DirectoryBase directory;
View
1 System.IO.Abstractions/FileSystemInfoBase.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public abstract class FileSystemInfoBase
{
public abstract void Delete();
View
1 System.IO.Abstractions/FileWrapper.cs
@@ -3,6 +3,7 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public class FileWrapper : FileBase
{
public override void AppendAllText(string path, string contents)
View
1 System.IO.Abstractions/PathBase.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public abstract class PathBase
{
public abstract char AltDirectorySeparatorChar { get; }
View
1 System.IO.Abstractions/PathWrapper.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions
{
+ [Serializable]
public class PathWrapper : PathBase
{
public override char AltDirectorySeparatorChar
View
27 TestHelpers.Tests/FileSystemTests.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace System.IO.Abstractions.TestingHelpers.Tests
+{
+ [TestFixture]
+ class FileSystemTests
+ {
+
+ [Test]
+ public void Is_Serializable()
+ {
+ var fileSystem = new System.IO.Abstractions.FileSystem();
+ var memoryStream = new System.IO.MemoryStream();
+
+ System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();
+ serializer.Serialize(memoryStream, fileSystem);
+
+ Assert.That(memoryStream.Length > 0, "Length didnt increase after serialization task.");
+ }
+
+
+ }
+}
View
17 TestHelpers.Tests/MockFileSystemTests.cs
@@ -58,5 +58,22 @@ public void MockFileSystem_GetFile_ShouldReturnFileRegisteredInConstructorWhenPa
// Assert
Assert.AreEqual(file1, result);
}
+
+ [Test]
+ public void Is_Serializable()
+ {
+ var file1 = new MockFileData("Demo\r\ntext\ncontent\rvalue");
+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
+ {
+ { @"c:\something\demo.txt", file1 },
+ { @"c:\something\other.gif", new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) }
+ });
+ var memoryStream = new System.IO.MemoryStream();
+
+ System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();
+ serializer.Serialize(memoryStream, fileSystem);
+
+ Assert.That(memoryStream.Length > 0, "Length didnt increase after serialization task.");
+ }
}
}
View
1 TestHelpers.Tests/TestHelpers.Tests.csproj
@@ -74,6 +74,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="FileSystemTests.cs" />
<Compile Include="MockDirectoryTests.cs" />
<Compile Include="MockFileInfoFactoryTests.cs" />
<Compile Include="MockFileInfoTests.cs" />
View
1 TestingHelpers/MockDirectory.cs
@@ -5,6 +5,7 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
public class MockDirectory : DirectoryBase
{
readonly FileBase fileBase;
View
1 TestingHelpers/MockDirectoryInfo.cs
@@ -3,6 +3,7 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
public class MockDirectoryInfo : DirectoryInfoBase
{
readonly IMockFileDataAccessor mockFileDataAccessor;
View
1 TestingHelpers/MockDirectoryInfoFactory.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
public class MockDirectoryInfoFactory : IDirectoryInfoFactory
{
readonly IMockFileDataAccessor mockFileSystem;
View
1 TestingHelpers/MockFile.cs
@@ -3,6 +3,7 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
public class MockFile : FileBase
{
readonly IMockFileDataAccessor mockFileDataAccessor;
View
1 TestingHelpers/MockFileData.cs
@@ -3,6 +3,7 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
public class MockFileData
{
static readonly Encoding defaultEncoding = Encoding.UTF8;
View
1 TestingHelpers/MockFileInfo.cs
@@ -2,6 +2,7 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
internal class MockFileInfo : FileInfoBase
{
readonly IMockFileDataAccessor mockFileSystem;
View
1 TestingHelpers/MockFileInfoFactory.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
public class MockFileInfoFactory : IFileInfoFactory
{
readonly IMockFileDataAccessor mockFileSystem;
View
1 TestingHelpers/MockFileStream.cs
@@ -1,5 +1,6 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
public class MockFileStream : MemoryStream
{
readonly IMockFileDataAccessor mockFileDataAccessor;
View
1 TestingHelpers/MockFileSystem.cs
@@ -3,6 +3,7 @@
namespace System.IO.Abstractions.TestingHelpers
{
+ [Serializable]
public class MockFileSystem : IFileSystem, IMockFileDataAccessor
{
readonly IDictionary<string, MockFileData> files;
View
1 TestingHelpers/MockPath.cs
@@ -8,6 +8,7 @@ namespace System.IO.Abstractions.TestingHelpers
/// <summary>
/// PathWrapper calls direct to Path but all this does is string manipulation so we can inherit directly from PathWrapper as no IO is done
/// </summary>
+ [Serializable]
public class MockPath : PathWrapper
{

0 comments on commit 2a6ab57

Please sign in to comment.
Something went wrong with that request. Please try again.