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 JSONSerialiser() { string id = String.Empty; string glyphKey = String.Empty; string glyphColour = String.Empty; string name = String.Empty; string description = String.Empty; string website = String.Empty; DateTime createdAt = DateTime.MinValue; DateTime lastUpdatedAt = DateTime.MinValue; DateTime passwordLastModifiedAt = DateTime.MinValue; string username = String.Empty; string password = String.Empty; string[] tags = null; string notes = String.Empty; AuditLogEntry[] auditLogEntries = null; Credential credential = CreateRandomCredential(_rng, out id, out glyphKey, out glyphColour, out name, out description, out website, out createdAt, out lastUpdatedAt, out passwordLastModifiedAt, out username, out password, out tags, out notes, out auditLogEntries); ISerialiser serialiser = FormatVersions.GetLatestSerialiser(typeof(Credential)); JObject json = (JObject)serialiser.Write(credential, String.Empty); Credential credentialReloaded = (Credential)serialiser.Read(json, String.Empty); Assert.IsTrue(credential.CompareTo(credentialReloaded) == 0); }