Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Jul 19, 2023
1 parent f832a37 commit 85c4250
Showing 1 changed file with 66 additions and 11 deletions.
77 changes: 66 additions & 11 deletions tests/RepoM.Api.Tests/Ordering/Az/AzComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public AzComparerTests()
}

[Fact]
public void Compare_ShouldBeZero_WhenReposAreNull()
public void Compare_ShouldReturnZero_WhenReposAreNull()
{
// arrange
var sut = new AzComparer(10, "Name");
Expand All @@ -33,7 +33,7 @@ public void Compare_ShouldBeZero_WhenReposAreNull()
[Theory]
[InlineData(10)]
[InlineData(24)]
public void Compare_ShouldBeWeight_WhenSecondRepoIsNull(int weight)
public void Compare_ShouldReturnWeight_WhenSecondRepoIsNull(int weight)
{
// arrange
var sut = new AzComparer(weight, "Name");
Expand All @@ -48,7 +48,7 @@ public void Compare_ShouldBeWeight_WhenSecondRepoIsNull(int weight)
[Theory]
[InlineData(10)]
[InlineData(24)]
public void Compare_ShouldBeNegativeWeight_WhenFirstRepoIsNull(int weight)
public void Compare_ShouldReturnNegativeWeight_WhenFirstRepoIsNull(int weight)
{
// arrange
var sut = new AzComparer(weight, "Name");
Expand All @@ -61,14 +61,14 @@ public void Compare_ShouldBeNegativeWeight_WhenFirstRepoIsNull(int weight)
}

[Theory]
[InlineData(10)]
[InlineData(24)]
public void Compare_ShouldBeNegativeWeight_WhenNameOfFirstRepoIsBeforeNameSecondRepo(int weight)
[InlineData("name", 10)]
[InlineData("NAmE", 24)]
public void Compare_ShouldReturnNegativeWeight_WhenNameOfFirstRepoIsBeforeNameSecondRepo(string property, int weight)
{
// arrange
A.CallTo(() => _repo1.Name).Returns("Abcd");
A.CallTo(() => _repo2.Name).Returns("Def");
var sut = new AzComparer(weight, "Name");
var sut = new AzComparer(weight, property);

// act
var result = sut.Compare(_repo1, _repo2);
Expand All @@ -80,14 +80,14 @@ public void Compare_ShouldBeNegativeWeight_WhenNameOfFirstRepoIsBeforeNameSecond
}

[Theory]
[InlineData(10)]
[InlineData(24)]
public void Compare_ShouldBeNegativeWeight_WhenNameOfFirstRepoIsAfterNameSecondRepo(int weight)
[InlineData("name", 10)]
[InlineData("NAmE", 24)]
public void Compare_ShouldReturnWeight_WhenNameOfFirstRepoIsAfterNameSecondRepo(string property, int weight)
{
// arrange
A.CallTo(() => _repo1.Name).Returns("Def");
A.CallTo(() => _repo2.Name).Returns("Abcd");
var sut = new AzComparer(weight, "Name");
var sut = new AzComparer(weight, property);

// act
var result = sut.Compare(_repo1, _repo2);
Expand All @@ -97,4 +97,59 @@ public void Compare_ShouldBeNegativeWeight_WhenNameOfFirstRepoIsAfterNameSecondR
A.CallTo(() => _repo2.Name).MustHaveHappenedOnceExactly();
result.Should().Be(weight);
}

[Theory]
[InlineData(10)]
[InlineData(24)]
public void Compare_ShouldReturnZero_WhenPropertyIsNotKnown(int weight)
{
// arrange
var sut = new AzComparer(weight, "x");

// act
var result = sut.Compare(_repo1, _repo2);

// assert
A.CallTo(_repo1).MustNotHaveHappened();
A.CallTo(_repo2).MustNotHaveHappened();
result.Should().Be(0);
}

[Theory]
[InlineData("Location", 10)]
[InlineData("LoCAtion", 24)]
public void Compare_ShouldReturnNegativeWeight_WhenLocationOfFirstRepoIsBeforeLocationSecondRepo(string property, int weight)
{
// arrange
A.CallTo(() => _repo1.Location).Returns("Abcd");
A.CallTo(() => _repo2.Location).Returns("Def");
var sut = new AzComparer(weight, property);

// act
var result = sut.Compare(_repo1, _repo2);

// assert
A.CallTo(() => _repo1.Location).MustHaveHappenedOnceExactly();
A.CallTo(() => _repo2.Location).MustHaveHappenedOnceExactly();
result.Should().Be(weight * -1);
}

[Theory]
[InlineData("Location", 10)]
[InlineData("LoCAtion", 24)]
public void Compare_ShouldReturnWeight_WhenLocationOfFirstRepoIsAfterLocationSecondRepo(string property, int weight)
{
// arrange
A.CallTo(() => _repo1.Location).Returns("Def");
A.CallTo(() => _repo2.Location).Returns("Abcd");
var sut = new AzComparer(weight, property);

// act
var result = sut.Compare(_repo1, _repo2);

// assert
A.CallTo(() => _repo1.Location).MustHaveHappenedOnceExactly();
A.CallTo(() => _repo2.Location).MustHaveHappenedOnceExactly();
result.Should().Be(weight);
}
}

0 comments on commit 85c4250

Please sign in to comment.