static bool isFiltered(MemberInfo mb) { if (mb == null) return false; ObsoleteAttribute oa = mb.GetCustomAttributes(typeof(ObsoleteAttribute), false).FirstOrDefault() as ObsoleteAttribute; if (oa != null/* && oa.IsError*/) //希望只过滤掉Error类别过时方法可以把oa.IsError加上 { return true; } if (mb is FieldInfo && (mb as FieldInfo).FieldType.IsPointer) return true; if (mb is PropertyInfo && (mb as PropertyInfo).PropertyType.IsPointer) return true; if (mb is MethodInfo && (mb as MethodInfo).ReturnType.IsPointer) return true; if (filters != null && filters.Count > 0) { foreach (var filter in filters) { if ((bool)filter.Invoke(null, new object[] { mb })) { return true; } } } if (mb is MethodBase && (mb as MethodBase).GetParameters().Any(pInfo => pInfo.ParameterType.IsPointer)) return true; return false; }
public bool PosTest1() { bool retVal = true; const string c_TEST_DESC = "PosTest1: Verify IsError property default value is false"; const string c_TEST_ID = "P001"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(); if (oa.IsError) { string errorDesc = "IsError property default value should be false"; TestLibrary.TestFramework.LogError("001 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002 "+"TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
/// <summary> /// Gets the documentation based on <see cref="T:System.Web.Http.Controllers.HttpActionDescriptor" />. /// </summary> /// <param name="actionDescriptor">The action descriptor.</param> /// <returns>The documentation for the action.</returns> public virtual string GetDocumentation(HttpActionDescriptor actionDescriptor) { var methodNode = this.GetMethodNode(actionDescriptor); var s = new List <string> { GetTagValueForAction(methodNode, "summary"), GetTagValueForAction(methodNode, "remarks") }; // Add message if controller requires authorization if (actionDescriptor.GetCustomAttributes <AuthorizeAttribute>().Any()) { s.Add("<p><i class='fa fa-lock'></i> Requires authorization!</p>"); } // Add message if action is marked as Obsolete ObsoleteAttribute obsoleteAttribute = actionDescriptor.GetCustomAttributes <ObsoleteAttribute>().FirstOrDefault(); if (obsoleteAttribute != null) { s.Add(string.Format("<p><i class='fa fa-warning'></i> This action is Obsolete: {0}</p>", string.IsNullOrEmpty(obsoleteAttribute.Message) ? "<i>unknown reason</i>" : obsoleteAttribute.Message)); } return(string.Join("", s.Where(x => !string.IsNullOrEmpty(x)))); }
public static void AddAttributes(List <AttributeCodeElement> attributeList, object[] attributeObjects) { foreach (object o in attributeObjects) { if (o is ObsoleteAttribute) { ObsoleteAttribute a = (ObsoleteAttribute)o; attributeList.Add(new ObsoleteAttributeCodeElement(a.Message, a.IsError)); } else if (o is GeneratedClassAttribute) { GeneratedClassAttribute a = (GeneratedClassAttribute)o; attributeList.Add(new GeneratedClassAttributeCodeElement(a.CreationDate)); } else if (o is GeneratedMemberAttribute) { GeneratedMemberAttribute a = (GeneratedMemberAttribute)o; attributeList.Add(new GeneratedMemberAttributeCodeElement(a.CreationDate)); } else { Scio.CodeGeneration.Logger.Debug("Attribute = " + o.ToString()); } } }
public bool PosTest1() { bool retVal = true; const string c_TEST_DESC = "PosTest1: Verify IsError property default value is false"; const string c_TEST_ID = "P001"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(); if (oa.IsError) { string errorDesc = "IsError property default value should be false"; TestLibrary.TestFramework.LogError("001 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; const string c_TEST_DESC = "PosTest3: Verify IsError property is true"; const string c_TEST_ID = "P003"; string message = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message, true); if (!oa.IsError) { string errorDesc = "IsError property value should be true"; TestLibrary.TestFramework.LogError("005 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
static void Main(string[] args) { // create an Attribute Tester for the attribute we are interested in AttributeTester <ObsoleteAttribute> attrTester = new AttributeTester <ObsoleteAttribute>(); // check to see if the attribute has been applied to a property bool propTest = attrTester.TestForPropertyAttribute(typeof(Calculator), "MyProperty"); if (propTest) { // the attribute is defined - get the instance of the attribute ObsoleteAttribute attr = attrTester.GetPropertyAttribute(typeof(Calculator), "MyProperty"); // write out the properties of the attribute Console.WriteLine("Attribute: message: {0}, error: {1}", attr.Message, attr.IsError); } // get a list of the names of the properties that have been modified string[] modifiedFieldNames = attrTester.GetModifiedProperties(typeof(Calculator)); foreach (string s in modifiedFieldNames) { Console.WriteLine("Modified property: {0}", s); } // wait for input before exiting Console.WriteLine("Press enter to finish"); Console.ReadLine(); }
private static TypeFlags GetConstructorFlags(Type type, ref Exception exception) { ConstructorInfo ctor = type.GetConstructor(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, new Type[0]); if (ctor != null) { TypeFlags flags = TypeFlags.HasDefaultConstructor; if (!ctor.IsPublic) { flags |= TypeFlags.CtorInaccessible; } else { object[] attrs = ctor.GetCustomAttributes(typeof(ObsoleteAttribute), false).ToArray(); if (attrs != null && attrs.Length > 0) { ObsoleteAttribute obsolete = (ObsoleteAttribute)attrs[0]; if (obsolete.IsError) { flags |= TypeFlags.CtorInaccessible; } } } return(flags); } return(0); }
/// <summary> /// Common method for Obsolete error/warning reporting. /// </summary> public static void ReportObsoleteMessage(ParseContext parseContext, ObsoleteAttribute oa, string member, SourceSpan loc) { if (oa.IsError) { parseContext.ReportError( 619, string.Format("'{0}' is obsolete: '{1}'.", member, oa.Message), loc); return; } if (string.IsNullOrEmpty(oa.Message)) { parseContext.ReportError( 612, string.Format("'{0}' is obsolete.", member), Severity.Warning, loc); return; } parseContext.ReportError( 612, string.Format("'{0}' is obsolete: '{1}'.", member, oa.Message), Severity.Warning, loc); }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify IsError property is false"; const string c_TEST_ID = "P002"; string message = TestLibrary.Generator.GetString(-55, false,c_MINI_STRING_LENGTH,c_MAX_STRING_LENGTH); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message,false); if (oa.IsError) { string errorDesc = "IsError property value should be false"; TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public ResourceDescription(ITableType tableType) { var type = tableType.TypeName; this.ResourceName = type.Name; //遍历所有自定义属性 foreach (var one in type.GetProperties()) { ObsoleteAttribute obsolete = Attribute.GetCustomAttribute(one, typeof(ObsoleteAttribute)) as ObsoleteAttribute; ColumnAttribute att = Attribute.GetCustomAttribute(one, typeof(ColumnAttribute)) as ColumnAttribute; if (att == null) { continue; } FieldDefine rf = GetPropertyInfo(one, att, obsolete); if (rf == null) { continue; } Fields.Add(rf); } }
private void InitCommon() { // set the metadata this.Command.CommandInfo = this.CommandInfo; // set the ObsoleteAttribute of the current command _obsoleteAttribute = this.CommandInfo.CommandMetadata.Obsolete; // set the execution context this.Command.Context = this._context; // Now set up the command runtime for this command. try { this.commandRuntime = new MshCommandRuntime(_context, this.CommandInfo, this.Command); this.Command.commandRuntime = this.commandRuntime; } catch (Exception e) // Catch-all OK, 3rd party callout. { // Log a command health event MshLog.LogCommandHealthEvent( this._context, e, Severity.Warning); throw; } }
private static TypeFlags GetConstructorFlags(Type type, ref Exception exception) { ConstructorInfo info = type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null); if (info == null) { return(TypeFlags.None); } TypeFlags hasDefaultConstructor = TypeFlags.HasDefaultConstructor; if (!info.IsPublic) { return(hasDefaultConstructor | TypeFlags.CtorInaccessible); } object[] customAttributes = info.GetCustomAttributes(typeof(ObsoleteAttribute), false); if ((customAttributes != null) && (customAttributes.Length > 0)) { ObsoleteAttribute attribute = (ObsoleteAttribute)customAttributes[0]; if (attribute.IsError) { hasDefaultConstructor |= TypeFlags.CtorInaccessible; } } return(hasDefaultConstructor); }
public static void Ctor_String() { var attribute = new ObsoleteAttribute("this is obsolete"); Assert.Equal("this is obsolete", attribute.Message); Assert.False(attribute.IsError); }
public static void Ctor_String_Bool() { var attribute = new ObsoleteAttribute("this is obsolete", true); Assert.Equal("this is obsolete", attribute.Message); Assert.True(attribute.IsError); }
private static void CheckDeprecation(string functionName, MethodInfo function, Project project) { // check whether the function is deprecated ObsoleteAttribute obsoleteAttribute = (ObsoleteAttribute) Attribute.GetCustomAttribute(function, typeof(ObsoleteAttribute), true); // if function itself is not deprecated, check if its declaring // type is deprecated if (obsoleteAttribute == null) { obsoleteAttribute = (ObsoleteAttribute) Attribute.GetCustomAttribute(function.DeclaringType, typeof(ObsoleteAttribute), true); } if (obsoleteAttribute != null) { string obsoleteMessage = string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1087"), functionName, obsoleteAttribute.Message); if (obsoleteAttribute.IsError) { throw new BuildException(obsoleteMessage, Location.UnknownLocation); } else { project.Log(Level.Warning, "{0}", obsoleteMessage); } } }
public static void Ctor_Default() { var attribute = new ObsoleteAttribute(); Assert.Null(attribute.Message); Assert.False(attribute.IsError); }
public void Ctor_String_Bool(string message, bool error) { var attribute = new ObsoleteAttribute(message, error); Assert.Equal(message, attribute.Message); Assert.Equal(error, attribute.IsError); }
public void Ctor_String(string message) { var attribute = new ObsoleteAttribute(message); Assert.Equal(message, attribute.Message); Assert.False(attribute.IsError); }
public bool PosTest3() { bool retVal = true; const string c_TEST_DESC = "PosTest3: Verify create the ObsoleteAttribute object's IsError property is false"; const string c_TEST_ID = "P003"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(); if (oa.IsError) { string errorDesc = "created ObsoleteAttribute IsError property should be false"; TestLibrary.TestFramework.LogError("005 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify createed ObsoleteAttribute object's Message is null"; const string c_TEST_ID = "P002"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(); if (oa.Message != null) { string errorDesc = "created ObsoleteAttribute's Message should be null"; TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { ObsoleteAttribute obsoleteAttribute = (ObsoleteAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(ObsoleteAttribute)); EditorStyles.label.richText = true; EditorGUI.PropertyField(position, property, new GUIContent("<color=red><i>" + label.text + "</i></color>", "**OBSOLETE**\n\n" + obsoleteAttribute.Message), true); }
public void Remove_AttributeThatIsNotDerivedFromDisposableAttribute_ShouldThrow() { Mock <IGarbageDisposalStrategy> strategyMock = new Mock <IGarbageDisposalStrategy>(); Attribute attribute = new ObsoleteAttribute(); this.strategyHolder.RemoveStrategy(attribute.GetType()); }
static void Main(string[] args) { // Get the class type to access its metadata. Type clsType = typeof(TestClass); // Get the MethodInfo object for Method1. MethodInfo mInfo = clsType.GetMethod("Method1"); // See if the Obsolete attribute is defined for this method. bool isDef = Attribute.IsDefined(mInfo, typeof(ObsoleteAttribute)); // Display the result. Console.WriteLine("The Obsolete Attribute {0} defined for {1} of class {2}.", isDef ? "is" : "is not", mInfo.Name, clsType.Name); // If it's defined, display the attribute's message. if (isDef) { ObsoleteAttribute obsAttr = (ObsoleteAttribute)Attribute.GetCustomAttribute( mInfo, typeof(ObsoleteAttribute)); if (obsAttr != null) { Console.WriteLine("The message is: \"{0}\".", obsAttr.Message); } else { Console.WriteLine("The message could not be retrieved."); } } }
/// <summary> /// Returns instance of ObsoleteAttribute for this MemberCore /// </summary> public virtual ObsoleteAttribute GetAttributeObsolete() { if ((caching_flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) { return(null); } caching_flags &= ~Flags.Obsolete_Undetected; if (OptAttributes == null) { return(null); } Attribute obsolete_attr = OptAttributes.Search(Module.PredefinedAttributes.Obsolete); if (obsolete_attr == null) { return(null); } caching_flags |= Flags.Obsolete; ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute(); if (obsolete == null) { return(null); } return(obsolete); }
public void Attributes() { Attribute[] attributes = new Attribute [3]; Attribute[] attributes2; attributes[0] = new ObsoleteAttribute(); attributes[1] = new ObsoleteAttribute(); attributes[2] = new NonSerializedAttribute(); PropertyMetadata pm = new PropertyMetadata(attributes); attributes2 = pm.GetAttributes(); Assert.AreEqual(3, attributes2.Length, "C9#1"); Assert.AreEqual(attributes[0], attributes2[0], "C9#2"); Assert.AreEqual(attributes[1], attributes2[1], "C9#3"); Assert.AreEqual(attributes[2], attributes2[2], "C9#4"); attributes2 = pm.GetAttributes(typeof(NonSerializedAttribute)); Assert.AreEqual(1, attributes2.Length, "C9#5"); Assert.AreEqual(attributes[2], attributes2[0], "C9#6"); attributes2 = pm.GetAttributes(typeof(ObsoleteAttribute)); Assert.AreEqual(2, attributes2.Length, "C9#7"); Assert.AreEqual(attributes[0], attributes2[0], "C9#8"); Assert.AreEqual(attributes[1], attributes2[1], "C9#9"); attributes2 = pm.GetAttributes(typeof(ParamArrayAttribute)); Assert.AreEqual(0, attributes2.Length, "C9#10"); }
public bool PosTest1() { bool retVal = true; const string c_TEST_DESC = "PosTest1: Verify Message property default value is null"; const string c_TEST_ID = "P001"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(); if (oa.Message != null) { string errorDesc = "Message default value is not null expected:Actual (\"" + oa.Message + "\")"; TestLibrary.TestFramework.LogError("001 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public static void Main() { // Get all public members of this type. MemberInfo[] members = typeof(Example).GetMembers(); // Count total obsolete members. int n = 0; // Try to get the ObsoleteAttribute for each public member. Console.WriteLine("Obsolete members in the Example class:\n"); foreach (var member in members) { ObsoleteAttribute[] attribs = (ObsoleteAttribute[]) member.GetCustomAttributes(typeof(ObsoleteAttribute), false); if (attribs.Length > 0) { ObsoleteAttribute attrib = attribs[0]; Console.WriteLine("Member Name: {0}.{1}", member.DeclaringType.FullName, member.Name); Console.WriteLine(" Message: {0}", attrib.Message); Console.WriteLine(" Warning/Error: {0}", attrib.IsError ? "Error" : "Warning"); n++; } } if (n == 0) { Console.WriteLine("The Example type has no obsolete attributes."); } }
public bool PosTest3() { bool retVal = true; const string c_TEST_DESC = "PosTest3: Verify Message property is empty"; const string c_TEST_ID = "P003"; string message = String.Empty; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message, false); if (oa.Message != message) { string errorDesc = "Message value is not empty expected:Actual (\"" + oa.Message + "\")"; TestLibrary.TestFramework.LogError("005 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify Message property is random string"; const string c_TEST_ID = "P002"; string message = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message); if (oa.Message != message) { string errorDesc = "Message value is not \""+message+"\" expected:Actual (\"" + oa.Message + "\")"; TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify Message property is random string"; const string c_TEST_ID = "P002"; string message = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message); if (oa.Message != message) { string errorDesc = "Message value is not \"" + message + "\" expected:Actual (\"" + oa.Message + "\")"; TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
static bool isFiltered(MemberInfo mb) { if (mb == null) { return(false); } ObsoleteAttribute oa = mb.GetCustomAttributes(typeof(ObsoleteAttribute), false).FirstOrDefault() as ObsoleteAttribute; if (oa != null /* && oa.IsError*/) //希望只过滤掉Error类别过时方法可以把oa.IsError加上 { return(true); } if (filters != null && filters.Count > 0) { foreach (var filter in filters) { if ((bool)filter.Invoke(null, new object[] { mb })) { return(true); } } } return(false); }
public bool PosTest1() { bool retVal = true; const string c_TEST_DESC = "PosTest1: Verify Message property default value is null"; const string c_TEST_ID = "P001"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(); if (oa.Message != null) { string errorDesc = "Message default value is not null expected:Actual (\""+oa.Message+"\")"; TestLibrary.TestFramework.LogError("001 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify createed ObsoleteAttribute object's Message is null"; const string c_TEST_ID = "P002"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(); if (oa.Message != null) { string errorDesc = "created ObsoleteAttribute's Message should be null"; TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public void FindTypesByAttributeInAssemblies() { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); var types = new ObsoleteAttribute().FindAttributedTypes(assemblies); Assert.IsTrue(types.Any()); }
public bool PosTest1() { bool retVal = true; const string c_TEST_DESC = "PosTest1: Verify the message is the random string and isError is false"; const string c_TEST_ID = "P001"; string message = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message,false); if (oa.Message != message) { string errorDesc = "Message is not \"" + message + "\" as expected:Actual(\"" + oa.Message + "\")"; TestLibrary.TestFramework.LogError("001 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } if (oa.IsError) { string errorDesc = "IsError should be false"; TestLibrary.TestFramework.LogError("002 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e +"IsError is false and message is "+message); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify the message is empty"; const string c_TEST_ID = "P002"; string message = String.Empty; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message); if (oa.Message != message) { string errorDesc = "Message is not empty as expected:Actual(\"" + oa.Message + "\")"; TestLibrary.TestFramework.LogError("004 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } if (oa.IsError) { string errorDesc = "created ObsoleteAttribute IsError property should be false"; TestLibrary.TestFramework.LogError("005 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006 ", "Unexpected exception: " + e+"message is empty"); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
/// <summary> /// Write warning message for an obsolete command /// </summary> /// <param name="obsoleteAttr"></param> private void HandleObsoleteCommand(ObsoleteAttribute obsoleteAttr) { string commandName = String.IsNullOrEmpty(CommandInfo.Name) ? "script block" : String.Format(System.Globalization.CultureInfo.InvariantCulture, CommandBaseStrings.ObsoleteCommand, CommandInfo.Name); string warningMsg = String.Format( System.Globalization.CultureInfo.InvariantCulture, CommandBaseStrings.UseOfDeprecatedCommandWarning, commandName, obsoleteAttr.Message); // We ignore the IsError setting because we don't want to break people when obsoleting a command using (this.CommandRuntime.AllowThisCommandToWrite(false)) { this.CommandRuntime.WriteWarning(new WarningRecord(FQIDCommandObsolete, warningMsg)); } }
public bool PosTest4() { bool retVal = true; const string c_TEST_DESC = "PosTest4: Verify the message is null and isError is true"; const string c_TEST_ID = "P004"; string message = null; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message, true); if (oa.Message != null) { string errorDesc = "Message is not null as expected:Actual(\"" + oa.Message + "\")"; TestLibrary.TestFramework.LogError("010 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } if (!oa.IsError) { string errorDesc = "IsError should be true"; TestLibrary.TestFramework.LogError("011 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("012 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e + "message is " + "IsError is true and message is null"); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; const string c_TEST_DESC = "PosTest3: Verify Message property is empty"; const string c_TEST_ID = "P003"; string message = String.Empty; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(message,false); if (oa.Message != message) { string errorDesc = "Message value is not empty expected:Actual (\"" + oa.Message + "\")"; TestLibrary.TestFramework.LogError("005 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
private void InitCommon() { // set the metadata this.Command.CommandInfo = this.CommandInfo; // set the ObsoleteAttribute of the current command _obsoleteAttribute = this.CommandInfo.CommandMetadata.Obsolete; // set the execution context this.Command.Context = this._context; // Now set up the command runtime for this command. try { this.commandRuntime = new MshCommandRuntime(_context, this.CommandInfo, this.Command); this.Command.commandRuntime = this.commandRuntime; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); // Log a command health event MshLog.LogCommandHealthEvent( this._context, e, Severity.Warning); throw; } }
public bool PosTest3() { bool retVal = true; const string c_TEST_DESC = "PosTest3: Verify create the ObsoleteAttribute object's IsError property is false"; const string c_TEST_ID = "P003"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { ObsoleteAttribute oa = new ObsoleteAttribute(); if (oa.IsError) { string errorDesc = "created ObsoleteAttribute IsError property should be false"; TestLibrary.TestFramework.LogError("005 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }