-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-448) Add a search criteria for "Contains"
- Loading branch information
Showing
4 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
Source/StrongGrid.UnitTests/Models/Search/Legacy/SearchCriteriaTests.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,51 @@ | ||
using Shouldly; | ||
using StrongGrid.Models.Search.Legacy; | ||
using Xunit; | ||
|
||
namespace StrongGrid.UnitTests.Models.Search.Legacy | ||
{ | ||
public class SearchCriteriaTests | ||
{ | ||
[Fact] | ||
public void SearchCriteriaBetween() | ||
{ | ||
// Arrange | ||
var searchCriteria = new SearchCriteriaBetween(EmailActivitiesFilterField.Clicks, 1, 5); | ||
|
||
// Act | ||
var result = searchCriteria.ToString(); | ||
|
||
// Assert | ||
result.ShouldNotBeNull(); | ||
result.ShouldBe("clicks BETWEEN 1 AND 5"); | ||
} | ||
|
||
[Fact] | ||
public void SearchCriteriaIn() | ||
{ | ||
// Arrange | ||
var searchCriteria = new SearchCriteriaIn(EmailActivitiesFilterField.Subject, new[] { "Subject1", "Subject2" }); | ||
|
||
// Act | ||
var result = searchCriteria.ToString(); | ||
|
||
// Assert | ||
result.ShouldNotBeNull(); | ||
result.ShouldBe("subject IN (\"Subject1\",\"Subject2\")"); | ||
} | ||
|
||
[Fact] | ||
public void SearchCriteriaEqual() | ||
{ | ||
// Arrange | ||
var searchCriteria = new SearchCriteriaEqual(EmailActivitiesFilterField.CampaignName, "abc123"); | ||
|
||
// Act | ||
var result = searchCriteria.ToString(); | ||
|
||
// Assert | ||
result.ShouldNotBeNull(); | ||
result.ShouldBe("campaign_name=\"abc123\""); | ||
} | ||
} | ||
} |
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
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,33 @@ | ||
using System; | ||
|
||
namespace StrongGrid.Models.Search | ||
{ | ||
/// <summary> | ||
/// Filter the result of a search for a field to contain a value. | ||
/// </summary> | ||
/// <typeparam name="TEnum">The type containing an enum of fields that can used for searching/segmenting.</typeparam> | ||
public class SearchCriteriaContains<TEnum> : SearchCriteria<TEnum> | ||
where TEnum : Enum | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SearchCriteriaContains{TEnum}"/> class. | ||
/// </summary> | ||
/// <param name="filterField">The filter field.</param> | ||
/// <param name="filterValue">The filter value.</param> | ||
public SearchCriteriaContains(TEnum filterField, object filterValue) | ||
: base(filterField, SearchComparisonOperator.Contains, filterValue) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Returns a string representation of the search criteria. | ||
/// </summary> | ||
/// <returns>A <see cref="string"/> representation of the search criteria.</returns> | ||
public override string ToString() | ||
{ | ||
var filterOperator = ConvertOperatorToString(); | ||
var filterValue = ConvertValueToString(); | ||
return $"{filterOperator}({FilterField},{filterValue})"; | ||
} | ||
} | ||
} |