public void Equals_DifferentCategories()
        {
            var firstAttribute  = new CategoryAttribute("category");
            var secondAttribute = new DescriptionAttribute(string.Empty);

            Assert.False(firstAttribute.Equals(secondAttribute));
        }
        public void Equals_DifferentCategories()
        {
            var firstAttribute = new CategoryAttribute("category");
            var secondAttribute = new DescriptionAttribute(string.Empty);

            Assert.False(firstAttribute.Equals(secondAttribute));
        }
 public void Equals_Object_ReturnsExpected(CategoryAttribute attribute, object other, bool expected)
 {
     Assert.Equal(expected, attribute.Equals(other));
     if (other is CategoryAttribute otherAttribute && otherAttribute.Category != null)
     {
         Assert.Equal(expected, attribute.GetHashCode().Equals(other.GetHashCode()));
     }
 }
示例#4
0
        public void CopyPropertyTo(AppProductRecipe toRecipe)
        {
            CategoryAttribute target_attribute = new CategoryAttribute("Product Recipe");

            PropertyInfo[] toObjectProperties = toRecipe.GetType().GetProperties();
            foreach (PropertyInfo propTo in toObjectProperties)
            {
                try
                {
                    PropertyInfo        propFrom   = this.GetType().GetProperty(propTo.Name);
                    AttributeCollection attributes = TypeDescriptor.GetProperties(this)[propTo.Name].Attributes;
                    CategoryAttribute   ca         = (CategoryAttribute)attributes[typeof(CategoryAttribute)];

                    if (propFrom != null && propFrom.CanWrite && ca.Equals(target_attribute))
                    {
                        propTo.SetValue(toRecipe, propFrom.GetValue(this, null), null);
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
        public void Equals_NullCategory_ThrowsNullReferenceException()
        {
            var attribute = new CategoryAttribute(null);

            Assert.Throws <NullReferenceException>(() => attribute.Equals(new CategoryAttribute("a")));
        }