コード例 #1
0
        public void ProcessRequest_ShouldProperlyMoveFile()
        {
            // Arrange
            var configuration = new Mock <IConfiguration>();

            configuration.Setup(conf => conf["output-directory"]).Returns("C:\\MyFolder");

            var dialog = new Mock <IProtocolDialogServer>();

            dialog.Setup(dia => dia.ReadValue(4, It.IsAny <Func <byte[], int> >())).Returns(5);
            dialog.Setup(dia => dia.ReadValue(5, It.IsAny <Func <byte[], string> >())).Returns("b.txt");
            dialog.Setup(dia => dia.DialogData).Returns(new ProtocolDialogData
            {
                FileAction       = FileAction.Rename,
                Version          = 1,
                RelativeFilePath = "a.txt"
            });

            var fileSystem = new Mock <IFileSystem>();

            fileSystem.Setup(fs => fs.Path).Returns(new FileSystem().Path);
            var file = new Mock <FileBase>();

            fileSystem.Setup(fs => fs.File).Returns(file.Object);

            // Act
            IFileReceiverStrategy rename = new RenameReceiverStrategy(dialog.Object, configuration.Object, fileSystem.Object);

            rename.ProcessRequest();

            // Assert
            file.Verify(f => f.Move("C:\\MyFolder\\a.txt", "C:\\MyFolder\\b.txt"), Times.Once);
        }
コード例 #2
0
        public void ProcessRequest_DestinationFolderEXists_ShouldRemoveFolderBeforeMoving()
        {
            // Arrange
            var configuration = new Mock <IConfiguration>();

            configuration.Setup(conf => conf["output-directory"]).Returns("C:\\MyFolder");

            var dialog = MockDialogForFolderRenaming();

            var(fileSystem, directory) = MockFileSystemForFolderRenaming();

            // Act
            IFileReceiverStrategy rename = new RenameReceiverStrategy(dialog.Object, configuration.Object, fileSystem.Object);

            rename.ProcessRequest();

            // Assert
            directory.Verify(d => d.Delete("C:\\MyFolder\\b"), Times.Once);
        }