public void VerifyPath_PathIsDirectory_ThrowsFileNotFoundException() { //Arrange var path = @"TestResources\UniversalFHTestResources"; var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act //Assert Assert.ThrowsException <FileNotFoundException>(() => ufh.VerifyPath(path)); }
public void VerifyPath_PathWithInvalidColon_ThrowsNotSupportedException() { //Arrange var path = "/Evil_D:rectory/Lang_File"; var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act //Assert Assert.ThrowsException <NotSupportedException>(() => ufh.VerifyPath(path)); }
public void VerifyPath_TooLongPath_ThrowsPathTooLangException() { //Arrange var path = FindShortestStringThatTriggersPathTooLongException(); var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act //Assert Assert.ThrowsException <PathTooLongException>(() => ufh.VerifyPath(path)); }
public void VerifyPath_WhiteSpacePath_ThrowsArgumentException() { //Arrange var path = " "; var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act //Assert Assert.ThrowsException <ArgumentException>(() => ufh.VerifyPath(path)); }
public void ReadAllTextWrapper_PathIsDirectory_ThrowsUnauthorizedAccessException() { //Arrange var path = @"TestResources\UniversalFHTestResources"; var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act //Assert Assert.ThrowsException <UnauthorizedAccessException>(() => ufh.ReadAllTextWrapper(path)); }
public void VerifyPath_NullPath_ThrowsArgumentNullException() { //Arrange string path = null; var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act //Assert Assert.ThrowsException <ArgumentNullException>(() => ufh.VerifyPath(path)); }
public void ReadAllTextWrapper_FileDoesNotExists_ThrowsFileNotFoundException() { //Arrange var nonexistentPath = GetNonExistentPath(); var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act //Assert Assert.ThrowsException <FileNotFoundException>(() => ufh.ReadAllTextWrapper(nonexistentPath)); }
public void VerifyPath_PathWithUnsupportedChars_ThrowsArgumentException() { //Arrange //Testing OS specific, because behaviour of ufh is also OS specific. var notSupported = Path.GetInvalidPathChars(); var magicNumber = Math.Min(3, notSupported.Length); var path = $"Evil_D{notSupported[magicNumber]}rectory/Lang_File"; var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act //Assert Assert.ThrowsException <ArgumentException>(() => ufh.VerifyPath(path)); }
public void ReadAllTextWrapper_FileExists_ContentIsRead() { //Arrange var path = TextFilePath; var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act var readText = ufh.ReadAllTextWrapper(path); //Assert Assert.AreEqual(readText, TextFileContent); }
public void CopyBackupWrapperTest() { //Arrange var path = TextFilePath; var nonexistentPath = GetNonExistentPath(); var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act ufh.CopyBackupWrapper(path, nonexistentPath); //Assert Assert.IsTrue(File.Exists(nonexistentPath)); Assert.AreEqual(TextFileContent, File.ReadAllText(nonexistentPath)); //Cleanup File.Delete(nonexistentPath); }
public void WriteAllTextWrapperTest() { //Arrange var expectedContent = TextFileContent; var nonexistentPath = GetNonExistentPath(); var ufh = new UniversalFileHandler(typeof(UniversalFileHandlerTests)); //Act ufh.WriteAllTextWrapper(expectedContent, nonexistentPath); //Assert Assert.IsTrue(File.Exists(nonexistentPath)); Assert.AreEqual(expectedContent, File.ReadAllText(nonexistentPath)); //Cleanup File.Delete(nonexistentPath); }
/// <summary> /// Creates the instance of the JsonFileProvider, which reads and persists all translations from Json-files. /// </summary> /// <param name="translationFilePath">The path under which the dictionary will be saved.</param> /// <exception cref="ArgumentNullException"> /// Thrown, if <paramref name="translationFilePath" /> is null. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// Thrown, if the permissions are missing that are needed to create the directory for /// <paramref name="translationFilePath" /> or <paramref name="translationFilePath" /> is write-only, /// read-only, a directory, hidden, the needed permissions for opening or writing are missing or /// the operation is not supported on the current platform. /// </exception> /// <exception cref="System.Security.SecurityException"> /// Thrown, if certain permissions are missing. (CLR level) /// </exception> /// <exception cref="FileNotFoundException"> /// Thrown, if <paramref name="translationFilePath" /> does not exist or cannot be found. /// For example because it is a direcory. /// </exception> /// <exception cref="IOException"> /// Thrown, if an unknown I/O-Error occurs. /// </exception> /// <exception cref="NotSupportedException"> /// Thrown, if <paramref name="translationFilePath" /> contains a colon anywhere other than as part of a /// volume identifier ("C:\"). /// </exception> /// <exception cref="PathTooLongException"> /// Thrown, if <paramref name="translationFilePath" /> is too long. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// Thrown, if the directory was not found. /// For example because it is on an unmapped device. /// </exception> public JsonFileProvider(string translationFilePath) { //set Status. Status = ProviderStatus.InitializationInProgress; //easy initializations. _logger = GlobalSettings.LibraryLoggerFactory.CreateLogger <JsonFileProvider>(); _logger.Log(LogLevel.Trace, "Initializing JsonFileProvider."); _fileHandler = new UniversalFileHandler(typeof(JsonFileProvider)); //null check. ExceptionLoggingUtils.ThrowIfNull(_logger, (object)translationFilePath, nameof(translationFilePath), "Unable to open null path.", "JsonFileProvider received null parameter in constructor."); //start proper initialization. _fileHandler.VerifyPath(translationFilePath); _path = translationFilePath; Initialize(); }