Exemplo n.º 1
0
        /// <summary>
        /// Gets the empty file in random directory
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public static NFile New(string filePath)
        {
            Contract.Requires<ArgumentNullException>(!String.IsNullOrEmpty(filePath), "Initial path is null or empty");
            Contract.Ensures(Contract.Result<NFile>() != null);

            //Get corrected format path
            var path = Helper.GetFormatedPath(filePath);

            String folderPath = null;
            //Check for Folder in path
            if (path.Contains(Path.DirectorySeparatorChar))
            {
                //File + Dir
                folderPath = Path.GetDirectoryName(path);
                path = Path.GetFileName(path);
            }

            var dir = DirectoryFactory.New(folderPath);
            var file = new EmptyFile(dir, path);
            file.Create();
            //Subscribe file deleting
            file.FileDeleted += (sender, args) => dir.Dispose();

            return file;
        }
Exemplo n.º 2
0
        public void CreateFakeFile_Path_EnsureExist()
        {
            const string fileName = @"1.jpg";

            var directory = new NDirectory();

            using (var file = new EmptyFile(directory, fileName))
            {
                file.Create();
                Assert.True(File.Exists(file.FullPath));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add empty file to directory
        /// </summary>
        /// <param name="parentDirectory">The directory.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static NFile Add(NDirectory parentDirectory, string fileName)
        {
            Contract.Requires<ArgumentNullException>(parentDirectory != null);
            Contract.Requires<ArgumentNullException>(fileName != null);
            Contract.Ensures(Contract.Result<NFile>() != null);

            Helper.CheckForSeparatorChar(fileName);

            var file = new EmptyFile(parentDirectory, fileName);

            CreateFile(parentDirectory, file);

            return file;
        }