Exemplo n.º 1
0
        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();
            var serializer   = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            serializer.Serialize(memoryStream, fileSystem);
            memoryStream.Flush();
            memoryStream.Position = 0;
            fileSystem            = (MockFileSystem)serializer.Deserialize(memoryStream);
            memoryStream.Dispose();

            // Assert
            Assert.AreEqual(
                expected,
                fileSystem.GetFile(path).Contents);
            Assert.AreEqual(
                content,
                fileSystem.File.ReadAllBytes(path));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deserializes the user.
 /// </summary>
 /// <param name="serializedaum">The serialized AuthUserData.</param>
 /// <returns></returns>
 /// <remarks></remarks>
 private static AuthUserData DeserializeUser(string serializedaud)
 {
     Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     IO.MemoryStream mem = new IO.MemoryStream(Convert.FromBase64String(serializedaud));
     return((AuthUserData)bf.Deserialize(mem));
 }