コード例 #1
0
        public void InitializationPermissions(FileAccess permissions, bool shouldThrow)
        {
            var store = new TestLocalObjectStore();
            var dir   = Path.Combine(TestStorageRoot, $"CSharp-TestAlgorithm-8");

            Directory.CreateDirectory(dir);

            //Determine filename for key "Jose" using Base64
            var filename = Convert.ToBase64String(Encoding.UTF8.GetBytes("Jose"));

            File.WriteAllText(Path.Combine(dir, filename), "Pepe");

            store.Initialize($"CSharp-TestAlgorithm-8", 0, 0, "", new Controls {
                StoragePermissions = permissions
            });

            if (shouldThrow)
            {
                Assert.Throws <InvalidOperationException>(() => store.ContainsKey("Jose"));
            }
            else
            {
                Assert.IsTrue(store.ContainsKey("Jose"));
            }

            Directory.Delete(dir, true);
        }
コード例 #2
0
        public void ReadBytesPermissions(FileAccess permissions, bool shouldThrow)
        {
            var store = new TestLocalObjectStore();

            store.Initialize($"CSharp-TestAlgorithm-{permissions}", 0, 0, "", new Controls {
                StoragePermissions = permissions
            });

            if (shouldThrow)
            {
                Assert.Throws <InvalidOperationException>(() => store.ReadBytes("Jose"));
            }
            else
            {
                Assert.Throws <KeyNotFoundException>(() => store.ReadBytes("Jose"));
            }
        }
コード例 #3
0
        public void PersistCalledSynchronously()
        {
            var store = new TestLocalObjectStore();

            store.Initialize("CSharp-TestAlgorithm2", 0, 0, "", new Controls
            {
                PersistenceIntervalSeconds = -1
            });

            store.SaveBytes("Pepe", new byte[] { 1 });
            Assert.AreEqual(1, store.ReadBytes("Pepe").Single());
            Assert.IsTrue(store.PersistDataCalled);

            store.PersistDataCalled = false;

            store.Delete("Pepe");
            Assert.IsTrue(store.PersistDataCalled);
            Assert.IsFalse(store.ContainsKey("Pepe"));

            store.DisposeSafely();
        }
コード例 #4
0
        public void InitializationPermissions(FileAccess permissions, bool shouldThrow)
        {
            var store = new TestLocalObjectStore();
            var dir   = Path.Combine(TestStorageRoot, $"CSharp-TestAlgorithm-8");

            Directory.CreateDirectory(dir);
            File.WriteAllText(Path.Combine(dir, "Jose"), "Pepe");
            store.Initialize($"CSharp-TestAlgorithm-8", 0, 0, "", new Controls {
                StoragePermissions = permissions
            });

            if (shouldThrow)
            {
                Assert.Throws <InvalidOperationException>(() => store.ContainsKey("Jose"));
            }
            else
            {
                Assert.IsTrue(store.ContainsKey("Jose"));
            }

            Directory.Delete(dir, true);
        }