Exemple #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));
        }
Exemple #2
0
 /// <summary>
 /// Serializes the user.
 /// </summary>
 /// <param name="aum">The AuthUserData.</param>
 /// <returns></returns>
 /// <remarks>The AuthUserData is a custom serializable poco that holds the data</remarks>
 private static string SerializeUser(AuthUserData aud)
 {
     Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     IO.MemoryStream mem = new IO.MemoryStream();
     bf.Serialize(mem, aud);
     return(Convert.ToBase64String(mem.ToArray()));
 }
        public void Is_Serializable()
        {
            var fileSystem = new FileSystem();
            var memoryStream = new MemoryStream();

            var serializer = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            serializer.Serialize(memoryStream, fileSystem);

            Assert.That(memoryStream.Length > 0, "Length didnt increase after serialization task.");
        }
        public void Is_Serializable()
        {
            var fileSystem   = new FileSystem();
            var memoryStream = new MemoryStream();

            var serializer = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            serializer.Serialize(memoryStream, fileSystem);

            Assert.True(memoryStream.Length > 0, "Length didn't increase after serialization task.");
        }
Exemple #5
0
        public void Is_Serializable()
        {
            var fileSystem   = new FileSystem();
            var memoryStream = new MemoryStream();

            var serializer = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();

#pragma warning disable SYSLIB0011
            serializer.Serialize(memoryStream, fileSystem);
#pragma warning restore SYSLIB0011

            Assert.That(memoryStream.Length > 0, "Length didn't increase after serialization task.");
        }
        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.");
        }
        public void MockFileSystem_ByDefault_IsSerializable()
        {
            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 MemoryStream();

            var serializer = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            serializer.Serialize(memoryStream, fileSystem);

            Assert.That(memoryStream.Length > 0, "Length didn't increase after serialization task.");
        }
Exemple #8
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));
 }