public void Can_Undo_RenameAndMove_Operation()
        {
            // arrange
            var file = Path.GetTempFileName();
            var operation = new RenameAndMoveOperation(
                new FileInfo(file),
                new DirectoryInfo(Path.GetTempPath()),
                DateTimeGenerator.AnyDateBetween(
                    DateTimeGenerator.FirstDayOfThisMonth(),
                    DateTimeGenerator.LastDayOfThisMonth()),
               Guid.NewGuid().ToString());
            var newFilename = Path.Combine(
                operation.TargetDirectory.FullName, operation.NewFilename);
            operation.Do();

            // assume
            File.Exists(file).ShouldBe(false);
            File.Exists(newFilename).ShouldBe(true);

            // act
            operation.Undo();

            // assert
            File.Exists(file).ShouldBe(true);
            File.Exists(newFilename).ShouldBe(false);
        }
Пример #2
0
        public void RenameAndMoveDocument()
        {
            if (!DocumentDate.HasValue)
                return;

            try
            {
                //var extension = Path.GetExtension(SelectedSourceFile.Name);
                //var filename = $"{DocumentDate:yyyy.MM.dd} - {DocumentTitle}{extension}";
                //var fullFilename = Path.Combine(SelectedTargetDirectory.FullName, filename);
                //var newFile = new FileInfo(fullFilename);
                var operation = new RenameAndMoveOperation(
                    SelectedSourceFile,
                    SelectedTargetDirectory,
                    DocumentDate.Value,
                    DocumentTitle);
                OperationsStack.DoOperation(operation);

                AfterAction();
            }
            catch (Exception ex)
            {
                Log.Error("Error renameing / moving document.", ex);
                MessageBox.Show("Error:" + ex.Message);
            }
        }