/// <summary> /// Cmdlet begin process. Write to logs, setup Http Tracing and initialize profile /// </summary> protected override void BeginProcessing() { FlushInitializationWarnings(); SessionState = base.SessionState; var profile = _dataCollectionProfile; //TODO: Inject from CI server lock (lockObject) { if (_metricHelper == null) { _metricHelper = new MetricHelper(profile); _metricHelper.AddTelemetryClient(new TelemetryClient { InstrumentationKey = "7df6ff70-8353-4672-80d6-568517fed090" }); } } InitializeQosEvent(); LogCmdletStartInvocationInfo(); InitDebuggingFilter(); SetupDebuggingTraces(); SetupHttpClientPipeline(); base.BeginProcessing(); //Now see if the cmdlet has any Breaking change attributes on it and process them if it does //This will print any breaking change attribute messages that are applied to the cmdlet BreakingChangeAttributeHelper.ProcessCustomAttributesAtRuntime(this.GetType(), this.MyInvocation, WriteWarning); PreviewAttributeHelper.ProcessCustomAttributesAtRuntime(this.GetType(), this.MyInvocation, WriteDebug); }
/// <summary> /// Cmdlet begin process. Write to logs, setup Http Tracing and initialize profile /// </summary> protected override void BeginProcessing() { FlushInitializationWarnings(); SessionState = base.SessionState; var profile = _dataCollectionProfile; //TODO: Inject from CI server if (_metricHelper == null) { lock (lockObject) { if (_metricHelper == null) { _metricHelper = new MetricHelper(profile); _metricHelper.AddDefaultTelemetryClient(); } } } // Fetch module name and version which will be used by telemetry and useragent if (this.MyInvocation != null && this.MyInvocation.MyCommand != null) { this.ModuleName = this.MyInvocation.MyCommand.ModuleName; if (this.MyInvocation.MyCommand.Version != null) { this.ModuleVersion = this.MyInvocation.MyCommand.Version.ToString(); } } else { this.ModuleName = this.GetType().Assembly.GetName().Name; this.ModuleVersion = this.GetType().Assembly.GetName().Version.ToString(); } InitializeQosEvent(); LogCmdletStartInvocationInfo(); InitDebuggingFilter(); SetupDebuggingTraces(); SetupHttpClientPipeline(); base.BeginProcessing(); //Now see if the cmdlet has any Breaking change attributes on it and process them if it does //This will print any breaking change attribute messages that are applied to the cmdlet BreakingChangeAttributeHelper.ProcessCustomAttributesAtRuntime(this.GetType(), this.MyInvocation, WriteWarning); PreviewAttributeHelper.ProcessCustomAttributesAtRuntime(this.GetType(), this.MyInvocation, WriteDebug); }
public void TestForCmdletOutputTypeDropped() { List <GenericBreakingChangeAttribute> attribs = new List <GenericBreakingChangeAttribute>(BreakingChangeAttributeHelper.GetAllBreakingChangeAttributesInType(typeof(AzureRMTestCmdletWithCmdletWithOutputTypeDropped), null)); Assert.Equal(1, attribs.Count); Assert.False(attribs[0].ChangeInEfectByDateSet); Assert.False(attribs[0].DeprecateByVersionSet); string pat = @"(The output type ')(.*)(' is being deprecated without a replacement.)"; Regex reg = new Regex(pat, RegexOptions.IgnoreCase | RegexOptions.Singleline); List <string> messages = BreakingChangeAttributeHelper.GetBreakingChangeMessagesForType(typeof(AzureRMTestCmdletWithCmdletWithOutputTypeDropped)); Assert.Equal(1, messages.Count); Assert.True(reg.IsMatch(messages[0])); Assert.True(messages[0].Contains(" - Cmdlet : '" + VerbNameHolder.CmdletNameVerb + "-" + AzureRMTestCmdletWithCmdletWithOutputTypeDropped.CmdletName)); Assert.False(messages[0].Contains("This change will take effect on '")); Assert.False(messages[0].Contains("Change description : ")); Assert.False(messages[0].Contains("The change is expected to take effect from the version")); Assert.False(messages[0].Contains("powershell\r\n# Old")); }
public void TestForCmdletWithParamTypeChange() { List <GenericBreakingChangeAttribute> attribs = new List <GenericBreakingChangeAttribute>(BreakingChangeAttributeHelper.GetAllBreakingChangeAttributesInType(typeof(AzureRMTestCmdletWithParamTypeChange), null)); Assert.Equal(1, attribs.Count); Assert.False(attribs[0].ChangeInEfectByDateSet); Assert.False(attribs[0].DeprecateByVersionSet); string pat = @"(The parameter : ')(.*)(' is changing)"; string pat1 = @"(The type of the parameter is changing from ')(.*)(' to ')(.*)('.)"; Regex reg = new Regex(pat, RegexOptions.IgnoreCase | RegexOptions.Singleline); Regex reg1 = new Regex(pat1, RegexOptions.IgnoreCase | RegexOptions.Singleline); List <string> messages = BreakingChangeAttributeHelper.GetBreakingChangeMessagesForType(typeof(AzureRMTestCmdletWithParamTypeChange)); Assert.Equal(1, messages.Count); Assert.True(reg.IsMatch(messages[0])); Assert.True(reg1.IsMatch(messages[0])); Assert.True(messages[0].Contains(" - Cmdlet : '" + VerbNameHolder.CmdletNameVerb + "-" + AzureRMTestCmdletWithParamTypeChange.CmdletName)); Assert.False(messages[0].Contains("This change will take effect on '")); Assert.False(messages[0].Contains("The change is expected to take effect from the version")); Assert.False(messages[0].Contains("powershell\r\n# Old")); Assert.False(messages[0].Contains("Change description : ")); }
public void TestAzureRMTestCmdletWithParameterMetadataChangeAndOrderChange() { List <GenericBreakingChangeAttribute> attribs = new List <GenericBreakingChangeAttribute>(BreakingChangeAttributeHelper.GetAllBreakingChangeAttributesInType(typeof(AzureRMTestCmdletWithParameterMetadataChangeAndAGenericChange), null)); Assert.Equal(2, attribs.Count); //This gets in the weeds here a lil too much, we get two different types of attributes, we will try and cast one to each type and then check if //the messages look good on each GenericBreakingChangeAttribute genericAttrib = null; CmdletParameterBreakingChangeAttribute paramMetaAttrib = null; try { genericAttrib = (GenericBreakingChangeAttribute)attribs[0]; } catch (InvalidCastException) { try { genericAttrib = (GenericBreakingChangeAttribute)attribs[1]; } catch (InvalidCastException) { //this is an exception that should not happen, one of these should be of the type we are tryin to get Assert.False(true); } } try { paramMetaAttrib = (CmdletParameterBreakingChangeAttribute)attribs[0]; } catch (InvalidCastException) { try { paramMetaAttrib = (CmdletParameterBreakingChangeAttribute)attribs[1]; } catch (InvalidCastException) { //this is an exception that should not happen, one of these should be of the type we are tryin to get Assert.False(true); } } Assert.NotNull(genericAttrib); Assert.NotNull(paramMetaAttrib); string pat1 = @"(" + AzureRMTestCmdletWithParameterMetadataChangeAndAGenericChange.GenericChangeDesc + ")"; Regex reg1 = new Regex(pat1, RegexOptions.IgnoreCase | RegexOptions.Singleline); string pat2 = @"(The parameter : ')(.*)(' is changing')"; Regex reg2 = new Regex(pat2, RegexOptions.IgnoreCase | RegexOptions.Singleline); List <string> messages = BreakingChangeAttributeHelper.GetBreakingChangeMessagesForType(typeof(AzureRMTestCmdletWithParameterMetadataChangeAndAGenericChange)); Assert.Equal(2, messages.Count); string genericMessage = null; string paramMessage = null; if (reg1.IsMatch(messages[0])) { genericMessage = messages[0]; paramMessage = messages[1]; } else { genericMessage = messages[1]; paramMessage = messages[0]; } Assert.NotNull(genericMessage); Assert.NotNull(paramMessage); //The below check confirms that the pattterns exist in different messages Assert.False(reg1.IsMatch(paramMessage)); Assert.False(reg2.IsMatch(genericMessage)); Assert.False(genericMessage.Contains("This change will take effect on '")); Assert.True(genericMessage.Contains("The change is expected to take effect from the version")); Assert.False(genericMessage.Contains("powershell\r\n# Old")); Assert.True(genericMessage.Contains(" - Cmdlet : '" + VerbNameHolder.CmdletNameVerb + "-" + AzureRMTestCmdletWithParameterMetadataChangeAndAGenericChange.CmdletName)); Assert.False(genericMessage.Contains("Change description : ")); Assert.False(paramMessage.Contains("This change will take effect on '")); Assert.True(paramMessage.Contains(" - Cmdlet : '" + VerbNameHolder.CmdletNameVerb + "-" + AzureRMTestCmdletWithParameterMetadataChangeAndAGenericChange.CmdletName)); Assert.False(paramMessage.Contains("The change is expected to take effect from the version")); Assert.False(paramMessage.Contains("powershell\r\n# Old")); Assert.True(paramMessage.Contains("Change description : " + AzureRMTestCmdletWithParameterMetadataChangeAndAGenericChange.ParamChangeDesc)); }