コード例 #1
0
    public void DistinctModelsProduceDistinctHashCodesAndNonEquality()
    {
        // Arrange
        var fieldIdentifier1 = new FieldIdentifier(new object(), "field");
        var fieldIdentifier2 = new FieldIdentifier(new object(), "field");

        // Act/Assert
        Assert.NotEqual(fieldIdentifier1.GetHashCode(), fieldIdentifier2.GetHashCode());
        Assert.False(fieldIdentifier1.Equals(fieldIdentifier2));
    }
コード例 #2
0
    public void SameContentsProduceSameHashCodesAndEquality()
    {
        // Arrange
        var model            = new object();
        var fieldIdentifier1 = new FieldIdentifier(model, "field");
        var fieldIdentifier2 = new FieldIdentifier(model, "field");

        // Act/Assert
        Assert.Equal(fieldIdentifier1.GetHashCode(), fieldIdentifier2.GetHashCode());
        Assert.True(fieldIdentifier1.Equals(fieldIdentifier2));
    }
コード例 #3
0
    public void FieldIdentifier_ForModelWithoutField_ProduceSameHashCodesAndEquality()
    {
        // Arrange
        var model            = new object();
        var fieldIdentifier1 = new FieldIdentifier(model, fieldName: string.Empty);
        var fieldIdentifier2 = new FieldIdentifier(model, fieldName: string.Empty);

        // Act/Assert
        Assert.Equal(fieldIdentifier1.GetHashCode(), fieldIdentifier2.GetHashCode());
        Assert.True(fieldIdentifier1.Equals(fieldIdentifier2));
    }
コード例 #4
0
    public void FieldNamesAreCaseSensitive()
    {
        // Arrange
        var model = new object();
        var fieldIdentifierLower  = new FieldIdentifier(model, "field");
        var fieldIdentifierPascal = new FieldIdentifier(model, "Field");

        // Act/Assert
        Assert.Equal("field", fieldIdentifierLower.FieldName);
        Assert.Equal("Field", fieldIdentifierPascal.FieldName);
        Assert.NotEqual(fieldIdentifierLower.GetHashCode(), fieldIdentifierPascal.GetHashCode());
        Assert.False(fieldIdentifierLower.Equals(fieldIdentifierPascal));
    }
コード例 #5
0
    public void SameContents_WithOverridenEqualsAndGetHashCode_ProduceSameHashCodesAndEquality()
    {
        // Arrange
        var model            = new EquatableModel();
        var fieldIdentifier1 = new FieldIdentifier(model, nameof(EquatableModel.Property));

        model.Property = "changed value"; // To show it makes no difference if the overridden `GetHashCode` result changes
        var fieldIdentifier2 = new FieldIdentifier(model, nameof(EquatableModel.Property));

        // Act/Assert
        Assert.Equal(fieldIdentifier1.GetHashCode(), fieldIdentifier2.GetHashCode());
        Assert.True(fieldIdentifier1.Equals(fieldIdentifier2));
    }