Skip to content

Commit

Permalink
Add Epic Link without functions
Browse files Browse the repository at this point in the history
  • Loading branch information
albiberto committed Jan 29, 2024
1 parent b4b831e commit 1677b42
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
124 changes: 124 additions & 0 deletions JQLBuilder.Tests/Types/EpickLinkTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
namespace JQLBuilder.Tests.Types;

using Constants;
using Infrastructure;
using JQLBuilder.Types.JqlTypes;
using FieldContestants = Constants.Fields;
using Fields = Fields;
using Functions = Functions;
using FunctionsConstants = Constants.Functions;

[TestClass]
public class EpicLinkTests
{
const string EpicLink = "ABS-123";
const int EpicLinkId = 123;
const string ExpectedEpicLinkField = $@"""{FieldContestants.EpicLink}""";

[TestMethod]
public void Should_Cast_EpicLink_Expression_From_String()
{
var expression = (JqlEpicLink)EpicLink;

Assert.AreEqual("Field", expression.Value.GetType().Name);
Assert.AreEqual(new Field(EpicLink), expression.Value);
}

[TestMethod]
public void Should_Cast_EpicLink_Expression_Form_Int()
{
var expression = (JqlEpicLink)EpicLinkId;

Assert.AreEqual("Int32", expression.Value.GetType().Name);
Assert.AreEqual(EpicLinkId, expression.Value);
}

[TestMethod]
public void Should_Cast_EpicLink_Field()
{
var field = Fields.All.Issue.EpicLink;
var actual = ((Field)field.Value).Value;

Assert.AreEqual(FieldContestants.EpicLink, actual);
}

[TestMethod]
public void Should_Parses_Equality_Operators()
{
var expected =
$"{ExpectedEpicLinkField} {Operators.Equals} {EpicLink} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.Equals} {EpicLinkId} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.NotEquals} {EpicLink} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.NotEquals} {EpicLinkId} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.Equals} {EpicLink} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.Equals} {EpicLinkId} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.NotEquals} {EpicLink} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.NotEquals} {EpicLinkId}";

var actual = JqlBuilder.Query
.Where(f => f.Issue.EpicLink == EpicLink)
.And(f => f.Issue.EpicLink == EpicLinkId)
.And(f => f.Issue.EpicLink != EpicLink)
.And(f => f.Issue.EpicLink != EpicLinkId)
.And(f => EpicLink == f.Issue.EpicLink)
.And(f => EpicLinkId == f.Issue.EpicLink)
.And(f => EpicLink != f.Issue.EpicLink)
.And(f => EpicLinkId != f.Issue.EpicLink)
.ToString();

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void Should_Parses_Nullable_Operators()
{
const string expected =
$"{ExpectedEpicLinkField} {Operators.Is} {Keywords.Empty} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.Is} {Keywords.Empty} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.Is} {Keywords.Null} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.IsNot} {Keywords.Empty} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.IsNot} {Keywords.Empty} {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.IsNot} {Keywords.Null}";

var actual = JqlBuilder.Query
.Where(f => f.Issue.EpicLink.Is())
.And(f => f.Issue.EpicLink.Is(s => s.Empty))
.And(f => f.Issue.EpicLink.Is(s => s.Null))
.And(f => f.Issue.EpicLink.IsNot())
.And(f => f.Issue.EpicLink.IsNot(s => s.Empty))
.And(f => f.Issue.EpicLink.IsNot(s => s.Null))
.ToString();

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void Should_Parses_Membership_Operators()
{
var expected =
$"{ExpectedEpicLinkField} {Operators.In} ({EpicLinkId}, {EpicLinkId}, {EpicLinkId}) {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.In} ({EpicLinkId}, {EpicLinkId}, {EpicLinkId}) {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.In} ({EpicLinkId}, {EpicLink}, {EpicLinkId}) {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.In} ({EpicLinkId}, {EpicLink}, {EpicLinkId}) {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.NotIn} ({EpicLinkId}, {EpicLinkId}, {EpicLinkId}) {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.NotIn} ({EpicLinkId}, {EpicLinkId}, {EpicLinkId}) {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.NotIn} ({EpicLinkId}, {EpicLink}, {EpicLinkId}) {Keywords.And} " +
$"{ExpectedEpicLinkField} {Operators.NotIn} ({EpicLinkId}, {EpicLink}, {EpicLinkId})";

var homogeneousFilter = new JqlCollection<JqlEpicLink> { EpicLinkId, EpicLinkId, EpicLinkId };
var heterogeneousFilter = new JqlCollection<JqlEpicLink> { EpicLinkId, EpicLink, EpicLinkId };

var actual = JqlBuilder.Query
.Where(f => f.Issue.EpicLink.In(EpicLinkId, EpicLinkId, EpicLinkId))
.And(f => f.Issue.EpicLink.In(homogeneousFilter))
.And(f => f.Issue.EpicLink.In(EpicLinkId, EpicLink, EpicLinkId))
.And(f => f.Issue.EpicLink.In(heterogeneousFilter))
.And(f => f.Issue.EpicLink.NotIn(EpicLinkId, EpicLinkId, EpicLinkId))
.And(f => f.Issue.EpicLink.NotIn(homogeneousFilter))
.And(f => f.Issue.EpicLink.NotIn(EpicLinkId, EpicLink, EpicLinkId))
.And(f => f.Issue.EpicLink.NotIn(heterogeneousFilter))
.ToString();

Assert.AreEqual(expected, actual);
}
}
8 changes: 4 additions & 4 deletions JQLBuilder.Tests/Types/ProjectTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class ProjectTypeTests
{
const string ProjectType = "software";
const string ExpectedProjectType = $@"""{ProjectType}""";
[TestMethod]

[TestMethod]
public void Should_Cast_Project_Expression_From_String()
{
var expression = (JqlProjectType)ProjectType;
Expand All @@ -35,7 +35,7 @@ public void Should_Cast_Project_Field()
[TestMethod]
public void Should_Parses_Equality_Operators()
{
var expected =
const string expected =
$"{FieldContestants.ProjectType} {Operators.Equals} {ExpectedProjectType} {Keywords.And} " +
$"{FieldContestants.ProjectType} {Operators.NotEquals} {ExpectedProjectType} {Keywords.And} " +
$"{FieldContestants.ProjectType} {Operators.Equals} {ExpectedProjectType} {Keywords.And} " +
Expand All @@ -54,7 +54,7 @@ public void Should_Parses_Equality_Operators()
[TestMethod]
public void Should_Parses_Membership_Operators()
{
var expected =
const string expected =
$"{FieldContestants.ProjectType} {Operators.In} ({ExpectedProjectType}, {ExpectedProjectType}, {ExpectedProjectType}) {Keywords.And} " +
$"{FieldContestants.ProjectType} {Operators.In} ({ExpectedProjectType}, {ExpectedProjectType}, {ExpectedProjectType}) {Keywords.And} " +
$"{FieldContestants.ProjectType} {Operators.NotIn} ({ExpectedProjectType}, {ExpectedProjectType}, {ExpectedProjectType}) {Keywords.And} " +
Expand Down
1 change: 1 addition & 0 deletions JQLBuilder/Constants/Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal static class Fields
internal const string Watchers = "watchers";
internal const string HierarchicalLevel = "hierarchicalLevel";
internal const string ProjectType = "projectType";
internal const string EpicLink = "Epic Link";

internal static string Custom(int id) => $"cf[{id}]";
}
2 changes: 2 additions & 0 deletions JQLBuilder/Types/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Issue : IssueField
public ParentField Parent { get; } = Field.Custom<ParentField>(Fields.Parent);
public TypeField IssueType { get; } = Field.Custom<TypeField>(Fields.IssueType);
public TypeField Type { get; } = Field.Custom<TypeField>(Fields.Type);
public EpicLinkField EpicLink { get; } = Field.Custom<EpicLinkField>(Fields.EpicLink);
}

public class OrderingIssue : IssueField
Expand All @@ -27,4 +28,5 @@ public class OrderingIssue : IssueField
public IssueField Key { get; } = Field.Custom<IssueField>(Fields.Key);
public TypeField IssueType { get; } = Field.Custom<TypeField>(Fields.IssueType);
public TypeField Type { get; } = Field.Custom<TypeField>(Fields.Type);
public EpicLinkField EpicLink { get; } = Field.Custom<EpicLinkField>(Fields.EpicLink);
}
22 changes: 22 additions & 0 deletions JQLBuilder/Types/JqlTypes/JqlEpicLink.cs
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 EpicLinkField : JqlValue, IJqlField<JqlEpicLink>, IJqlNullable
#pragma warning restore CS0660, CS0661
{
public static Bool operator ==(EpicLinkField left, JqlEpicLink right) => left.Equal(right);
public static Bool operator !=(EpicLinkField left, JqlEpicLink right) => left.NotEqual(right);
public static Bool operator ==(JqlEpicLink left, EpicLinkField right) => right.Equal(left);
public static Bool operator !=(JqlEpicLink left, EpicLinkField right) => right.NotEqual(left);
}

public class JqlEpicLink : JqlValue, IJqlMembership<JqlEpicLink>
{
public static implicit operator JqlEpicLink(string value) => new() { Value = new Field(value) };
public static implicit operator JqlEpicLink(int value) => new() { Value = value };
}

0 comments on commit 1677b42

Please sign in to comment.