Пример #1
0
        /// <summary>
        /// Copy from the given file (<paramref name="a_source"/> to this one overwriting if necessary..
        /// </summary>
        /// <param name="a_source">File from which to copy.</param>
        public void CopyFrom(IFile a_source)
        {
            #region Argument Validation

            if (a_source == null)
            {
                throw new ArgumentNullException(nameof(a_source));
            }

            #endregion

            if (!a_source.Directory.Exists)
            {
                throw new DirectoryNotFoundException("Cannot CopyTo because directory of source file does not exist");
            }

            if (!a_source.Exists)
            {
                throw new FileNotFoundException("Cannot CopyTo because source file does not exist.");
            }

            TestFileInstance instance = null;

            var source = a_source as TestFile;
            if (source != null)
            {
                instance = source.Instance.Clone();
            }

            FileSystem.StageFile(Path, instance);
        }
Пример #2
0
        /// <summary>
        /// Create a file with the given text (<paramref name="a_text"/>) as its contents.
        /// </summary>
        /// <param name="a_text">Text contents.</param>
        /// <param name="a_encoding"></param>
        public void Create(string a_text, Encoding a_encoding = null)
        {
            a_encoding = a_encoding ?? Encoding.UTF8;

            var fileStats = new TestFileInstance();

            fileStats.Data                = a_encoding.GetBytes(a_text);
            fileStats.Size                = fileStats.Data.Length;
            fileStats.CreatedTimeUtc      = DateTime.UtcNow;
            fileStats.LastModifiedTimeUtc = DateTime.UtcNow;

            FileSystem.StageFile(Path, fileStats);
        }
Пример #3
0
        /// <summary>
        /// Create the file with the given stream (<paramref name="a_contents"/>) as its contents.
        /// </summary>
        /// <param name="a_contents">Stream contents.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_contents"/> is null.</exception>
        public void Create(Stream a_contents)
        {
            #region Argument Validation

            if (a_contents == null)
            {
                throw new ArgumentNullException(nameof(a_contents));
            }

            #endregion

            var fileStats = new TestFileInstance();
            fileStats.Size                = a_contents.Length;
            fileStats.CreatedTimeUtc      = DateTime.UtcNow;
            fileStats.LastModifiedTimeUtc = DateTime.UtcNow;

            fileStats.Data = new byte[a_contents.Length];
            a_contents.Read(fileStats.Data, 0, (int)a_contents.Length);

            FileSystem.StageFile(Path, fileStats);
        }
Пример #4
0
            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="a_instance">File instance.</param>
            /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_instance"/> is null.</exception>
            public TestMemoryStream(TestFileInstance a_instance)
            {
                #region Argument Validation

                if (a_instance == null)
                {
                    throw new ArgumentNullException(nameof(a_instance));
                }

                #endregion

                _instance = a_instance;

                if (a_instance.Data.Any())
                {
                    var writer = new BinaryWriter(this);
                    writer.Write(_instance.Data, 0, _instance.Data.Length);
                    writer.Flush();
                    Seek(0, SeekOrigin.Begin);
                }
            }
Пример #5
0
        /// <summary>
        /// Create a file with the given path (<paramref name="a_path"/>) within this file system.
        /// </summary>
        /// <param name="a_path">File path.</param>
        /// <param name="a_file">File stats.</param>
        /// <returns>This file system used with fluent interface.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_path"/> is null.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_file"/> is null.</exception>
        public TestFile StageFile(string a_path, TestFileInstance a_file = null)
        {
            #region Argument Validation

            if (a_path == null)
            {
                throw new ArgumentNullException(nameof(a_path));
            }

            #endregion

            a_path = PreparePath(a_path);

            var pb        = PathBuilder.Create(a_path).WithRoot(PathBuilder.WindowsDriveRoot);
            var directory = pb.Parent();
            var file      = pb.Name();

            StageDirectory(directory);

            var files = _directories[directory];
            files[file] = a_file ?? new TestFileInstance();

            return(new TestFile(this, a_path));
        }