public void InstallUnitDescriptorFactoryDispatchesToNupkgDescriptorFactoryAndCreatesDescriptorTest() { EngineEnvironmentSettings.SettingsLoader.Components.Register(typeof(NupkgInstallUnitDescriptorFactory)); string serializedDescriptor = @" { ""3A06B18C-224E-46E3-95EB-8E411DB61B0B"": { ""FactoryId"": """ + NupkgInstallUnitDescriptorFactory.FactoryId.ToString() + @""", ""MountPointId"": ""D1ADBDAF-0382-4EEA-A43C-8356A8BEFAA9"", ""Identifier"": ""TestPackage"", ""Details"": { ""Version"": ""1.2.3"", ""Author"": ""Microsoft"", } } }"; JObject descriptorJObject = JObject.Parse(serializedDescriptor); JProperty descriptorProperty = descriptorJObject.Properties().First(); Assert.True(InstallUnitDescriptorFactory.TryParse(EngineEnvironmentSettings, descriptorProperty, out IInstallUnitDescriptor parsedDescriptor)); NupkgInstallUnitDescriptor nupkgDescriptor = parsedDescriptor as NupkgInstallUnitDescriptor; Assert.NotNull(nupkgDescriptor); Assert.Equal(NupkgInstallUnitDescriptorFactory.FactoryId, nupkgDescriptor.FactoryId); Assert.Equal("TestPackage", nupkgDescriptor.Identifier); Assert.Equal("D1ADBDAF-0382-4EEA-A43C-8356A8BEFAA9", nupkgDescriptor.MountPointId.ToString(), ignoreCase: true); Assert.Equal("1.2.3", nupkgDescriptor.Version); Assert.Equal("1.2.3", nupkgDescriptor.Details["Version"]); }
public void InstallUnitDescriptorFactoryDispatchesToNupkgDescriptorFactoryAndCreatesDescriptorTest() { EngineEnvironmentSettings.SettingsLoader.Components.Register(typeof(NupkgInstallUnitDescriptorFactory)); string serializedDescriptor = @" { ""FactoryId"": """ + NupkgInstallUnitDescriptorFactory.FactoryId.ToString() + @""", ""Details"": { ""MountPointId"": ""D1ADBDAF-0382-4EEA-A43C-8356A8BEFAA9"", ""PackageName"": ""TestPackage"", ""Version"": ""1.2.3"" } }"; JObject descriptorJObject = JObject.Parse(serializedDescriptor); Assert.True(InstallUnitDescriptorFactory.TryParse(EngineEnvironmentSettings, descriptorJObject, out IInstallUnitDescriptor parsedDescriptor)); NupkgInstallUnitDescriptor nupkgDescriptor = parsedDescriptor as NupkgInstallUnitDescriptor; Assert.NotNull(nupkgDescriptor); Assert.Equal(NupkgInstallUnitDescriptorFactory.FactoryId, nupkgDescriptor.FactoryId); Assert.Equal("TestPackage", nupkgDescriptor.Identifier); Assert.Equal("TestPackage", nupkgDescriptor.PackageName); Assert.Equal("D1ADBDAF-0382-4EEA-A43C-8356A8BEFAA9", nupkgDescriptor.MountPointId.ToString(), ignoreCase: true); Assert.Equal("1.2.3", nupkgDescriptor.Version); Assert.Equal("D1ADBDAF-0382-4EEA-A43C-8356A8BEFAA9", nupkgDescriptor.Details["MountPointId"], ignoreCase: true); Assert.Equal("TestPackage", nupkgDescriptor.Details["PackageName"]); Assert.Equal("1.2.3", nupkgDescriptor.Details["Version"]); }
public void InstallUnitDescriptorFactoryFailsGracefullyOnMissingDetailsTest() { string serializedDescriptor = @" { ""FactoryId"": ""25AB3648-DC67-4A95-A658-5EEE8ADC2695"", }"; JObject descriptorJObject = JObject.Parse(serializedDescriptor); Assert.False(InstallUnitDescriptorFactory.TryParse(EngineEnvironmentSettings, descriptorJObject, out IInstallUnitDescriptor descriptor)); }
public void InstallUnitDescriptorFactoryFailsGracefullyOnMissingFactoryIdTest() { string serializedDescriptor = @" { ""Details"": { } }"; JObject descriptorJObject = JObject.Parse(serializedDescriptor); Assert.False(InstallUnitDescriptorFactory.TryParse(EngineEnvironmentSettings, descriptorJObject, out IInstallUnitDescriptor descriptor)); }
public void InstallUnitDescriptorFactoryFailsGracefullyOnUnknownDescriptorFactoryIdTest() { // guid was randomly generated, doesn't match any descriptor factory string serializedDescriptor = @" { ""FactoryId"": ""25AB3648-DC67-4A95-A658-5EEE8ADC2695"", ""Details"": { } }"; JObject descriptorJObject = JObject.Parse(serializedDescriptor); Assert.False(InstallUnitDescriptorFactory.TryParse(EngineEnvironmentSettings, descriptorJObject, out IInstallUnitDescriptor descriptor)); }
public static InstallUnitDescriptorCache FromJObject(IEngineEnvironmentSettings environmentSettings, JObject cacheObj) { List <IInstallUnitDescriptor> allDescriptors = new List <IInstallUnitDescriptor>(); foreach (JProperty descriptorProperty in cacheObj.PropertiesOf(nameof(Descriptors))) { if (InstallUnitDescriptorFactory.TryParse(environmentSettings, descriptorProperty, out IInstallUnitDescriptor parsedDescriptor)) { allDescriptors.Add(parsedDescriptor); } } return(new InstallUnitDescriptorCache(environmentSettings, allDescriptors)); }
public void InstallUnitDescriptorFactoryFailsGracefullyOnStructuredDetailsDataTest() { string serializedDescriptor = @" { ""FactoryId"": ""25AB3648-DC67-4A95-A658-5EEE8ADC2695"", ""Details"": { ""OuterKey"" : { ""InnerKey"": ""InnerValue"" } } }"; JObject descriptorJObject = JObject.Parse(serializedDescriptor); Assert.False(InstallUnitDescriptorFactory.TryParse(EngineEnvironmentSettings, descriptorJObject, out IInstallUnitDescriptor descriptor)); }
public void InstallUnitDescriptorFactoryFailsGracefullyOnUnknownDescriptorFactoryIdTest() { // guid was randomly generated, doesn't match any descriptor factory string serializedDescriptor = @" { ""2DB9FBE1-5DFA-4A56-A9B7-8291236D7580"": { ""FactoryId"": ""25AB3648-DC67-4A95-A658-5EEE8ADC2695"", ""Details"": { } } }"; JObject descriptorObject = JObject.Parse(serializedDescriptor); JProperty descriptorProperty = descriptorObject.Properties().First(); Assert.False(InstallUnitDescriptorFactory.TryParse(EngineEnvironmentSettings, descriptorProperty, out IInstallUnitDescriptor descriptor)); }
public static InstallUnitDescriptorCache FromJObject(IEngineEnvironmentSettings environmentSettings, JObject cacheObj) { List <IInstallUnitDescriptor> allDescriptors = new List <IInstallUnitDescriptor>(); foreach (JProperty prop in cacheObj.PropertiesOf(nameof(Descriptors))) { JObject descriptorObj = prop.Value as JObject; if (InstallUnitDescriptorFactory.TryParse(environmentSettings, descriptorObj, out IInstallUnitDescriptor parsedDescriptor)) { allDescriptors.Add(parsedDescriptor); } } Dictionary <Guid, string> installedItems = new Dictionary <Guid, string>(); foreach (KeyValuePair <string, string> item in cacheObj.ToStringDictionary(propertyName: nameof(InstalledItems))) { installedItems[Guid.Parse(item.Key)] = item.Value; } return(new InstallUnitDescriptorCache(environmentSettings, allDescriptors, installedItems)); }
public void InstallUnitDescriptorFactoryTryParseFailsGracefullyOnNullDescriptorObjectTest() { Assert.False(InstallUnitDescriptorFactory.TryParse(EngineEnvironmentSettings, null, out IInstallUnitDescriptor descriptor)); }