public void TestSimpleReadWrite() { string stringData = "Hello, world! This is a string.\n"; var binData = BinString.FromBytes("09F911029D74E35BD84156C5635688C0"); var dd = DataDir.Create(DataDirType.Temporary); dd.WriteAllText("test.txt", stringData, System.Text.Encoding.ASCII); Assert.AreEqual(stringData, dd.ReadAllText("test.txt", Encoding.ASCII)); dd.WriteAllBytes("test.bin", binData); Assert.AreEqual(binData, dd.ReadAllBytes("test.bin")); }
public void SystemRandomSourceTest() { using (var sr = new SystemRandomRandomnessSource()) { for (int i = 0; i < 32; i++) { Assert.AreEqual(i, sr.GetRandomBytes(i).Length); } } using (var seeded = new SystemRandomRandomnessSource(new Random(42))) { Assert.AreEqual(BinString.FromBytes("3e17ba96ae04cd3b99869e56f0adbf3a"), seeded.GetRandomBytes(16)); } }
public void TestGetPath() { var data = BinString.FromBytes("C0FFEEC0FFEEC0FFEEC0FFEE"); var dd = DataDir.Create(DataDirType.Temporary); string filename = DateTime.Now.Ticks.ToString("x") + ".tmp"; string fullPath = dd.GetFullPath(filename); Assert.IsFalse(File.Exists(fullPath)); dd.WriteAllBytes(filename, data); Assert.AreEqual(data, (BinString)File.ReadAllBytes(fullPath)); data = BinString.FromTextString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Encoding.ASCII); File.WriteAllBytes(fullPath, data); Assert.AreEqual(data, dd.ReadAllBytes(filename)); Assert.IsTrue(File.Exists(fullPath)); dd.DeleteFile(filename); Assert.IsFalse(File.Exists(fullPath)); }