System.Net.Http.Headers.AuthenticationHeaderValue.Equals C# (CSharp) Method

Equals() public method

public Equals ( object obj ) : bool
obj object
return bool
        public override bool Equals(object obj)
        {
            AuthenticationHeaderValue other = obj as AuthenticationHeaderValue;

            if (other == null)
            {
                return false;
            }

            if (string.IsNullOrEmpty(_parameter) && string.IsNullOrEmpty(other._parameter))
            {
                return (string.Equals(_scheme, other._scheme, StringComparison.OrdinalIgnoreCase));
            }
            else
            {
                // Since we can't parse the parameter, we use case-sensitive comparison.
                return string.Equals(_scheme, other._scheme, StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(_parameter, other._parameter, StringComparison.Ordinal);
            }
        }

Usage Example

        public void Equals_UseSameAndDifferentAuth_EqualOrNotEqualNoExceptions()
        {
            AuthenticationHeaderValue auth1 = new AuthenticationHeaderValue("A", "b");
            AuthenticationHeaderValue auth2 = new AuthenticationHeaderValue("a", "b");
            AuthenticationHeaderValue auth3 = new AuthenticationHeaderValue("A", "B");
            AuthenticationHeaderValue auth4 = new AuthenticationHeaderValue("A");
            AuthenticationHeaderValue auth5 = new AuthenticationHeaderValue("A", "");
            AuthenticationHeaderValue auth6 = new AuthenticationHeaderValue("X", "b");

            Assert.False(auth1.Equals(null));
            Assert.True(auth1.Equals(auth2));
            Assert.False(auth1.Equals(auth3));
            Assert.False(auth1.Equals(auth4));
            Assert.False(auth4.Equals(auth1));
            Assert.False(auth1.Equals(auth5));
            Assert.False(auth5.Equals(auth1));
            Assert.True(auth4.Equals(auth5));
            Assert.True(auth5.Equals(auth4));
            Assert.False(auth1.Equals(auth6));
        }