Пример #1
0
        public IFile CopyTo(string destFileName, bool overwrite)
        {
            EnsureExists();

            if (FileSystem == null)
            {
                throw new InvalidOperationException("FileMock FileSystem property should be set before copying is possible.");
            }

            var file = FileSystem.GetFile(destFileName);

            if (!file.Exists)
            {
                file = new FileMock(Path.GetFileName(destFileName), _data.ToArray())
                {
                    FullName = destFileName
                };
                FileSystem.Add(file);
            }
            else if (overwrite)
            {
                file.WriteAllBytes(this.ReadAllBytes());
            }
            else
            {
                throw new IOException(string.Format("Cannot copy '{1}' to '{0}': file already exists.", destFileName, this.FullName));
            }

            return(file);
        }
Пример #2
0
 public void Add([NotNull] FileMock file)
 {
     file.FileSystem = this;
     _items.Add(file);
 }
 public void Add([NotNull] FileMock file)
 {
     file.Directory = this;
     _items.Add(file);
 }