public void Delete_NullFileName_ReturnNoFileNameException() { var file = new TextFile() { Filename = null, Path = "just path" }; var mockPathProvider = new Mock <IPathProvider>(); mockPathProvider.Setup(f => f.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns(It.IsAny <string>()); file.PathProvider = mockPathProvider.Object; Action action = () => file.Delete(file.Filename, file.Path); action.Should().Throw <NoFileNameException>().WithMessage("DELETE: FileName is missing"); }
public void Delete_FileDoesNotExist_ReturnFileExistException() { var file = new TextFile() { Filename = "test.txt", Path = "just path" }; var mockPathProvider = new Mock <IPathProvider>(); var mockFileProvider = new Mock <IFileProvider>(); mockPathProvider.Setup(f => f.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns(It.IsAny <string>()); mockFileProvider.Setup(f => f.Exist(It.IsAny <string>())).Returns(false); file.PathProvider = mockPathProvider.Object; file.FileProvider = mockFileProvider.Object; Action action = () => file.Delete(file.Filename, file.Path); action.Should().Throw <FileExistException>(); }
public void Delete_FileNameAndPathIsCorrect_ReturnTrue() { var file = new TextFile() { Filename = "test.txt", Path = "just path" }; var mockPathProvider = new Mock <IPathProvider>(); var mockFileProvider = new Mock <IFileProvider>(); mockPathProvider.Setup(f => f.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns(It.IsAny <string>()); mockFileProvider.Setup(f => f.Exist(It.IsAny <string>())).Returns(true); mockFileProvider.Setup(f => f.Delete(It.IsAny <string>())).Returns(true); file.PathProvider = mockPathProvider.Object; file.FileProvider = mockFileProvider.Object; var result = file.Delete(file.Filename, file.Path); result.Should().BeTrue(); }
public void Delete_FileIsNotExist_ReturnFileExistException(string filename, string path) { // Act var file = new TextFile(); var mockPathProvider = new Mock <IPathProvider>(); var mockFileProvider = new Mock <IFileProvider>(); mockPathProvider.Setup(p => p.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns(Guid.NewGuid().ToString()); mockFileProvider.Setup(f => f.Exist(It.IsAny <string>())).Returns(false); file.FileProvider = mockFileProvider.Object; file.PathProvider = mockPathProvider.Object; // Arrange Action action = () => file.Delete(filename, path); // Assert action.Should().Throw <FileExistException>().Where(e => e.ParamName.Equals($"The file \"{filename}\" does not exist in the \"{path}\" directory")); }
public void Delete_NULLPath_ReturnFileExistException() { var file = new TextFile() { Filename = "test.txt", Path = null }; var mockFile = new Mock <IFileProvider>(); var mockPath = new Mock <IPathProvider>(); var mockUserDir = new Mock <IDirectory>(); mockUserDir.Setup(f => f.Get()).Returns(It.IsAny <string>()); mockPath.Setup(f => f.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns(It.IsAny <string>()); mockFile.Setup(f => f.Exist(It.IsAny <string>())).Returns(false); file.UserDirectory = mockUserDir.Object; file.PathProvider = mockPath.Object; file.FileProvider = mockFile.Object; Action action = () => file.Delete(file.Filename, file.Path); action.Should().Throw <FileExistException>(); }
public void Delete_NULLPath_ReturnTrue() { var file = new TextFile() { Filename = "test.txt", Path = null }; var mockUserDirectory = new Mock <IDirectory>(); var mockPathProvider = new Mock <IPathProvider>(); var mockFileProvider = new Mock <IFileProvider>(); mockUserDirectory.Setup(f => f.Get()).Returns("This is User Directory"); mockPathProvider.Setup(f => f.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns(It.IsAny <string>()); mockFileProvider.Setup(f => f.Exist(It.IsAny <string>())).Returns(true); mockFileProvider.Setup(f => f.Delete(It.IsAny <string>())).Returns(true); file.FileProvider = mockFileProvider.Object; file.PathProvider = mockPathProvider.Object; file.UserDirectory = mockUserDirectory.Object; bool result = file.Delete(file.Filename, file.Path); result.Should().BeTrue(); }
public async Task <bool> Save() { errorProvider.Clear(); if (string.IsNullOrWhiteSpace(textBoxFileName.Text)) { errorProvider.SetError(textBoxFileName, "Filename is required"); return(false); } string fileName = System.IO.Path.GetFileNameWithoutExtension(textBoxFileName.Text.Trim()); bool isNewName = !fileName.Equals(originalFileName, StringComparison.InvariantCultureIgnoreCase); if (!TextHasChanged && !isNewName) { return(true); } //textbox returns lines as /n .. weird should ne /r/n //so hack work around string[] lines = richTextBox.Lines; string text = "-"; if (lines?.Length > 0) { StringBuilder sb = new StringBuilder(); int lineCount = lines.Length; for (int i = 0; i < lineCount; i++) { if (i + 1 < lineCount) { sb.AppendLine(lines[i]); } else { sb.Append(lines[i]); } } text = sb.ToString(); } byte[] data = FileConverter.TexttoRTF(text); if (TextFile != null) { await BrickExplorer.UploadFile(data, Directory.Path, $"{fileName}.rtf"); if (isNewName) { await TextFile.Delete(); } } else { await BrickExplorer.UploadFile(data, Directory.Path, $"{fileName}.rtf"); } TextHasChanged = false; RefreshDirectory = true; return(true); }