예제 #1
0
        /// <summary>
        /// Copy this file to the given file (<paramref name="a_dest"/>).
        /// </summary>
        /// <param name="a_dest">File to which to copy.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_dest"/> is null.</exception>
        public void CopyTo(IFile a_dest)
        {
            #region Argument Validation

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

            #endregion

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

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

            var stats = new TestFileStats
            {
                Size                = Size,
                CreatedTimeUtc      = DateTime.UtcNow,
                LastModifiedTimeUtc = DateTime.UtcNow,
            };

            FileSystem.StageFile(a_dest.Path, stats);
        }
예제 #2
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 TestFileStats();
            fileStats.Size                = a_contents.Length;
            fileStats.CreatedTimeUtc      = DateTime.UtcNow;
            fileStats.LastModifiedTimeUtc = DateTime.UtcNow;

            FileSystem.StageFile(Path, fileStats);
        }
예제 #3
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_stats">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_stats"/> is null.</exception>
        public TestFile StageFile(string a_path, TestFileStats a_stats = 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_stats ?? new TestFileStats();

            return(new TestFile(this, a_path));
        }
예제 #4
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_stats">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_stats"/> is null.</exception>
        public TestFile StageFile(string a_path, TestFileStats a_stats = 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_stats ?? new TestFileStats();

            return new TestFile(this, a_path);
        }
예제 #5
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 TestFileStats();
            fileStats.Size = a_contents.Length;
            fileStats.CreatedTimeUtc = DateTime.UtcNow;
            fileStats.LastModifiedTimeUtc = DateTime.UtcNow;

            FileSystem.StageFile(Path, fileStats);
        }
예제 #6
0
        /// <summary>
        /// Copy this file to the given file (<paramref name="a_dest"/>).
        /// </summary>
        /// <param name="a_dest">File to which to copy.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_dest"/> is null.</exception>
        public void CopyTo(IFile a_dest)
        {
            #region Argument Validation

            if (a_dest == null)
                throw new ArgumentNullException(nameof(a_dest));

            #endregion

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

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

            var stats = new TestFileStats
            {
                Size = Size,
                CreatedTimeUtc = DateTime.UtcNow,
                LastModifiedTimeUtc = DateTime.UtcNow,
            };

            FileSystem.StageFile(a_dest.Path, stats);
        }