예제 #1
0
        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"));
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
        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));
        }