Skip to content

Commit

Permalink
Fix Issue Type and add Project Type
Browse files Browse the repository at this point in the history
  • Loading branch information
albiberto committed Jan 29, 2024
1 parent 9918d7e commit b4b831e
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using FieldContestants = Constants.Fields;

[TestClass]
public class TypeTests
public class IssueTypeTests
{
const string Type = "Enanchement";
const int TypeId = 1;
Expand Down Expand Up @@ -35,7 +35,7 @@ public void Should_Cast_Type_Field()
{
const string expected = FieldContestants.Type;

var field = Fields.All.Type;
var field = Fields.All.Issue.Type;
var actual = ((Field)field.Value).Value;

Assert.AreEqual(expected, actual);
Expand All @@ -46,7 +46,7 @@ public void Should_Cast_TypeType_Field()
{
const string expected = FieldContestants.IssueType;

var field = Fields.All.Type.Issue;
var field = Fields.All.Issue.IssueType;
var actual = ((Field)field.Value).Value;

Assert.AreEqual(expected, actual);
Expand All @@ -56,24 +56,24 @@ public void Should_Cast_TypeType_Field()
public void Should_Parses_Equality_Operators()
{
var expected =
$"{FieldContestants.Type} {Operators.Equals} {Type} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.Equals} {TypeId} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.NotEquals} {Type} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.NotEquals} {TypeId} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.Equals} {Type} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.Equals} {TypeId} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.NotEquals} {Type} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.NotEquals} {TypeId}";
$"{FieldContestants.IssueType} {Operators.Equals} {Type} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.Equals} {TypeId} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.NotEquals} {Type} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.NotEquals} {TypeId} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.Equals} {Type} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.Equals} {TypeId} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.NotEquals} {Type} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.NotEquals} {TypeId}";

var actual = JqlBuilder.Query
.Where(f => f.Type == Type)
.And(f => f.Type == TypeId)
.And(f => f.Type != Type)
.And(f => f.Type != TypeId)
.And(f => Type == f.Type)
.And(f => TypeId == f.Type)
.And(f => Type != f.Type)
.And(f => TypeId != f.Type)
.Where(f => f.Issue.IssueType == Type)
.And(f => f.Issue.IssueType == TypeId)
.And(f => f.Issue.IssueType != Type)
.And(f => f.Issue.IssueType != TypeId)
.And(f => Type == f.Issue.IssueType)
.And(f => TypeId == f.Issue.IssueType)
.And(f => Type != f.Issue.IssueType)
.And(f => TypeId != f.Issue.IssueType)
.ToString();

Assert.AreEqual(expected, actual);
Expand All @@ -83,20 +83,20 @@ public void Should_Parses_Equality_Operators()
public void Should_Parses_Nullable_Operators()
{
const string expected =
$"{FieldContestants.Type} {Operators.Is} {Keywords.Empty} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.Is} {Keywords.Empty} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.Is} {Keywords.Null} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.IsNot} {Keywords.Empty} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.IsNot} {Keywords.Empty} {Keywords.And} " +
$"{FieldContestants.Type} {Operators.IsNot} {Keywords.Null}";
$"{FieldContestants.IssueType} {Operators.Is} {Keywords.Empty} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.Is} {Keywords.Empty} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.Is} {Keywords.Null} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.IsNot} {Keywords.Empty} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.IsNot} {Keywords.Empty} {Keywords.And} " +
$"{FieldContestants.IssueType} {Operators.IsNot} {Keywords.Null}";

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

Assert.AreEqual(expected, actual);
Expand All @@ -119,14 +119,14 @@ public void Should_Parses_Membership_Operators()
var heterogeneousFilter = new JqlCollection<JqlType> { TypeId, Type, TypeId };

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

Assert.AreEqual(expected, actual);
Expand All @@ -140,8 +140,8 @@ public void Should_Parses_Ordering_Fields()
$"{FieldContestants.IssueType} {Keywords.Ascending}";

var actual = JqlBuilder.Query
.OrderBy(f => f.Type)
.ThenBy(f => f.Type.Issue)
.OrderBy(f => f.Issue.Type)
.ThenBy(f => f.Issue.IssueType)
.ToString();

Assert.AreEqual(expected, actual);
Expand Down
74 changes: 74 additions & 0 deletions JQLBuilder.Tests/Types/ProjectTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
namespace JQLBuilder.Tests.Types;

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

[TestClass]
public class ProjectTypeTests
{
const string ProjectType = "software";
const string ExpectedProjectType = $@"""{ProjectType}""";

[TestMethod]
public void Should_Cast_Project_Expression_From_String()
{
var expression = (JqlProjectType)ProjectType;

Assert.AreEqual("String", expression.Value.GetType().Name);
Assert.AreEqual(ProjectType, expression.Value);
}

[TestMethod]
public void Should_Cast_Project_Field()
{
const string expected = FieldContestants.Project;

var field = Fields.All.Project;
var actual = ((Field)field.Value).Value;

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void Should_Parses_Equality_Operators()
{
var expected =
$"{FieldContestants.ProjectType} {Operators.Equals} {ExpectedProjectType} {Keywords.And} " +
$"{FieldContestants.ProjectType} {Operators.NotEquals} {ExpectedProjectType} {Keywords.And} " +
$"{FieldContestants.ProjectType} {Operators.Equals} {ExpectedProjectType} {Keywords.And} " +
$"{FieldContestants.ProjectType} {Operators.NotEquals} {ExpectedProjectType}";

var actual = JqlBuilder.Query
.Where(f => f.Project.Type == ProjectType)
.And(f => f.Project.Type != ProjectType)
.And(f => ProjectType == f.Project.Type)
.And(f => ProjectType != f.Project.Type)
.ToString();

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void Should_Parses_Membership_Operators()
{
var 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} " +
$"{FieldContestants.ProjectType} {Operators.NotIn} ({ExpectedProjectType}, {ExpectedProjectType}, {ExpectedProjectType})";

var homogeneousFilter = new JqlCollection<JqlProjectType> { ProjectType, ProjectType, ProjectType };

var actual = JqlBuilder.Query
.Where(f => f.Project.Type.In(ProjectType, ProjectType, ProjectType))
.And(f => f.Project.Type.In(homogeneousFilter))
.And(f => f.Project.Type.NotIn(ProjectType, ProjectType, ProjectType))
.And(f => f.Project.Type.NotIn(homogeneousFilter))
.ToString();

Assert.AreEqual(expected, actual);
}
}
1 change: 1 addition & 0 deletions JQLBuilder/Constants/Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal static class Fields
internal const string Votes = "votes";
internal const string Watchers = "watchers";
internal const string HierarchicalLevel = "hierarchicalLevel";
internal const string ProjectType = "projectType";

internal static string Custom(int id) => $"cf[{id}]";
}
1 change: 0 additions & 1 deletion JQLBuilder/Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class Fields
public Attachment Attachment { get; } = new();
public Category Category { get; } = new();
public Priority Priority { get; } = new();
public Type Type { get; } = new();
public Issue Issue { get; } = new();
public Status Status { get; } = new();
public User User { get; } = new();
Expand Down
2 changes: 1 addition & 1 deletion JQLBuilder/Ordering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Ordering
public OrderingProject Project { get; } = new();
public OrderingVersion Version { get; } = new();
public OrderingPriority Priority { get; } = new();
public OrderingType Type { get; } = new();
public OrderingIssueType IssueType { get; } = new();
public OrderingIssue Issue { get; } = new();
public OrderingStatus Status { get; } = new();
public OrderingUser User { get; } = new();
Expand Down
4 changes: 4 additions & 0 deletions JQLBuilder/Types/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Issue : IssueField
public IssueField Id { get; } = Field.Custom<IssueField>(Fields.Id);
public IssueField Key { get; } = Field.Custom<IssueField>(Fields.Key);
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 class OrderingIssue : IssueField
Expand All @@ -23,4 +25,6 @@ public class OrderingIssue : IssueField
public IssueField IssueKey { get; } = Field.Custom<IssueField>(Fields.IssueKey);
public IssueField Id { get; } = Field.Custom<IssueField>(Fields.Id);
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);
}
19 changes: 19 additions & 0 deletions JQLBuilder/Types/IssueType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace JQLBuilder.Types;

using Constants;
using Infrastructure;
using JqlTypes;

public class IssueType : TypeField
{
public IssueType() => Value = new Field(Fields.Type);

public TypeField Issue { get; } = Field.Custom<TypeField>(Fields.IssueType);
}

public class OrderingIssueType : TypeField
{
public OrderingIssueType() => Value = new Field(Fields.Type);

public TypeField Issue { get; } = Field.Custom<TypeField>(Fields.IssueType);
}
21 changes: 21 additions & 0 deletions JQLBuilder/Types/JqlTypes/JqlProjectType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace JQLBuilder.Types.JqlTypes;

using Abstract;
using Infrastructure;
using Infrastructure.Abstract;
using Infrastructure.Operators;

#pragma warning disable CS0660, CS0661
public class ProjectTypeField : JqlValue, IJqlField<JqlProjectType>
#pragma warning restore CS0660, CS0661
{
public static Bool operator ==(ProjectTypeField left, JqlProjectType right) => left.Equal(right);
public static Bool operator !=(ProjectTypeField left, JqlProjectType right) => left.NotEqual(right);
public static Bool operator ==(JqlProjectType left, ProjectTypeField right) => right.Equal(left);
public static Bool operator !=(JqlProjectType left, ProjectTypeField right) => right.NotEqual(left);
}

public class JqlProjectType : JqlValue, IJqlMembership<JqlProjectType>
{
public static implicit operator JqlProjectType(string value) => new() { Value = value };
}
2 changes: 2 additions & 0 deletions JQLBuilder/Types/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
public class Project : ProjectField
{
public Project() => Value = new Field(Fields.Project);

public ProjectTypeField Type { get; } = Field.Custom<ProjectTypeField>(Fields.ProjectType);
}

public class OrderingProject : ProjectField
Expand Down
19 changes: 0 additions & 19 deletions JQLBuilder/Types/Type.cs

This file was deleted.

0 comments on commit b4b831e

Please sign in to comment.