Beispiel #1
0
        public override void Copy(string sourceFileName, string destFileName, bool overwrite)
        {
            ValidateParameter(sourceFileName, "sourceFileName");
            ValidateParameter(destFileName, "destFileName");

            var directoryNameOfDestination = mockPath.GetDirectoryName(destFileName);

            if (!mockFileDataAccessor.Directory.Exists(directoryNameOfDestination))
            {
                throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, "Could not find a part of the path '{0}'.", destFileName));
            }

            var fileExists = mockFileDataAccessor.FileExists(destFileName);

            if (fileExists)
            {
                if (!overwrite)
                {
                    throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file {0} already exists.", destFileName));
                }

                mockFileDataAccessor.RemoveFile(destFileName);
            }

            var sourceFile = mockFileDataAccessor.GetFile(sourceFileName);

            mockFileDataAccessor.AddFile(destFileName, sourceFile);
        }
Beispiel #2
0
        public override void Copy(string sourceFileName, string destFileName, bool overwrite)
        {
            if (sourceFileName == null)
            {
                throw new ArgumentNullException(nameof(sourceFileName), StringResources.Manager.GetString("FILENAME_CANNOT_BE_NULL"));
            }

            if (destFileName == null)
            {
                throw new ArgumentNullException(nameof(destFileName), StringResources.Manager.GetString("FILENAME_CANNOT_BE_NULL"));
            }

            mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(sourceFileName, "sourceFileName");
            mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(destFileName, "destFileName");

            if (!Exists(sourceFileName))
            {
                throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.Manager.GetString("COULD_NOT_FIND_FILE_EXCEPTION"), sourceFileName));
            }

            var directoryNameOfDestination = mockPath.GetDirectoryName(destFileName);

            if (!mockFileDataAccessor.Directory.Exists(directoryNameOfDestination))
            {
                throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.Manager.GetString("COULD_NOT_FIND_PART_OF_PATH_EXCEPTION"), destFileName));
            }

            var fileExists = mockFileDataAccessor.FileExists(destFileName);

            if (fileExists)
            {
                if (!overwrite)
                {
                    throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file {0} already exists.", destFileName));
                }

                mockFileDataAccessor.RemoveFile(destFileName);
            }

            var sourceFileData = mockFileDataAccessor.GetFile(sourceFileName);

            mockFileDataAccessor.AddFile(destFileName, new MockFileData(sourceFileData));
        }
        public override void Copy(string sourceFileName, string destFileName, bool overwrite)
        {
            //This is the order that checks are executed in MSCORLIB.
            if (sourceFileName == null)
            {
                throw new ArgumentNullException("sourceFileName", Properties.Resources.FILENAME_CANNOT_BE_NULL);
            }

            if (destFileName == null)
            {
                throw new ArgumentNullException("destFileName", Properties.Resources.FILENAME_CANNOT_BE_NULL);
            }
            mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(sourceFileName, "sourceFileName");
            mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(destFileName, "destFileName");
            if (!Exists(sourceFileName))
            {
                throw new FileNotFoundException();
            }

            var directoryNameOfDestination = mockPath.GetDirectoryName(destFileName);

            if (!mockFileDataAccessor.Directory.Exists(directoryNameOfDestination))
            {
                throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.COULD_NOT_FIND_PART_OF_PATH_EXCEPTION, destFileName));
            }

            var fileExists = mockFileDataAccessor.FileExists(destFileName);

            if (fileExists)
            {
                if (!overwrite)
                {
                    throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file {0} already exists.", destFileName));
                }

                mockFileDataAccessor.RemoveFile(destFileName);
            }

            var sourceFile = mockFileDataAccessor.GetFile(sourceFileName);

            mockFileDataAccessor.AddFile(destFileName, sourceFile);
        }
        public override void Copy(string sourceFileName, string destFileName, bool overwrite)
        {
            if (sourceFileName == null)
            {
                throw new ArgumentNullException(nameof(sourceFileName), Properties.Resources.FILENAME_CANNOT_BE_NULL);
            }

            if (destFileName == null)
            {
                throw new ArgumentNullException(nameof(destFileName), Properties.Resources.FILENAME_CANNOT_BE_NULL);
            }

            _mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(sourceFileName, nameof(sourceFileName));
            _mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(destFileName, nameof(destFileName));

            string directoryNameOfDestination = _mockPath.GetDirectoryName(destFileName);

            if (!_mockFileDataAccessor.Directory.Exists(directoryNameOfDestination))
            {
                throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.COULD_NOT_FIND_PART_OF_PATH_EXCEPTION, destFileName));
            }

            bool fileExists = _mockFileDataAccessor.FileExists(destFileName);

            if (fileExists)
            {
                if (!overwrite)
                {
                    throw new IOException($"The file {destFileName} already exists.");
                }

                _mockFileDataAccessor.RemoveFile(destFileName);
            }

            MockFileData sourceFile = _mockFileDataAccessor.GetFile(sourceFileName);

            _mockFileDataAccessor.AddFile(destFileName, sourceFile);
        }