public void Initialize() { // run following command to write test method metadata to console: // dotnet test --logger:"console;verbosity=normal" MethodInfo methodInfo = this.GetType().GetMethod(this.TestContext.TestName); DescriptionAttribute descriptionAttribute = methodInfo.GetCustomAttribute <DescriptionAttribute>(); Console.WriteLine($"Description : {descriptionAttribute.Description}"); TestCategoryAttribute testCategoryAttribute = methodInfo.GetCustomAttribute <TestCategoryAttribute>(); Console.WriteLine($"Category : {string.Join(',', testCategoryAttribute.TestCategories)}"); PriorityAttribute priorityAttribute = methodInfo.GetCustomAttribute <PriorityAttribute>(); Console.WriteLine($"Priority : {priorityAttribute.Priority}"); OwnerAttribute ownerAttribute = methodInfo.GetCustomAttribute <OwnerAttribute>(); Console.WriteLine($"Owner : {ownerAttribute.Owner}"); Stopwatch testMethodStopwatch = new Stopwatch(); testMethodStopwatch.Start(); this.TestContext.Properties["TestMethodStopwatch"] = testMethodStopwatch; }
protected virtual void InitPanels() { var attrs = DataPanelAttribute.GetDataPanels(this.DataContext.GetDataType()); SortedList <int, DataPanelAttribute> list = new SortedList <int, DataPanelAttribute>(); if (attrs != null) { foreach (var attr in attrs) { int priority = PriorityAttribute.GetPriority(attr.DataPanelType); list.Add(priority, attr); } } foreach (var attr in list.Values) { UserControl panel = (UserControl)attr.DataPanelType.GetConstructor(new Type[0]).Invoke(new object[0]); panel.Visible = false; panel.AutoSize = true; panel.Dock = DockStyle.Fill; this.AddPanel(attr.Path, panel); } if (this.panels.Count > 1) { this.SplitContainer.Panel1Collapsed = false; } this.calculateSize(); if (this.panels.Count > 0) { this.SelectPanel(this.panels[0]); } }
public void PriorityAttribute_IsValid_PriorityIsCorrect(int priority) { var priorityAttribute = new PriorityAttribute(); var result = priorityAttribute.IsValid(priority); Assert.True(result); }
public void PriorityAttribute_IsValid_PriorityIsIncorrect(int priority) { var priorityAttribute = new PriorityAttribute(); var result = priorityAttribute.GetValidationResult(priority, new ValidationContext(priority)); Assert.True(result != ValidationResult.Success); Assert.Equal("Priority does not exist", result.ErrorMessage); }
/// <summary> /// Initializes a new instance of the <see cref="AspectInfo" /> class. /// </summary> /// <param name="advices">The advices.</param> /// <param name="pointcutMethod">The pointcut method.</param> /// <param name="pointcutMethodHandle">The pointcut method handle.</param> /// <param name="advisedMethod">The advised method.</param> /// <param name="advisedMethodHandle">The advised method handle.</param> public AspectInfo(IEnumerable <AdviceInfo> advices, MethodInfo pointcutMethod, RuntimeMethodHandle pointcutMethodHandle, MethodBase advisedMethod, RuntimeMethodHandle advisedMethodHandle) { Advices = advices.OrderByDescending(a => PriorityAttribute.GetLevel(a.Advice)).ToArray(); PointcutMethod = pointcutMethod; PointcutMethodHandle = pointcutMethodHandle; AdvisedMethod = advisedMethod; AdvisedMethodHandle = advisedMethodHandle; }
public ActionInfo(Type type) { this.action = type.GetConstructor(new Type[0]).Invoke(new object[0]); this.priority = PriorityAttribute.GetPriority(this.action, 1000); this.text = CaptionAttribute.GetCaption(this.action, type.Name); this.description = BAL.Types.AttributesExtensions.GetDescription(null, this.action); var pinfo = type.GetProperty("Target", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.target = (ActionTarget)pinfo.GetValue(this.action, null); } else { this.target = ActionTarget.None; } pinfo = type.GetProperty("MarginLeft", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.MarginLeft = (int)pinfo.GetValue(this.action, null); } pinfo = type.GetProperty("MarginRight", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.MarginRight = (int)pinfo.GetValue(this.action, null); } pinfo = type.GetProperty("MarginTop", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.MarginTop = (int)pinfo.GetValue(this.action, null); } pinfo = type.GetProperty("MarginBottom", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.MarginBottom = (int)pinfo.GetValue(this.action, null); } this.propertySelectedRows = type.GetProperty("SelectedRows"); this.propertyCurrentRow = type.GetProperty("CurrentRow"); this.propertyFireReload = type.GetProperty("FireReload"); this.propertyFireRefresh = type.GetProperty("FireRefresh"); this.propertyFireSelectionChanged = type.GetProperty("FireSelectionChanged"); this.methodOnAction = type.GetMethod("OnAction", BindingFlags.Instance | BindingFlags.Public); this.methodOnSelectionChanged = type.GetMethod("OnSelectionChanged", BindingFlags.Instance | BindingFlags.Public); }
public static Priority GetPriority(this Type t) { // I am not sure, but I don't think GetCustomAttribute<PriorityAttribute> // would return derived PriorityAttribute such as EventListenerAttribute var priorityAttribute = new PriorityAttribute(); foreach (var attribute in t.GetCustomAttributes()) { if (attribute is PriorityAttribute priorityAttribute2) { priorityAttribute = priorityAttribute2; break; } } return(priorityAttribute.Priority); }
private static void checkCache() { if (__cache__ == null) { __cache__ = new Dictionary <Type, Type>(); var attrs = AppController.Instance.AssemblyAttributes[typeof(AppServiceAttribute)]; foreach (AppServiceAttribute attr in attrs) { if (__cache__.ContainsKey(attr.ServiceInterface)) { if (PriorityAttribute.GetPriority(attr) < PriorityAttribute.GetPriority(__cache__[attr.ServiceInterface])) { __cache__[attr.ServiceInterface] = attr.ServiceType; } } else { __cache__.Add(attr.ServiceInterface, attr.ServiceType); } } } }
public static StunRecord Read(byte[] bytes) { var record = new StunRecord(); var idx = 0; record.MessageType = (StunMessageType)BinaryPrimitives.ReadUInt16BigEndian(bytes.AsSpan(idx)); idx += 2; var stunMessageLength = BinaryPrimitives.ReadUInt16BigEndian(bytes.AsSpan(idx)); idx += 2; var stunMessageCookie = BinaryPrimitives.ReadInt32BigEndian(bytes.AsSpan(idx)); idx += 4; if (stunMessageCookie != StunRecord.MessageCookie) { throw new InvalidOperationException("Malformed STUN packet"); } record.MessageTransactionId = bytes.AsSpan(idx, 12).ToArray(); idx += 12; record.StunAttributes = new List <StunAttribute>(); while (idx < bytes.Length) { var stunAttributeType = (StunAttributeType)BinaryPrimitives.ReadUInt16BigEndian(bytes.AsSpan(idx)); idx += 2; var stunAttributeLength = BinaryPrimitives.ReadUInt16BigEndian(bytes.AsSpan(idx)); idx += 2; var stunAttributePaddingRemainder = (byte)(stunAttributeLength % 4); var stunAttributePadding = (byte)(stunAttributePaddingRemainder == 0 ? 0 : 4 - stunAttributePaddingRemainder); var stunAttributeValue = bytes.AsSpan(idx, stunAttributeLength).ToArray(); idx += stunAttributeLength; if (stunAttributePadding > 0) { idx += stunAttributePadding; } StunAttribute stunAttribute; switch (stunAttributeType) { case StunAttributeType.Username: stunAttribute = new UsernameAttribute(); break; case StunAttributeType.IceControlled: stunAttribute = new IceControlledAttribute(); break; case StunAttributeType.Priority: stunAttribute = new PriorityAttribute(); break; case StunAttributeType.MessageIntegrity: stunAttribute = new MessageIntegrityAttribute(); break; case StunAttributeType.Fingerprint: stunAttribute = new FingerprintAttribute(); break; default: stunAttribute = new StunAttribute { Type = stunAttributeType }; break; } stunAttribute.Value = stunAttributeValue; if (stunAttribute.Type != StunAttributeType.MessageIntegrity && stunAttribute.Type != StunAttributeType.Fingerprint) { record.StunAttributes.Add(stunAttribute); } } return(record); }
private void GetTestMethodData(MemberInfo member, ref DataRow row) { this.TestMethodData(); object[] attributes = member.GetCustomAttributes(true); bool testmethod = false; object[] objArray = attributes; int num = 0; while (num < (int)objArray.Length) { if (!(objArray[num] is TestMethodAttribute)) { num++; } else { testmethod = true; break; } } if (testmethod) { row[this.rTestName] = member.Name; HashAlgorithm Provider = new SHA1CryptoServiceProvider(); byte[] hash = Provider.ComputeHash(Encoding.Unicode.GetBytes(string.Concat(member.DeclaringType.FullName, ".", member.Name))); byte[] to = new byte[16]; Array.Copy(hash, to, 16); string str = this.rTestGUID; Guid guid = new Guid(to); row[str] = guid.ToString(); string p = ""; string o = ""; string c = ""; object[] objArray1 = attributes; for (int i = 0; i < (int)objArray1.Length; i++) { object att = objArray1[i]; PriorityAttribute pri = att as PriorityAttribute; OwnerAttribute own = att as OwnerAttribute; TestCategoryAttribute cate = att as TestCategoryAttribute; if (pri != null) { p = pri.Priority.ToString(); } if (own != null) { o = own.Owner; } if (cate != null) { foreach (string ca in cate.TestCategories) { c = string.Concat(c, ca, ";"); } } } row[this.rTestPriority] = p; row[this.rTestOwner] = o; if (c.Length > 0) { row[this.rTestCategory] = c.Remove(c.Length - 1); } } }