public void CanDeserializeAndSerializeInstallManifest() { List <InstallActionInfo> entries = new List <InstallActionInfo>() { this.CreateInstallActionInfo(), this.CreateInstallActionInfo() }; InstallManifest installManifest = new InstallManifest(); installManifest.AddPlatformInstallManifest(InstallManifest.WindowsPlatformKey, entries); JsonSerializer serializer = new JsonSerializer(); using (MemoryStream ms = new MemoryStream()) using (StreamWriter streamWriter = new StreamWriter(ms)) using (JsonWriter jsWriter = new JsonTextWriter(streamWriter)) { string output = JsonConvert.SerializeObject(installManifest); serializer.Serialize(jsWriter, installManifest); jsWriter.Flush(); ms.Seek(0, SeekOrigin.Begin); StreamReader streamReader = new StreamReader(ms); InstallManifest deserializedInstallManifest = InstallManifest.FromJson(streamReader); this.VerifyInstallManifestsAreEqual(installManifest, deserializedInstallManifest); } }
private void VerifyInstallManifestsAreEqual(InstallManifest expected, InstallManifest actual) { actual.PlatformInstallManifests.Count.ShouldEqual(expected.PlatformInstallManifests.Count, $"The number of platforms ({actual.PlatformInstallManifests.Count}) do not match the expected number of platforms ({expected.PlatformInstallManifests.Count})."); foreach (KeyValuePair <string, InstallManifestPlatform> kvp in expected.PlatformInstallManifests) { this.VerifyPlatformManifestsAreEqual(kvp.Value, actual.PlatformInstallManifests[kvp.Key]); } }
public void CanReadExpectedJsonString() { string installManifestJsonString = @" { ""Version"" : ""1"", ""PlatformInstallManifests"" : { ""Windows"": { ""InstallActions"": [ { ""Name"" : ""Git"", ""Version"" : ""2.19.0.1.34"", ""InstallerRelativePath"" : ""Installers\\Windows\\G4W\\Git-2.19.0.gvfs.1.34.gc7fb556-64-bit.exe"", ""Args"" : ""/VERYSILENT /CLOSEAPPLICATIONS"" }, { ""Name"" : ""PostGitInstall script"", ""InstallerRelativePath"" : ""Installers\\Windows\\GSD\\postinstall.ps1"" }, ] } } } "; InstallManifest installManifest = InstallManifest.FromJsonString(installManifestJsonString); installManifest.ShouldNotBeNull(); InstallManifestPlatform platformInstallManifest = installManifest.PlatformInstallManifests[InstallManifest.WindowsPlatformKey]; platformInstallManifest.ShouldNotBeNull(); platformInstallManifest.InstallActions.Count.ShouldEqual(2); this.VerifyInstallActionInfo( platformInstallManifest.InstallActions[0], "Git", "2.19.0.1.34", "/VERYSILENT /CLOSEAPPLICATIONS", "Installers\\Windows\\G4W\\Git-2.19.0.gvfs.1.34.gc7fb556-64-bit.exe"); this.VerifyInstallActionInfo( platformInstallManifest.InstallActions[1], "PostGitInstall script", null, null, "Installers\\Windows\\GSD\\postinstall.ps1"); }