示例#1
0
        private void DoTest(StoreProvider provider)
        {
            // save bytes as new file
            provider.Save("test.txt", File.ReadAllBytes(TestFilePath));

            // save stream as new file
            using (var fs = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read)) {
                provider.Save("folder/folder2/test2.txt", fs);
            }

            // file exists
            Assert.IsTrue(provider.Exists("test.txt"));
            Assert.IsTrue(provider.Exists("folder/folder2/test2.txt"));
            Assert.IsFalse(provider.Exists("non-existing-file.txt"));

            byte[] bytes = null;
            Stream s     = null;

            try {
                // load bytes
                Assert.IsTrue(provider.Load("test.txt", out bytes));

                // load stream
                Assert.IsTrue(provider.Load("folder/folder2/test2.txt", out s));

                // compare
                for (var i = 0; i < bytes.Length; i++)
                {
                    Assert.AreEqual(s.ReadByte(), bytes[i]);
                }
                Assert.AreEqual(s.Position, s.Length);
            }
            finally {
                s.Dispose();
            }

            // overwrite file and read it to detect whether the changes were really saved
            var newData = new byte[] { 1, 2, 3, 4, 5 };

            provider.Save("test.txt", newData);
            byte[] newData2;
            provider.Load("test.txt", out newData2);
            for (int i = 0; i < newData.Length; i++)
            {
                Assert.AreEqual(newData[i], newData2[i]);
            }
            Assert.AreEqual(newData.Length, newData2.Length);

            // delete files
            provider.Delete("test.txt");
            provider.Delete("folder/folder2/test2.txt");

            // file exists
            Assert.IsFalse(provider.Exists("test.txt"));
            Assert.IsFalse(provider.Exists("folder/folder2/test2.txt"));
        }
示例#2
0
        private void DoTest(StoreProvider provider)
        {
            // save bytes as new file
            provider.Save("test.txt", File.ReadAllBytes(TestFilePath));

            // save stream as new file
            using (var fs = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read)) {
                provider.Save("folder/folder2/test2.txt", fs);
            }

            // file exists
            Assert.IsTrue(provider.Exists("test.txt"));
            Assert.IsTrue(provider.Exists("folder/folder2/test2.txt"));
            Assert.IsFalse(provider.Exists("non-existing-file.txt"));

            byte[] bytes = null;
            Stream s = null;
            try {
                // load bytes
                Assert.IsTrue(provider.Load("test.txt", out bytes));

                // load stream
                Assert.IsTrue(provider.Load("folder/folder2/test2.txt", out s));

                // compare
                for (var i = 0; i < bytes.Length; i++) {
                    Assert.AreEqual(s.ReadByte(), bytes[i]);
                }
                Assert.AreEqual(s.Position, s.Length);
            }
            finally {
                s.Dispose();
            }

            // overwrite file and read it to detect whether the changes were really saved
            var newData = new byte[] { 1, 2, 3, 4, 5 };
            provider.Save("test.txt", newData);
            byte[] newData2;
            provider.Load("test.txt", out newData2);
            for (int i = 0; i < newData.Length; i++)
            {
                Assert.AreEqual(newData[i], newData2[i]);
            }
            Assert.AreEqual(newData.Length, newData2.Length);

            // delete files
            provider.Delete("test.txt");
            provider.Delete("folder/folder2/test2.txt");

            // file exists
            Assert.IsFalse(provider.Exists("test.txt"));
            Assert.IsFalse(provider.Exists("folder/folder2/test2.txt"));
        }
示例#3
0
 public bool Exists(string key)
 {
     return(_retryStrategy.ExecuteFuncWithRetry(
                () => StoreProvider.Exists(key)));
 }