public void CopyNotificationTest04()
        {
            const string tmpPath = @"C:\tmp\";
            const string aPath   = @"C:\tmp\a\";
            const string bPath   = @"C:\tmp\b\";
            const string afPath  = @"C:\tmp\a\test.01";
            const string bfPath  = @"C:\tmp\b\test.01";

            if (!Directory.Exists(tmpPath))
            {
                Directory.CreateDirectory(tmpPath);
            }
            if (!Directory.Exists(aPath))
            {
                Directory.CreateDirectory(aPath);
            }
            if (!Directory.Exists(bPath))
            {
                Directory.CreateDirectory(bPath);
            }
            if (File.Exists(afPath))
            {
                File.Delete(afPath);
            }
            if (File.Exists(bfPath))
            {
                File.Delete(bfPath);
            }

            var content = C.Random <byte[]>(0x8FFF, 0xFFFF);

            File.WriteAllBytes(afPath, content);

            var vm = GetInstance();
            var a  = new LocalFileSystemContentViewModel();

            a.LoadDataAsync(LoadCommand.Load, new LoadDataAsyncParameters(new FileListPaneSettings(aPath, "Name", ListSortDirection.Ascending, ColumnMode.Title, FileListPaneViewMode.List)));
            var b = new LocalFileSystemContentViewModel();

            b.LoadDataAsync(LoadCommand.Load, new LoadDataAsyncParameters(new FileListPaneSettings(bPath, "Name", ListSortDirection.Ascending, ColumnMode.Title, FileListPaneViewMode.List)));

            var selection = a.Items.First(i => i.Name != "..");

            a.CurrentRow = selection;
            a.ToggleSelectionCommand.Execute(ToggleSelectionMode.Insert);
            Assert.AreEqual(1, a.SelectedItems.Count(), "One item should be selected");

            //first we copy the first file of the file
            var sourcePath = selection.Model.GetRelativePath(a.CurrentFolder.Path);
            var targetPath = b.GetTargetPath(sourcePath);
            var targetSize = selection.Size / 2;

            using (var targetStream = b.GetStream(targetPath, FileMode.CreateNew, FileAccess.Write, 0))
            {
                a.CopyStream(selection.Model, targetStream, 0, targetSize);
            }
            b.Refresh(false);

            Assert.IsTrue(b.Items.Any(i => i.Name == selection.Name), string.Format("The file {0} should have been copied", selection.Name));
            Assert.IsTrue(b.Items.Any(i => i.Name == selection.Name && i.Size == targetSize), string.Format("The file {0} should be {1} bytes", selection.Name, targetSize));

            var errorOccured = 0;

            ConsoleWriter.WriteErrorDialogResult = () => { errorOccured++; return(new TransferErrorDialogResult(ErrorResolutionBehavior.Retry, CopyActionScope.Current, CopyAction.Resume)); };

            var finish = new List <TransferFinishedEventArgs>();

            EventAggregator.GetEvent <TransferFinishedEvent>().Subscribe(finish.Add);
            //then we try to do the proper way and see if it appends it
            vm.Copy(a, b, null);

            Assert.AreEqual(1, errorOccured, "A file exists error should have been occurred exactly one time.");
            Assert.AreEqual(1, finish.Count, "TransferFinishedEvent should be triggered exactly one time.");
            Assert.IsTrue(b.Items.Any(i => i.Name == selection.Name && i.Size == selection.Size), string.Format("The file {0} should be {1} bytes", selection.Name, selection.Size));

            var bBytes = new byte[content.Length];

            using (var bStream = b.GetStream(targetPath, FileMode.Open, FileAccess.Read, 0))
            {
                bStream.Read(bBytes, 0, content.Length);
            }

            for (var i = 0; i < content.Length; i++)
            {
                Assert.AreEqual(content[i], bBytes[i], "The files content doesn't much at position: " + i);
            }

            Directory.Delete(tmpPath, true);
        }
        public void CopyNotificationTest04()
        {
            const string tmpPath = @"C:\tmp\";
            const string aPath = @"C:\tmp\a\";
            const string bPath = @"C:\tmp\b\";
            const string afPath = @"C:\tmp\a\test.01";
            const string bfPath = @"C:\tmp\b\test.01";
            if (!Directory.Exists(tmpPath)) Directory.CreateDirectory(tmpPath);
            if (!Directory.Exists(aPath)) Directory.CreateDirectory(aPath);
            if (!Directory.Exists(bPath)) Directory.CreateDirectory(bPath);
            if (File.Exists(afPath)) File.Delete(afPath);
            if (File.Exists(bfPath)) File.Delete(bfPath);

            var content = C.Random<byte[]>(0x8FFF, 0xFFFF);
            File.WriteAllBytes(afPath, content);

            var vm = GetInstance();
            var a = new LocalFileSystemContentViewModel();
            a.LoadDataAsync(LoadCommand.Load, new LoadDataAsyncParameters(new FileListPaneSettings(aPath, "Name", ListSortDirection.Ascending, ColumnMode.Title)));
            var b = new LocalFileSystemContentViewModel();
            b.LoadDataAsync(LoadCommand.Load, new LoadDataAsyncParameters(new FileListPaneSettings(bPath, "Name", ListSortDirection.Ascending, ColumnMode.Title)));

            var selection = a.Items.First(i => i.Name != "..");
            a.CurrentRow = selection;
            a.ToggleSelectionCommand.Execute(ToggleSelectionMode.Insert);
            Assert.AreEqual(1, a.SelectedItems.Count(), "One item should be selected");

            //first we copy the first file of the file
            var sourcePath = selection.Model.GetRelativePath(a.CurrentFolder.Path);
            var targetPath = b.GetTargetPath(sourcePath);
            var targetSize = selection.Size / 2;

            using (var targetStream = b.GetStream(targetPath, FileMode.CreateNew, FileAccess.Write, 0))
            {
                a.CopyStream(selection.Model, targetStream, 0, targetSize);
            }
            b.Refresh();

            Assert.IsTrue(b.Items.Any(i => i.Name == selection.Name), string.Format("The file {0} should have been copied", selection.Name));
            Assert.IsTrue(b.Items.Any(i => i.Name == selection.Name && i.Size == targetSize), string.Format("The file {0} should be {1} bytes", selection.Name, targetSize));

            var errorOccured = 0;
            ConsoleWriter.WriteErrorDialogResult = () => { errorOccured++; return new TransferErrorDialogResult(ErrorResolutionBehavior.Retry, CopyActionScope.Current, CopyAction.Resume); };

            var finish = new List<TransferFinishedEventArgs>();
            EventAggregator.GetEvent<TransferFinishedEvent>().Subscribe(finish.Add);
            //then we try to do the proper way and see if it appends it
            vm.Copy(a, b, null);

            Assert.AreEqual(1, errorOccured, "A file exists error should have been occurred exactly one time.");
            Assert.AreEqual(1, finish.Count, "TransferFinishedEvent should be triggered exactly one time.");
            Assert.IsTrue(b.Items.Any(i => i.Name == selection.Name && i.Size == selection.Size), string.Format("The file {0} should be {1} bytes", selection.Name, selection.Size));

            var bBytes = new byte[content.Length];
            using (var bStream = b.GetStream(targetPath, FileMode.Open, FileAccess.Read, 0))
            {
                bStream.Read(bBytes, 0, content.Length);
            }

            for (var i = 0; i < content.Length; i++)
            {
                Assert.AreEqual(content[i], bBytes[i], "The files content doesn't much at position: " + i);
            }

            Directory.Delete(tmpPath, true);
        }
Пример #3
0
 public OpenIsoPayload(LocalFileSystemContentViewModel parentPane, string path)
 {
     ParentPane = parentPane;
     Path       = path;
 }