Exemplo n.º 1
0
 public void Equals_Object_ReturnsExpected(DisplayNameAttribute attribute, object other, bool expected)
 {
     Assert.Equal(expected, attribute.Equals(other));
     if (other is DisplayNameAttribute otherAttribute && otherAttribute.DisplayName != null && attribute.DisplayName != null)
     {
         Assert.Equal(expected, attribute.GetHashCode().Equals(other.GetHashCode()));
     }
 }
        public void GetHashCodeTest()
        {
            DisplayNameAttribute dn = new DisplayNameAttribute();

            Assert.AreEqual(string.Empty.GetHashCode(), dn.GetHashCode(), "#A1");
            dn = new DisplayNameAttribute("A");
            Assert.AreEqual("A".GetHashCode(), dn.GetHashCode(), "#A2");

            // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=288534
            dn = new DisplayNameAttribute(null);
            try {
                dn.GetHashCode();
                Assert.Fail("#B1");
            } catch (NullReferenceException) {
            }
        }
Exemplo n.º 3
0
        public void GetHashCode_NullDisplayName_ThrowsNullReferenceException()
        {
            var attribute = new DisplayNameAttribute(null);

            Assert.Throws <NullReferenceException>(() => attribute.GetHashCode());
        }