Пример #1
0
        public async Task EnumerateTest()
        {
            // Arrange
            var storage = new EmbeddedStorage();
            var data    = new string[3] {
                "Tomato", "Banana", "Plum"
            };
            var dir = Path.Combine(REF, "_test");

            // Act
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            foreach (var item in data)
            {
                File.WriteAllText(Path.Combine(dir, item), item);
            }

            var actual = await storage.Enumerate(dir);

            var tomato = File.ReadAllText(Path.Combine(dir, data[0]));

            // Assert
            Assert.NotEmpty(actual);
            Assert.Equal(data[0], tomato);
        }
Пример #2
0
 public void InitializeEmptyFile_ExpectsNoFiles()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using(var es = new EmbeddedStorage(path))
     {
         var files = new List<FileInfo>(es.EnumerateFiles());
         Assert.AreEqual(0, files.Count);
     }
     if (File.Exists(path)) File.Delete(path);
 }
Пример #3
0
        public void NewRefTest()
        {
            // Arrange
            var storage  = new EmbeddedStorage();
            var fileName = "fileName";

            // Act
            var actual = storage.NewRef(REF, fileName);

            // Assert
            Assert.Equal(Path.Combine(REF, fileName), actual);
        }
Пример #4
0
        public async Task DeleteTest()
        {
            // Arrange
            var storage  = new EmbeddedStorage();
            var fileName = Path.Combine(REF, "delete");

            // Act
            File.WriteAllText(fileName, "delete Test");
            await storage.Delete(fileName);

            // Assert
            Assert.False(File.Exists(fileName));
        }
Пример #5
0
        public async Task ReadTest()
        {
            // Arrange
            var storage  = new EmbeddedStorage();
            var fileName = Path.Combine(REF, "read");
            var expected = "document content";

            // Act
            File.WriteAllText(fileName, expected);
            var actual = await storage.Read(fileName);

            // Assert
            Assert.Equal(expected, actual);
        }
 public void InitializeEmptyFile_GetLength()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var es = new EmbeddedStorage(path))
     {
         var ess = new EmbeddedStorageStream("Q", es);
         var length = ess.Length;
         Assert.AreEqual(0, length);
         var files = es.Files();
         Assert.AreEqual(1, files.Count);
         Assert.AreEqual("Q", files[0].Name);
     }
     if (File.Exists(path)) File.Delete(path);
 }
Пример #7
0
 public void InitializeEmptyFile_WriteOneFile()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var es = new EmbeddedStorage(path))
     {
         var fi = es.CreateFile("Q");
         var data = new byte[255];
         for (byte i = 0; i < 255; i++) data[i] = i;
         es.Write(fi, data, 0, 255);
         var content = es.Read(fi);
         Assert.AreEqual(data.Length, content.Length);
         for(byte i=0;i<255;i++) Assert.AreEqual(data[i], content[i]);
     }
     if (File.Exists(path)) File.Delete(path);
 }
Пример #8
0
 public void InitializeEmptyFile_AddOneFile()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var es = new EmbeddedStorage(path))
     {
         var fi = es.CreateFile("Q");
         Assert.AreEqual("Q", fi.Name);
         Assert.AreEqual((uint)0, fi.Length);
         var files = new List<FileInfo>(es.EnumerateFiles());
         Assert.AreEqual(1, files.Count);
         Assert.AreEqual(fi.Name, files[0].Name);
         Assert.AreEqual(fi.Length, files[0].Length);
     }
     if (File.Exists(path)) File.Delete(path);
 }
Пример #9
0
        public async Task EnumerateEmptyTest()
        {
            // Arrange
            var storage = new EmbeddedStorage();
            var folder  = Path.Combine(REF, "_empty");

            // Act
            if (Directory.Exists(folder))
            {
                Directory.Delete(folder, true);
            }

            var actual = await storage.Enumerate(folder);

            // Assert
            Assert.True(Directory.Exists(folder));
            Assert.Empty(actual);
        }
Пример #10
0
 public void WriteOneFile_RemoveOneFile()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var es = new EmbeddedStorage(path))
     {
         var files = es.Files();
         Assert.AreEqual(0, files.Count);
         var fi = es.CreateFile("Q");
         var data = new byte[255];
         for (byte i = 0; i < 255; i++) data[i] = i;
         es.Write(fi, data, 0, 255);
         files = es.Files();
         Assert.AreEqual(1, files.Count);
         es.Remove(fi);
         files = es.Files();
         Assert.AreEqual(0, files.Count);
     }
     if (File.Exists(path)) File.Delete(path);
 }
Пример #11
0
 public void ExistingFile_ContainsOneFile()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var es = new EmbeddedStorage(path))
     {
         var fi = es.CreateFile("Q");
     }
     using (var es = new EmbeddedStorage(path))
     {
         var files = es.Files();
         Assert.AreEqual(1, files.Count);
         Assert.AreEqual("Q", files[0].Name);
     }
     if (File.Exists(path)) File.Delete(path);
 }
Пример #12
0
 public void ExistingFile_SearchByFilename_ReadBigFile()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     const int count = 8192;
     var data = new byte[count];
     for (var i = 0; i < count; i++) data[i] = (byte)(i % 0xff);
     using (var es = new EmbeddedStorage(path))
     {
         var fi = es.CreateFile("Q");
         es.Write(fi, data, 0, count);
     }
     using (var es = new EmbeddedStorage(path))
     {
         var content = es.Read("Q");
         Assert.AreEqual(count, content.Length);
         for (var i = 0; i < count; i++) Assert.AreEqual(data[i], content[i]);
     }
     if (File.Exists(path)) File.Delete(path);
 }