Ejemplo n.º 1
0
        public void OpenedHandle()
        {
            using (var fs = new FileStream(state.ExistingFiles[0].FullName, FileMode.Append))
            {
                var ctSource = new CancellationTokenSource();
                var cpJob    = new FileTransferJob(
                    new FileTransferArguments(state.ExistingFiles[0], state.NonExistingFiles[0], TransferSettings.None),
                    state.OnProgressDebugPrint
                    ,
                    ctSource.Token);

                try
                {
                    cpJob.Run();
                }
                catch (FileTransferException e)
                {
                    state.ExceptionThrown = true;
                    Assert.IsTrue(e.InnerException is IOException);
                }

                Assert.IsTrue(state.ExceptionThrown);

                state.NonExistingFiles[0].Refresh();
                Assert.IsFalse(state.NonExistingFiles[0].Exists);
            }
        }
Ejemplo n.º 2
0
        public void DestinationFileExists()
        {
            File.WriteAllText(state.NonExistingFiles[0].FullName, "Oh this suddenly exists..");

            var ctSource = new CancellationTokenSource();
            var cpJob    = new FileTransferJob(
                new FileTransferArguments(state.ExistingFiles[0], state.NonExistingFiles[0], TransferSettings.None),
                state.OnProgressDebugPrint
                ,
                ctSource.Token);

            try
            {
                cpJob.Run();
            }
            catch (FileTransferException e)
            {
                state.ExceptionThrown = true;
                Assert.IsTrue(e.InnerException is IOException);
            }

            Assert.IsTrue(state.ExceptionThrown);
            Assert.IsTrue(state.NonExistingFiles[0].Exists);
            Assert.AreNotEqual(File.ReadAllText(state.ExistingFiles[0].FullName), File.ReadAllText(state.NonExistingFiles[0].FullName));
        }
Ejemplo n.º 3
0
        public void SourceDoesNotExist()
        {
            var cts     = new CancellationTokenSource();
            var moveJob = new FileTransferJob(
                new FileTransferArguments(state.NonExistingFiles[0], state.NonExistingFiles[1], TransferSettings.DeleteOriginal),
                state.OnProgressDebugPrint
                ,
                cts.Token);

            try
            {
                moveJob.Run();
            }
            catch (FileTransferException e)
            {
                state.ExceptionThrown = true;
                Assert.IsTrue(e.InnerException is FileNotFoundException);
            }


            state.NonExistingFiles[1].Refresh();

            Assert.IsFalse(state.NonExistingFiles[1].Exists);
            Assert.IsTrue(state.ExceptionThrown);
        }
Ejemplo n.º 4
0
        public void DestinationWithoutRights()
        {
            var cts     = new CancellationTokenSource();
            var moveJob = new FileTransferJob(
                new FileTransferArguments(state.ExistingFiles[0], state.NonExistentFileWithoutRights, TransferSettings.DeleteOriginal),
                state.OnProgressDebugPrint
                ,
                cts.Token);

            try
            {
                moveJob.Run();
            }
            catch (FileTransferException e)
            {
                state.ExceptionThrown = true;
                Assert.IsTrue(e.InnerException is UnauthorizedAccessException);
            }

            state.ExistingFiles[0].Refresh();
            state.NonExistentFileWithoutRights.Refresh();

            Assert.IsTrue(state.ExceptionThrown);
            Assert.IsTrue(state.ExistingFiles[0].Exists);
        }
Ejemplo n.º 5
0
        public void DestinationAlreadyExists()
        {
            var cts     = new CancellationTokenSource();
            var moveJob = new FileTransferJob(
                new FileTransferArguments(state.ExistingFiles[0], state.ExistingFiles[1], TransferSettings.DeleteOriginal),
                state.OnProgressDebugPrint
                ,
                cts.Token);

            try
            {
                moveJob.Run();
            }
            catch (FileTransferException e)
            {
                state.ExceptionThrown = true;
                Assert.IsTrue(e.InnerException is IOException);
            }

            state.ExistingFiles[0].Refresh();
            state.ExistingFiles[1].Refresh();

            Assert.IsTrue(state.ExceptionThrown);
            Assert.IsTrue(state.ExistingFiles[0].Exists);
            Assert.IsTrue(state.ExistingFiles[1].Exists);
            Assert.AreNotEqual(File.ReadAllText(state.ExistingFiles[0].FullName), File.ReadAllText(state.ExistingFiles[1].FullName));
        }
Ejemplo n.º 6
0
        public void RunSynchronously()
        {
            var ctSource = new CancellationTokenSource();
            var cpJob    = new FileTransferJob(
                new FileTransferArguments(state.ExistingFiles[0], state.NonExistingFiles[0], TransferSettings.None),
                state.OnProgressDebugPrint
                ,
                ctSource.Token);

            cpJob.Run();

            state.NonExistingFiles[0].Refresh();
            Assert.IsTrue(state.NonExistingFiles[0].Exists);
            Assert.AreEqual(File.ReadAllText(state.ExistingFiles[0].FullName), File.ReadAllText(state.NonExistingFiles[0].FullName));
        }
Ejemplo n.º 7
0
        public void RunSynchornously()
        {
            string existingFileContent = File.ReadAllText(state.ExistingFiles[0].FullName);

            var cts     = new CancellationTokenSource();
            var moveJob = new FileTransferJob(
                new FileTransferArguments(state.ExistingFiles[0], state.NonExistingFiles[0], TransferSettings.DeleteOriginal),
                state.OnProgressDebugPrint
                ,
                cts.Token);

            moveJob.Run();

            state.NonExistingFiles[0].Refresh();
            state.ExistingFiles[0].Refresh();

            Assert.IsTrue(state.NonExistingFiles[0].Exists);
            Assert.IsFalse(state.ExistingFiles[0].Exists);

            Assert.AreEqual(existingFileContent, File.ReadAllText(state.NonExistingFiles[0].FullName));
        }