public TicketRelationship CreateTicketRelationship(IIdentity <Relationship> relationshipId, TicketReference relatedTicketReference, RelationshipParticipant participationType) { if (relationshipId == null || relatedTicketReference == null || !participationType.IsDefinedValue()) { return(null); } var relatedTicket = ticketQuery.GetTicketByReference(relatedTicketReference); if (relatedTicket == null) { return(null); } var relationship = new TicketRelationship { Relationship = data.Theorise(relationshipId), }; if (participationType == RelationshipParticipant.Primary) { relationship.SecondaryTicket = relatedTicket; } if (participationType == RelationshipParticipant.Secondary) { relationship.PrimaryTicket = relatedTicket; } return(relationship); }
IEnumerable <TicketRelationshipDto> GetRelationships(IEnumerable <TicketRelationship> relationships, RelationshipParticipant participant, IGetsRelationshipSummary summaryProvider, ResolutionContext ctx) { return(relationships .Where(x => x != null) .Select(x => GetRelationship(x, participant, summaryProvider, ctx)) .ToArray()); }
public void CreateTicketRelationship_returns_null_if_relationship_id_is_null(TicketReference ticketReference, RelationshipParticipant participationType, TicketRelationshipFactory sut) { // Act var result = sut.CreateTicketRelationship(null, ticketReference, participationType); // Assert Assert.That(result, Is.Null); }
public string GetSummary(Relationship relationship, RelationshipParticipant forParticipant) { if (relationship == null) { return(null); } var visitor = visitorFactory(forParticipant); relationship.Accept(visitor); return(visitor.GetSummary()); }
public virtual Ticket GetTicket(RelationshipParticipant participant) { participant.RequireDefinedValue(nameof(participant)); if (participant == RelationshipParticipant.Primary) { return(PrimaryTicket); } if (participant == RelationshipParticipant.Secondary) { return(SecondaryTicket); } return(null); }
public void CreateTicketRelationship_sets_up_relationship([Frozen, InMemory] IEntityData data, Relationship relationship, TicketReference ticketReference, RelationshipParticipant participationType, TicketRelationshipFactory sut) { // Arrange data.Add(relationship); // Act var result = sut.CreateTicketRelationship(relationship.GetIdentity(), ticketReference, participationType); // Assert Assert.That(result?.Relationship, Is.SameAs(relationship)); }
TicketRelationshipDto GetRelationship(TicketRelationship relationship, RelationshipParticipant participant, IGetsRelationshipSummary summaryProvider, ResolutionContext ctx) { Ticket relatedTicket; if (participant == RelationshipParticipant.Primary) { relatedTicket = relationship.SecondaryTicket; } else { relatedTicket = relationship.PrimaryTicket; } return(new TicketRelationshipDto { Id = relationship.GetIdentity(), RelationshipId = relationship.Relationship?.GetIdentity(), Summary = summaryProvider.GetSummary(relationship.Relationship, participant), Participant = participant, RelatedTicket = ctx.Mapper.Map <TicketSummaryDto>(relatedTicket), }); }
public SummaryProvidingRelationshipVisitor(RelationshipParticipant desiredRelationship) { desiredRelationship.RequireDefinedValue(nameof(desiredRelationship)); this.desiredRelationship = desiredRelationship; }
public void CreateTicketRelationship_returns_null_if_related_ticket_ref_is_null(IIdentity <Relationship> relationshipId, RelationshipParticipant participationType, TicketRelationshipFactory sut) { // Act var result = sut.CreateTicketRelationship(relationshipId, null, participationType); // Assert Assert.That(result, Is.Null); }