52 lines
No EOL
1.4 KiB
C#
52 lines
No EOL
1.4 KiB
C#
using BuildingDirectory.Model;
|
|
|
|
namespace BuildingDirectory.Test;
|
|
|
|
public sealed class BusinessCardTests
|
|
{
|
|
|
|
[Fact]
|
|
public void Equals_Equal()
|
|
{
|
|
BusinessCard[] cards = CreateSampleCards();
|
|
|
|
cards[0].Equals(cards[1]).Should().BeTrue("only name is considered");
|
|
cards[2].Equals(cards[3]).Should().BeTrue("only name is considered");
|
|
}
|
|
|
|
[Fact]
|
|
public void Equals_NotEqual()
|
|
{
|
|
BusinessCard[] cards = CreateSampleCards();
|
|
|
|
cards[1].Equals(cards[2]).Should().BeFalse("different people");
|
|
}
|
|
|
|
[Fact]
|
|
public void HashCode_Value()
|
|
{
|
|
var card = CreateSampleCards()[0];
|
|
|
|
card.GetHashCode()
|
|
.Should().Be(card.GetHashCode(), "has to return same value for same input every time");
|
|
}
|
|
|
|
[Fact]
|
|
public void HashCode_RelevantProperties()
|
|
{
|
|
BusinessCard[] cards = CreateSampleCards();
|
|
var card1 = cards[2];
|
|
var card2 = cards[3];
|
|
|
|
card1.GetHashCode()
|
|
.Should().Be(card2.GetHashCode(), "hash code only based on relevant properties");
|
|
}
|
|
|
|
private static BusinessCard[] CreateSampleCards() =>
|
|
[
|
|
new("Horst", "Fuchs", "Sales", null, "h.fuchs@foo.com"),
|
|
new("Horst", "Fuchs", "KeyAccounting", "1234", "horst.fuchs@foo.com"),
|
|
new("Susi", "Sonne", "Development", null, "s.sonne@foo.com"),
|
|
new("Susi", "Sonne", "Research", null, "s.sonne@foo.com")
|
|
];
|
|
} |