ConfigurationProcessorGetAllTests.cs (6976B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ConfigurationProcessorGetAllTests.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.Management.Configuration.UnitTests.Tests 8 { 9 using System.Collections.Generic; 10 using System.IO; 11 using Microsoft.Management.Configuration.UnitTests.Fixtures; 12 using Microsoft.Management.Configuration.UnitTests.Helpers; 13 using Microsoft.VisualBasic; 14 using Windows.Foundation.Collections; 15 using Xunit; 16 using Xunit.Abstractions; 17 18 /// <summary> 19 /// Unit tests for getting details on processors. 20 /// </summary> 21 [Collection("UnitTestCollection")] 22 [InProc] 23 [OutOfProc] 24 public class ConfigurationProcessorGetAllTests : ConfigurationProcessorTestBase 25 { 26 /// <summary> 27 /// Initializes a new instance of the <see cref="ConfigurationProcessorGetAllTests"/> class. 28 /// </summary> 29 /// <param name="fixture">Unit test fixture.</param> 30 /// <param name="log">Log helper.</param> 31 public ConfigurationProcessorGetAllTests(UnitTestFixture fixture, ITestOutputHelper log) 32 : base(fixture, log) 33 { 34 } 35 36 /// <summary> 37 /// The unit settings processor returns an error HRESULT. 38 /// </summary> 39 [Fact] 40 public void GetAllSettings_ProcessorSettingsError() 41 { 42 ConfigurationUnit configurationUnit = this.ConfigurationUnit(); 43 44 TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); 45 factory.NullProcessor = new TestConfigurationSetProcessor(null); 46 var unitProcessor = factory.NullProcessor.CreateGetAllSettingsTestProcessor(configurationUnit); 47 unitProcessor.GetAllSettingsDelegate = () => throw new FileNotFoundException(); 48 49 ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); 50 51 GetAllConfigurationUnitSettingsResult result = processor.GetAllUnitSettings(configurationUnit); 52 53 Assert.NotNull(result); 54 Assert.Null(result.Settings); 55 Assert.NotNull(result.ResultInformation); 56 Assert.NotNull(result.ResultInformation.ResultCode); 57 Assert.IsType<FileNotFoundException>(result.ResultInformation.ResultCode); 58 } 59 60 /// <summary> 61 /// The unit settings processor returns an error in its result. 62 /// </summary> 63 [Fact] 64 public void GetAllSettings_ProcessorSettingsFailedResult() 65 { 66 ConfigurationUnit configurationUnit = this.ConfigurationUnit(); 67 68 TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); 69 factory.NullProcessor = new TestConfigurationSetProcessor(null); 70 var unitProcessor = factory.NullProcessor.CreateGetAllSettingsTestProcessor(configurationUnit); 71 72 GetAllSettingsResultInstance getAllSettingsResult = new GetAllSettingsResultInstance(configurationUnit); 73 getAllSettingsResult.InternalResult.ResultCode = new InvalidDataException(); 74 getAllSettingsResult.InternalResult.Description = "We fail because we must"; 75 unitProcessor.GetAllSettingsDelegate = () => getAllSettingsResult; 76 77 ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); 78 79 GetAllConfigurationUnitSettingsResult result = processor.GetAllUnitSettings(configurationUnit); 80 81 Assert.NotNull(result); 82 Assert.Null(result.Settings); 83 Assert.NotNull(result.ResultInformation); 84 Assert.Equal(getAllSettingsResult.ResultInformation.ResultCode.HResult, result.ResultInformation.ResultCode.HResult); 85 Assert.Equal(getAllSettingsResult.ResultInformation.Description, result.ResultInformation.Description); 86 } 87 88 /// <summary> 89 /// The unit settings processor returns good settings. 90 /// </summary> 91 [Fact] 92 public void GetAllSettings_ProcessorSettingsSuccess() 93 { 94 ConfigurationUnit configurationUnit = this.ConfigurationUnit(); 95 96 TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); 97 factory.NullProcessor = new TestConfigurationSetProcessor(null); 98 var unitProcessor = factory.NullProcessor.CreateGetAllSettingsTestProcessor(configurationUnit); 99 100 GetAllSettingsResultInstance getAllSettingsResult = new GetAllSettingsResultInstance(configurationUnit); 101 getAllSettingsResult.Settings = new List<ValueSet>() 102 { 103 new ValueSet 104 { 105 { "key", "value" }, 106 }, 107 }; 108 unitProcessor.GetAllSettingsDelegate = () => getAllSettingsResult; 109 110 ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); 111 112 GetAllConfigurationUnitSettingsResult result = processor.GetAllUnitSettings(configurationUnit); 113 114 Assert.NotNull(result); 115 Assert.NotNull(result.ResultInformation); 116 Assert.Null(result.ResultInformation.ResultCode); 117 Assert.Empty(result.ResultInformation.Description); 118 Assert.NotNull(result.Settings); 119 Assert.Equal(1, result.Settings.Count); 120 Assert.Contains("key", result.Settings[0]); 121 Assert.IsType<string>(result.Settings[0]["key"]); 122 Assert.Equal("value", (string)result.Settings[0]["key"]); 123 } 124 125 /// <summary> 126 /// The unit settings processor does not support GetAllSettings. 127 /// </summary> 128 [Fact] 129 public void GetAllSettings_UnsupportedByProcessor() 130 { 131 ConfigurationUnit configurationUnit = this.ConfigurationUnit(); 132 133 TestConfigurationProcessorFactory factory = new TestConfigurationProcessorFactory(); 134 factory.NullProcessor = new TestConfigurationSetProcessor(null); 135 var unitProcessor = factory.NullProcessor.CreateTestProcessor(configurationUnit); 136 137 ConfigurationProcessor processor = this.CreateConfigurationProcessorWithDiagnostics(factory); 138 139 GetAllConfigurationUnitSettingsResult result = processor.GetAllUnitSettings(configurationUnit); 140 141 Assert.NotNull(result); 142 Assert.NotNull(result.ResultInformation); 143 Assert.NotNull(result.ResultInformation.ResultCode); 144 Assert.Equal(Errors.WINGET_CONFIG_ERROR_NOT_SUPPORTED_BY_PROCESSOR, result.ResultInformation.ResultCode.HResult); 145 } 146 } 147 }