Ejemplo n.º 1
0
        public string Export()
        {
            var s      = default(Stream);
            var result = "";

            try
            {
                // restore path
                if (!string.IsNullOrEmpty(_setting.Location) &&
                    !Directory.Exists(_setting.Location))
                {
                    Directory.CreateDirectory(_setting.Location);
                }

                using (s = File.Open(_setting.FullPath, FileMode.Create))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(s, BinaryIO.ToBytes(_data));
                    result = _setting.FullPath;
                }
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public void ExportRepositoryToByteArray()
        {
            // arrange
            var input = new TestRepository {
                MyProperty = "hello test"
            };

            // act
            var bytes  = BinaryIO.ToBytes(input);
            var result = BinaryIO.FromBytes <TestRepository>(bytes);

            // assert
            Assert.AreEqual(result.MyProperty, input.MyProperty);
        }