-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathMockFileSystemSerializationTests.cs
More file actions
42 lines (36 loc) · 1.41 KB
/
MockFileSystemSerializationTests.cs
File metadata and controls
42 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#if !NET9_0_OR_GREATER
namespace System.IO.Abstractions.TestingHelpers.Tests
{
using NUnit.Framework;
using Text;
using XFS = MockUnixSupport;
[TestFixture]
class MockFileSystemSerializationTests
{
[Test]
public void SerializationBytes()
{
// Arrange
string path = XFS.Path(@"c:\something\demo.txt");
var content = "Hello there!" + Environment.NewLine + "Second line!" + Environment.NewLine;
var expected = Encoding.ASCII.GetBytes(content); //Convert a C# string to a byte array
var fileSystem = new MockFileSystem();
fileSystem.AddDirectory(XFS.Path(@"c:\something"));
fileSystem.File.WriteAllBytes(path, expected);
//Act
var memoryStream = new MemoryStream();
#pragma warning disable SYSLIB0011
var serializer = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();
serializer.Serialize(memoryStream, fileSystem);
memoryStream.Flush();
memoryStream.Position = 0;
fileSystem = (MockFileSystem)serializer.Deserialize(memoryStream);
#pragma warning restore SYSLIB0011
memoryStream.Dispose();
// Assert
Assert.That(fileSystem.GetFile(path).Contents, Is.EqualTo(expected));
Assert.That(fileSystem.File.ReadAllBytes(path), Is.EqualTo(content));
}
}
}
#endif