-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
namespace JQLBuilder.Tests.Types; | ||
|
||
using Constants; | ||
using Infrastructure; | ||
using JQLBuilder.Types.JqlTypes; | ||
using FieldContestants = Constants.Fields; | ||
using Fields = Fields; | ||
|
||
[TestClass] | ||
public class FilterTests | ||
{ | ||
const string Filter = "ABS"; | ||
const int FilterId = 123; | ||
|
||
[TestMethod] | ||
public void Should_Cast_Filter_Expression_From_String() | ||
{ | ||
var expression = (JqlFilter)Filter; | ||
|
||
Assert.AreEqual("Field", expression.Value.GetType().Name); | ||
Assert.AreEqual(new Field(Filter), expression.Value); | ||
} | ||
|
||
[TestMethod] | ||
public void Should_Cast_Filter_Expression_Form_Int() | ||
{ | ||
var expression = (JqlFilter)FilterId; | ||
|
||
Assert.AreEqual("Int32", expression.Value.GetType().Name); | ||
Assert.AreEqual(FilterId, expression.Value); | ||
} | ||
|
||
[TestMethod] | ||
public void Should_Cast_Filter_Field() | ||
{ | ||
const string expected = FieldContestants.Filter; | ||
|
||
var field = Fields.All.Filter; | ||
var actual = ((Field)field.Value).Value; | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[TestMethod] | ||
public void Should_Cast_SearchRequest_Field() | ||
{ | ||
const string expected = FieldContestants.SearchRequest; | ||
|
||
var field = Fields.All.Filter.SearchRequest; | ||
var actual = ((Field)field.Value).Value; | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[TestMethod] | ||
public void Should_Cast_SavedFilter_Field() | ||
{ | ||
const string expected = FieldContestants.SavedFilter; | ||
|
||
var field = Fields.All.Filter.SavedFilter; | ||
var actual = ((Field)field.Value).Value; | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[TestMethod] | ||
public void Should_Cast_Request_Field() | ||
{ | ||
const string expected = FieldContestants.Request; | ||
|
||
var field = Fields.All.Filter.Request; | ||
var actual = ((Field)field.Value).Value; | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[TestMethod] | ||
public void Should_Parses_Equality_Operators() | ||
{ | ||
var expected = | ||
$"{FieldContestants.Filter} {Operators.Equals} {Filter} {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.Equals} {FilterId} {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.NotEquals} {Filter} {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.NotEquals} {FilterId} {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.Equals} {Filter} {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.Equals} {FilterId} {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.NotEquals} {Filter} {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.NotEquals} {FilterId}"; | ||
|
||
var actual = JqlBuilder.Query | ||
.Where(f => f.Filter == Filter) | ||
.And(f => f.Filter == FilterId) | ||
.And(f => f.Filter != Filter) | ||
.And(f => f.Filter != FilterId) | ||
.And(f => Filter == f.Filter) | ||
.And(f => FilterId == f.Filter) | ||
.And(f => Filter != f.Filter) | ||
.And(f => FilterId != f.Filter) | ||
.ToString(); | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[TestMethod] | ||
public void Should_Parses_Membership_Operators() | ||
{ | ||
var expected = | ||
$"{FieldContestants.Filter} {Operators.In} ({FilterId}, {FilterId}, {FilterId}) {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.In} ({FilterId}, {FilterId}, {FilterId}) {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.In} ({FilterId}, {Filter}, {FilterId}) {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.In} ({FilterId}, {Filter}, {FilterId}) {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.NotIn} ({FilterId}, {FilterId}, {FilterId}) {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.NotIn} ({FilterId}, {FilterId}, {FilterId}) {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.NotIn} ({FilterId}, {Filter}, {FilterId}) {Keywords.And} " + | ||
$"{FieldContestants.Filter} {Operators.NotIn} ({FilterId}, {Filter}, {FilterId})"; | ||
|
||
var homogeneousFilter = new JqlCollection<JqlFilter> { FilterId, FilterId, FilterId }; | ||
var heterogeneousFilter = new JqlCollection<JqlFilter> { FilterId, Filter, FilterId }; | ||
|
||
var actual = JqlBuilder.Query | ||
.Where(f => f.Filter.In(FilterId, FilterId, FilterId)) | ||
.And(f => f.Filter.In(homogeneousFilter)) | ||
.And(f => f.Filter.In(FilterId, Filter, FilterId)) | ||
.And(f => f.Filter.In(heterogeneousFilter)) | ||
.And(f => f.Filter.NotIn(FilterId, FilterId, FilterId)) | ||
.And(f => f.Filter.NotIn(homogeneousFilter)) | ||
.And(f => f.Filter.NotIn(FilterId, Filter, FilterId)) | ||
.And(f => f.Filter.NotIn(heterogeneousFilter)) | ||
.ToString(); | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
} |
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,14 @@ | ||
namespace JQLBuilder.Types; | ||
|
||
using Constants; | ||
using Infrastructure; | ||
using JqlTypes; | ||
|
||
public class Filter : FilterField | ||
{ | ||
public Filter() => Value = new Field(Fields.Filter); | ||
|
||
public FilterField SearchRequest { get; } = Field.Custom<FilterField>(Fields.SearchRequest); | ||
public FilterField Request { get; } = Field.Custom<FilterField>(Fields.Request); | ||
public FilterField SavedFilter { get; } = Field.Custom<FilterField>(Fields.SavedFilter); | ||
} |
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,22 @@ | ||
namespace JQLBuilder.Types.JqlTypes; | ||
|
||
using Abstract; | ||
using Infrastructure; | ||
using Infrastructure.Abstract; | ||
using Infrastructure.Operators; | ||
|
||
#pragma warning disable CS0660, CS0661 | ||
public class FilterField : JqlValue, IJqlField<JqlFilter> | ||
#pragma warning restore CS0660, CS0661 | ||
{ | ||
public static Bool operator ==(FilterField left, JqlFilter right) => left.Equal(right); | ||
public static Bool operator !=(FilterField left, JqlFilter right) => left.NotEqual(right); | ||
public static Bool operator ==(JqlFilter left, FilterField right) => right.Equal(left); | ||
public static Bool operator !=(JqlFilter left, FilterField right) => right.NotEqual(left); | ||
} | ||
|
||
public class JqlFilter : JqlValue, IJqlMembership<JqlFilter> | ||
{ | ||
public static implicit operator JqlFilter(string value) => new() { Value = new Field(value) }; | ||
public static implicit operator JqlFilter(int value) => new() { Value = value }; | ||
} |