Esempio n. 1
0
        public async Task RestoreInvalidInputTestAsync()
        {
            ProtoBufDataBackupRestore backupRestore = new ProtoBufDataBackupRestore();
            await Assert.ThrowsAsync <ArgumentException>(() => backupRestore.RestoreAsync <string>(null, "abc"));

            await Assert.ThrowsAsync <ArgumentException>(() => backupRestore.RestoreAsync <string>(" ", "abc"));

            await Assert.ThrowsAsync <ArgumentException>(() => backupRestore.RestoreAsync <string>("abc", null));

            await Assert.ThrowsAsync <ArgumentException>(() => backupRestore.RestoreAsync <string>("abc", " "));

            await Assert.ThrowsAsync <IOException>(() => backupRestore.BackupAsync("abc", "abc", "C:\\" + Guid.NewGuid().ToString()));
        }
Esempio n. 2
0
        public async Task BackupRestoreSuccessTest()
        {
            ProtoBufDataBackupRestore backupRestore = new ProtoBufDataBackupRestore();

            Item         item1 = new Item("key1".ToBytes(), "val1".ToBytes());
            Item         item2 = new Item("key2".ToBytes(), "val2".ToBytes());
            IList <Item> items = new List <Item> {
                item1, item2
            };

            string name = "test";
            await backupRestore.BackupAsync(name, this.backupFolder, items);

            // Attempt a restore to validate that that backup succeeds.
            IList <Item> restoredItems = await backupRestore.RestoreAsync <IList <Item> >(name, this.backupFolder);

            Assert.Equal(items.Count, restoredItems.Count);
            Assert.All(items, x => restoredItems.Any(y => x.Key.SequenceEqual(y.Key) && x.Value.SequenceEqual(y.Value)));
        }
Esempio n. 3
0
        public async Task RestoreInvalidBackupDataTestAsync()
        {
            ProtoBufDataBackupRestore backupRestore = new ProtoBufDataBackupRestore();

            Item         item1 = new Item("key1".ToBytes(), "val1".ToBytes());
            Item         item2 = new Item("key2".ToBytes(), "val2".ToBytes());
            IList <Item> items = new List <Item> {
                item1, item2
            };

            string name = "test";
            await backupRestore.BackupAsync(name, this.backupFolder, items);

            // Corrupt the backup file.
            using (FileStream file = File.OpenWrite(Path.Combine(this.backupFolder, $"{name}.bin")))
            {
                file.Write(new byte[] { 1, 2 }, 1, 1);
            }

            // Attempting a restore should now fail.
            Exception ex = await Assert.ThrowsAsync <IOException>(() => backupRestore.RestoreAsync <IList <Item> >(name, this.backupFolder));

            Assert.True(ex.InnerException is ProtoException);
        }