示例#1
0
        public void SequentialUpgradeTest()
        {
            Vault testVault = VaultTests.CreateRandomVault(_rng);
            IEnumerable <FormatVersionAttribute> vaultSerialisers = FormatVersions.Instance.VersionSerialisers.Keys.Where(fva => fva.ObjectType == typeof(Vault)).OrderBy(fva => double.Parse(fva.Version));

            FormatVersionAttribute[] filteredOrderedSerialisers = vaultSerialisers.ToArray();
            object curSerialised = null;
            Vault  curVault      = null;
            string lastVersion   = String.Empty;

            for (int curVersion = 0; curVersion < filteredOrderedSerialisers.Length; curVersion++)
            {
                if (curSerialised != null)
                {
                    FormatVersionAttribute prevSerialiserAttrib = filteredOrderedSerialisers[curVersion - 1];
                    ISerialiser            prevSerialiser       = FormatVersions.Instance.GetSerialiser(prevSerialiserAttrib.Version, typeof(Vault));
                    curVault = (Vault)prevSerialiser.Read(curSerialised, String.Empty);
                }
                else
                {
                    curVault = testVault;
                }
                FormatVersionAttribute nextSerialiserAttrib = filteredOrderedSerialisers[curVersion];
                lastVersion = nextSerialiserAttrib.Version;
                ISerialiser nextSerialiser = FormatVersions.Instance.GetSerialiser(nextSerialiserAttrib.Version, typeof(Vault));
                curSerialised = nextSerialiser.Write(curVault, String.Empty);
            }
            Assert.IsTrue(lastVersion == Framework.Serialisers.JSON.Common.LATEST_VAULT_VERSION);
            ISerialiser latestSerialiser = FormatVersions.GetLatestSerialiser(typeof(Vault));

            curVault = (Vault)latestSerialiser.Read(curSerialised, String.Empty);
            Assert.IsTrue(curVault.CompareTo(testVault) == 0);
        }
        public void AESEncryptedVaultSerialiserTest()
        {
            String masterPassphrase = "This is my passphrase!";
            Vault  vault            = VaultTests.CreateRandomVault(_rnd);
            AESEncryptedVaultSerialiser serialiser = new AESEncryptedVaultSerialiser();

            Byte[] encrypted      = (Byte[])serialiser.Write(vault, masterPassphrase);
            Vault  decryptedVault = (Vault)serialiser.Read(encrypted, masterPassphrase);

            Assert.IsTrue(vault.CompareTo(decryptedVault) == 0);
        }