winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

TestConfigurationSetProcessor.cs (6238B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="TestConfigurationSetProcessor.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.Management.Configuration.UnitTests.Helpers
      8 {
      9     using System;
     10     using System.Collections.Generic;
     11 
     12     /// <summary>
     13     /// A test implementation of IConfigurationSetProcessor.
     14     /// </summary>
     15     internal partial class TestConfigurationSetProcessor : IConfigurationSetProcessor
     16     {
     17         /// <summary>
     18         /// Initializes a new instance of the <see cref="TestConfigurationSetProcessor"/> class.
     19         /// </summary>
     20         /// <param name="set">The set that this processor is for.</param>
     21         internal TestConfigurationSetProcessor(ConfigurationSet? set)
     22         {
     23             this.Set = set;
     24         }
     25 
     26         /// <summary>
     27         /// Gets or sets the processors to be used by this factory.
     28         /// </summary>
     29         internal Dictionary<ConfigurationUnit, TestConfigurationUnitProcessor> Processors { get; set; } =
     30             new Dictionary<ConfigurationUnit, TestConfigurationUnitProcessor>();
     31 
     32         /// <summary>
     33         /// Gets or sets the details to be used by this factory.
     34         /// </summary>
     35         internal Dictionary<ConfigurationUnit, TestConfigurationUnitProcessorDetails> Details { get; set; } =
     36             new Dictionary<ConfigurationUnit, TestConfigurationUnitProcessorDetails>();
     37 
     38         /// <summary>
     39         /// Gets or sets the exceptions to be used by this factory.
     40         /// </summary>
     41         internal Dictionary<ConfigurationUnit, Exception> Exceptions { get; set; } =
     42             new Dictionary<ConfigurationUnit, Exception>();
     43 
     44         /// <summary>
     45         /// Gets or sets a value indicating whether the default unit processors for groups will enable group processing.
     46         /// </summary>
     47         internal bool EnableDefaultGroupProcessorCreation { get; set; } = false;
     48 
     49         /// <summary>
     50         /// Gets the ConfigurationSet that this processor targets.
     51         /// </summary>
     52         protected ConfigurationSet? Set { get; private set; }
     53 
     54         /// <summary>
     55         /// Creates a new unit processor for the given unit.
     56         /// </summary>
     57         /// <param name="unit">The unit.</param>
     58         /// <returns>The configuration unit processor.</returns>
     59         public IConfigurationUnitProcessor CreateUnitProcessor(ConfigurationUnit unit)
     60         {
     61             if (this.Exceptions.ContainsKey(unit))
     62             {
     63                 throw this.Exceptions[unit];
     64             }
     65 
     66             if (!this.Processors.ContainsKey(unit))
     67             {
     68                 if (this.EnableDefaultGroupProcessorCreation && unit.IsGroup)
     69                 {
     70                     this.Processors.Add(unit, new TestConfigurationUnitGroupProcessor(unit));
     71                 }
     72                 else
     73                 {
     74                     this.Processors.Add(unit, new TestConfigurationUnitProcessor(unit));
     75                 }
     76             }
     77 
     78             return this.Processors[unit];
     79         }
     80 
     81         /// <summary>
     82         /// Gets the unit processor details for the given unit.
     83         /// </summary>
     84         /// <param name="unit">The unit.</param>
     85         /// <param name="detailFlags">The detail flags.</param>
     86         /// <returns>The details requested.</returns>
     87         public IConfigurationUnitProcessorDetails GetUnitProcessorDetails(ConfigurationUnit unit, ConfigurationUnitDetailFlags detailFlags)
     88         {
     89             if (this.Exceptions.ContainsKey(unit))
     90             {
     91                 throw this.Exceptions[unit];
     92             }
     93 
     94             if (!this.Details.ContainsKey(unit))
     95             {
     96                 this.Details.Add(unit, new TestConfigurationUnitProcessorDetails(unit, detailFlags));
     97             }
     98 
     99             return this.Details[unit];
    100         }
    101 
    102         /// <summary>
    103         /// Creates a new test processor for the given unit.
    104         /// </summary>
    105         /// <param name="unit">The unit.</param>
    106         /// <returns>The configuration unit processor.</returns>
    107         internal TestConfigurationUnitProcessor CreateTestProcessor(ConfigurationUnit unit)
    108         {
    109             this.Processors[unit] = new TestConfigurationUnitProcessor(unit);
    110             return this.Processors[unit];
    111         }
    112 
    113         /// <summary>
    114         /// Creates a new test group processor for the given unit.
    115         /// </summary>
    116         /// <param name="unit">The unit.</param>
    117         /// <returns>A new TestConfigurationUnitGroupProcessor for the unit.</returns>
    118         internal TestConfigurationUnitGroupProcessor CreateTestGroupProcessor(ConfigurationUnit unit)
    119         {
    120             TestConfigurationUnitGroupProcessor result = new (unit);
    121             this.Processors[unit] = result;
    122             return result;
    123         }
    124 
    125         /// <summary>
    126         /// Creates a new test processor that supports GetAllSettings for the given unit.
    127         /// </summary>
    128         /// <param name="unit">The unit.</param>
    129         /// <returns>The configuration unit processor.</returns>
    130         internal TestGetAllSettingsConfigurationUnitProcessor CreateGetAllSettingsTestProcessor(ConfigurationUnit unit)
    131         {
    132             var processor = new TestGetAllSettingsConfigurationUnitProcessor(unit);
    133             this.Processors[unit] = processor;
    134             return processor;
    135         }
    136 
    137         /// <summary>
    138         /// Creates a new unit processor details for the given unit.
    139         /// </summary>
    140         /// <param name="unit">The unit.</param>
    141         /// <param name="detailFlags">The detail flags.</param>
    142         /// <returns>The details requested.</returns>
    143         internal TestConfigurationUnitProcessorDetails CreateUnitDetails(ConfigurationUnit unit, ConfigurationUnitDetailFlags detailFlags)
    144         {
    145             this.Details[unit] = new TestConfigurationUnitProcessorDetails(unit, detailFlags);
    146             return this.Details[unit];
    147         }
    148     }
    149 }