-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/RepoM.App/RepositoryFiltering/QueryMatchers/IsBehindMatcher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace RepoM.App.RepositoryFiltering.QueryMatchers; | ||
|
||
using System; | ||
using JetBrains.Annotations; | ||
using RepoM.Core.Plugin.Repository; | ||
using RepoM.Core.Plugin.RepositoryFiltering; | ||
using RepoM.Core.Plugin.RepositoryFiltering.Clause.Terms; | ||
|
||
[UsedImplicitly] | ||
public class IsBehindMatcher : IQueryMatcher | ||
{ | ||
public bool? IsMatch(in IRepository repository, in TermBase term) | ||
{ | ||
if (term is not SimpleTerm st) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!"is".Equals(st.Term, StringComparison.CurrentCulture)) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!"behind".Equals(st.Value, StringComparison.CurrentCulture)) | ||
{ | ||
return null; | ||
} | ||
|
||
return repository.IsBehind; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,6 @@ public interface IRepository | |
|
||
|
||
public bool HasLocalChanges { get; } | ||
|
||
public bool IsBehind { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,6 @@ public string[] ReadAllBranches() | |
} | ||
|
||
public bool HasLocalChanges => false; | ||
|
||
public bool IsBehind => false; | ||
} |
68 changes: 68 additions & 0 deletions
68
tests/RepoM.App.Tests/RepositoryFiltering/QueryMatchers/IsBehindMatcherTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
namespace RepoM.App.Tests.RepositoryFiltering.QueryMatchers; | ||
|
||
using FakeItEasy; | ||
using FluentAssertions; | ||
using RepoM.App.RepositoryFiltering.QueryMatchers; | ||
using RepoM.Core.Plugin.Repository; | ||
using RepoM.Core.Plugin.RepositoryFiltering.Clause.Terms; | ||
using Xunit; | ||
|
||
public class IsBehindMatcherTests | ||
{ | ||
private readonly IRepository _repository = A.Fake<IRepository>(); | ||
private readonly IsBehindMatcher _sut = new(); | ||
|
||
[Fact] | ||
public void IsMatch_ShouldReturnNull_WhenTermIsNotSimpleTerm() | ||
{ | ||
// arrange | ||
TermBase term = A.Fake<TermBase>(); | ||
|
||
// act | ||
var result = _sut.IsMatch(in _repository, in term); | ||
|
||
// assert | ||
result.Should().BeNull(); | ||
A.CallTo(_repository).MustNotHaveHappened(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("","")] | ||
[InlineData("bla","")] | ||
[InlineData("is","")] | ||
[InlineData("", "bla")] | ||
[InlineData("x", "behind")] | ||
[InlineData("", "behind")] | ||
[InlineData("is", "abehind")] | ||
[InlineData("is", "Behind")] // invalid casing | ||
[InlineData("Is", "behind")] // invalid casing | ||
public void IsMatch_ShouldReturnNull_WhenTermAndValueAreNotIsBehind(string term, string value) | ||
{ | ||
// arrange | ||
TermBase simpleTerm = new SimpleTerm(term, value); | ||
|
||
// act | ||
var result = _sut.IsMatch(in _repository, in simpleTerm); | ||
|
||
// assert | ||
result.Should().BeNull(); | ||
A.CallTo(_repository).MustNotHaveHappened(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void IsMatch_ShouldReturnRepositoryIsBehindValue_WhenTermAndValueMatches(bool repositoryIsBehind) | ||
{ | ||
// arrange | ||
A.CallTo(() => _repository.IsBehind).Returns(repositoryIsBehind); | ||
TermBase simpleTerm = new SimpleTerm("is", "behind"); | ||
|
||
// act | ||
var result = _sut.IsMatch(in _repository, in simpleTerm); | ||
|
||
// assert | ||
result.Should().Be(repositoryIsBehind); | ||
A.CallTo(() => _repository.IsBehind).MustHaveHappenedOnceExactly(); | ||
} | ||
} |