public void WriteAndReadFile_RoundtripData() { var io = new LocalFileIO("foo", "bar"); io.WriteFile(".", "test1.txt", GenerateTestBytes(), false).Wait(); var outFileBytes = io.GetFile(".", "test1.txt").Result; Assert.AreEqual("hello tests!", Encoding.UTF8.GetString(outFileBytes)); }
public async void Should_GetByteArray_When_FileIsFound() { // arrange var io = new LocalFileIO("", ""); // act var result = await io.GetFile("/", "test.txt"); // assert Assert.Equal(2, result.Length); }
public async void Should_GetException_When_FileIsNotFound() { // arrange var io = new LocalFileIO("", ""); // act try { var result = await io.GetFile("/", "file.txt"); Assert.Equal(0, result.Length); } catch (FileNotFoundException e) { Assert.Equal(null, null); } }
static async Task <MessageResponse> GetFileMessage(Message message, object userContext) { //For test purpose only //message.Properties.Add("sourcePath", @"C:/Users"); //message.Properties.Add("sourceFilename", @"Test.txt"); //********************* logReceivedMessage(message); #region Checking required properties if (!validateStringParams(message, "sourcePath", "sourceFilename")) { return(MessageResponse.Abandoned); } #endregion // Process code here try { byte[] content = await localFileIO.GetFile(message.Properties["sourcePath"], message.Properties["sourceFilename"]); var moduleClient = userContext as ModuleClient; if (moduleClient == null) { throw new InvalidOperationException("UserContext doesn't exist. Not able to write in output."); } else { await moduleClient.SendEventAsync("GetFileOutput", new Message(content)); } } catch (Exception ex) { Console.WriteLine($"Error getting local file: {ex.Message}"); } Console.WriteLine("Done!"); return(MessageResponse.Completed); }