/// <summary> /// Create a unique named zero-byte length temporary file on disk and returns it's path. /// </summary> public static string GetTempFileName() { var rndName = GetRandomFileName(); var index = rndName.IndexOf('.'); return(JFile.CreateTempFile(rndName.JavaSubstring(0, index), rndName.JavaSubstring(index)).GetAbsolutePath()); }
public void testWriteAllText1() { var path = JFile.CreateTempFile("dot42.TestFile-WriteAllText1", "txt"); File.WriteAllText(path.AbsolutePath, "Hello world"); AssertTrue(path.Exists()); path.Delete(); AssertFalse(path.Exists()); }
public void test1() { var path = JFile.CreateTempFile("dot42.TestXLoad-1", "txt"); File.WriteAllText(path, "<root></root>"); var doc = XDocument.Load(path); path.Delete(); AssertNotNull(doc); AssertNotNull(doc.Root); }
public void testWriteAllText2() { const string Data = "Hello worldAllText2"; var path = JFile.CreateTempFile("dot42.TestFile-WriteAllText2", "txt"); File.WriteAllText(path.AbsolutePath, Data); AssertTrue(path.Exists()); var content = File.ReadAllText(path.AbsolutePath); path.Delete(); AssertEquals(content, Data); }
public void test2() { var path = JFile.CreateTempFile("dot42.TestXLoad-2", "txt"); File.WriteAllText(path, "<root></root>"); using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var doc = XDocument.Load(stream); AssertNotNull(doc); AssertNotNull(doc.Root); } path.Delete(); }
public void test3() { var path = JFile.CreateTempFile("dot42.TestXLoad-3", "txt"); File.WriteAllText(path, "<?xml version=\"1.0\" encoding=\"utf-8\"?><Version xmlns=\"urn:Dot42:TodoApi:1.0\">v1_0</Version>"); using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var doc = XDocument.Load(stream); AssertNotNull("doc should not be null", doc); AssertNotNull("doc.Root should not be null", doc.Root); AssertTrue("doc.Root.Name.LocalName != 'Version'", doc.Root.Name.LocalName == "Version"); AssertTrue("doc.Root.Value != 'v1_0' but:" + doc.Root.Value, doc.Root.Value == "v1_0"); } path.Delete(); }
public void testWriteAllBytes1() { var data = new byte[] { 1, 2, 3, 4 }; var path = JFile.CreateTempFile("dot42.TestFile-WriteAllBytes1", "txt"); File.WriteAllBytes(path.AbsolutePath, data); AssertTrue(path.Exists()); var readData = File.ReadAllBytes(path.AbsolutePath); path.Delete(); AssertFalse(path.Exists()); AssertEquals(data.Length, readData.Length); for (var i = 0; i < data.Length; i++) { AssertEquals(data[i], readData[i]); } }