Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Jul 19, 2023
1 parent 22e0948 commit f832a37
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/RepoM.Api/Git/RepositoryAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public RepositorySeparatorAction(IRepository repository)
}
}


public class RepositoryAction : RepositoryActionBase
{
public RepositoryAction(string name, IRepository repository):
Expand Down
100 changes: 100 additions & 0 deletions tests/RepoM.Api.Tests/Ordering/Az/AzComparerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
namespace RepoM.Api.Tests.Ordering.Az;

using FakeItEasy;
using FluentAssertions;
using RepoM.Api.Ordering.Az;
using RepoM.Core.Plugin.Repository;
using Xunit;

public class AzComparerTests
{
private readonly IRepository _repo1;
private readonly IRepository _repo2;

public AzComparerTests()
{
_repo1 = A.Fake<IRepository>();
_repo2 = A.Fake<IRepository>();
}

[Fact]
public void Compare_ShouldBeZero_WhenReposAreNull()
{
// arrange
var sut = new AzComparer(10, "Name");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit f832a37

Please sign in to comment.