Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions ProjectLighthouse.Tests/Unit/FilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,34 +749,6 @@ public void TeamPickFilter_ShouldReject_WhenNotTeamPick()
Assert.False(teamPickFunc(slot));
}

[Fact]
public void TextFilter_ShouldAccept_WhenDescriptionContainsText()
{
TextFilter textFilter = new("test");
Func<SlotEntity, bool> textFunc = textFilter.GetPredicate().Compile();

SlotEntity slot = new()
{
Description = "unit test",
};

Assert.True(textFunc(slot));
}

[Fact]
public void TextFilter_ShouldReject_WhenDescriptionDoesNotContainText()
{
TextFilter textFilter = new("test");
Func<SlotEntity, bool> textFunc = textFilter.GetPredicate().Compile();

SlotEntity slot = new()
{
Description = "fraction exam",
};

Assert.False(textFunc(slot));
}

[Fact]
public void TextFilter_ShouldAccept_WhenNameContainsText()
{
Expand Down
14 changes: 5 additions & 9 deletions ProjectLighthouse/Filter/Filters/TextFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ public TextFilter(string filter)
public Expression<Func<SlotEntity, bool>> GetPredicate()
{
Expression<Func<SlotEntity, bool>> predicate = PredicateExtensions.False<SlotEntity>();
string[] keywords = this.filter.Split(" ", StringSplitOptions.RemoveEmptyEntries);
foreach (string keyword in keywords)
{
predicate = predicate.Or(s =>
s.Name.Contains(keyword) ||
s.Description.ToLower().Contains(keyword) ||
s.SlotId.ToString().Equals(keyword));
predicate = predicate.Or(s => s.Creator != null && s.Creator.Username.Contains(keyword));
}
string trimmed = this.filter.Trim();
predicate = predicate.Or(s =>
s.Name.Contains(trimmed) ||
s.SlotId.ToString().Equals(trimmed));
predicate = predicate.Or(s => s.Creator != null && s.Creator.Username.Contains(trimmed));
return predicate;
}
}