public IEnumerator Write() { Assert.IsFalse(FileManager.Exists(RelativeFilePath)); // Given invalid paths and files data. byte[] fileData = new UTF8Encoding(true).GetBytes(FileContent); // When trying to read, write or check if the file exits using invalid arguments. defaultFileSystem.Write(RelativeFilePath, fileData); // Then assert that a proper exception is thrown. Assert.IsTrue(defaultFileSystem.Exists(RelativeFilePath)); yield break; }
/// <summary> /// Saves given <paramref name="fileData"/> in provided <paramref name="filePath"/>. /// </summary> /// <remarks><paramref name="filePath"/> must be relative to <see cref="PersistentDataPath"/>.</remarks> /// <returns>Returns true if <paramref name="fileData"/> could be saved successfully; otherwise, false.</returns> public static bool Write(string filePath, byte[] fileData) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("Invalid 'filePath'"); } if (Path.IsPathRooted(filePath)) { throw new ArgumentException($"Method only accepts relative paths.\n'filePath': {filePath}"); } if (fileData == null || fileData.Length == 0) { throw new ArgumentException("Invalid 'fileData'"); } return(platformFileSystem.Write(filePath, fileData)); }