Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Jul 19, 2023
1 parent 85c4250 commit 91e3db7
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/RepoM.Api/Ordering/Score/ScoreComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public int Compare(IRepository? x, IRepository? y)
return -1;
}

var result = _calculator.Score(y) - _calculator.Score(x);
return result;
return _calculator.Score(y) - _calculator.Score(x);
}
}
103 changes: 103 additions & 0 deletions tests/RepoM.Api.Tests/Ordering/Score/AzComparerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
namespace RepoM.Api.Tests.Ordering.Score;

using System;
using FakeItEasy;
using FluentAssertions;
using RepoM.Api.Ordering.Score;
using RepoM.Core.Plugin.Repository;
using RepoM.Core.Plugin.RepositoryOrdering;
using Xunit;

public class ScoreComparerTests
{
private readonly IRepository _repo1;
private readonly IRepository _repo2;
private readonly IRepositoryScoreCalculator _calculator;
private readonly ScoreComparer _sut;

public ScoreComparerTests()
{
_repo1 = A.Fake<IRepository>();
_repo2 = A.Fake<IRepository>();
_calculator = A.Fake<IRepositoryScoreCalculator>();
_sut = new ScoreComparer(_calculator);
}

[Fact]
public void Ctor_ShouldThrow_WhenArgumentNull()
{
// arrange

// act
Func<ScoreComparer> act = () => new ScoreComparer(null!);

// assert
act.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Compare_ShouldReturnZero_WhenBothAreNull()
{
// arrange

// act
var result = _sut.Compare(null!, null!);

// assert
result.Should().Be(0);
}

[Fact]
public void Compare_ShouldReturnZero_WhenBothSameRepo()
{
// arrange

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

// assert
result.Should().Be(0);
}

[Fact]
public void Compare_ShouldReturnOne_WhenSecondRepoIsNull()
{
// arrange

// act
var result = _sut.Compare(_repo1, null);

// assert
result.Should().Be(1);
}

[Fact]
public void Compare_ShouldReturnMinusOne_WhenSecondRepoIsNull()
{
// arrange

// act
var result = _sut.Compare(null, _repo1);

// assert
result.Should().Be(-1);
}

[Theory]
[InlineData(0, 0, 0)]
[InlineData(10, 0, -10)]
[InlineData(0, 10, 10)]
[InlineData(7, 10, 3)]
public void Compare_ShouldReturnSubtractedValueFromBothRepositoryScores(int score1, int score2, int expectedValue)
{
// arrange
A.CallTo(() => _calculator.Score(_repo1)).Returns(score1);
A.CallTo(() => _calculator.Score(_repo2)).Returns(score2);

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

// assert
result.Should().Be(expectedValue);
}
}

0 comments on commit 91e3db7

Please sign in to comment.