IValidatesTheoreticalTicketRelationships GetValidator(IComponentContext ctx)
        {
            IValidatesTheoreticalTicketRelationships impl = ctx.Resolve <CircularRelationshipValidator>();

            impl = ctx.Resolve <MultipleSecondaryRelationshipPreventingValidationDecorator>(TypedParameter.From(impl));
            return(impl);
        }
        public MultipleSecondaryRelationshipPreventingValidationDecorator(IValidatesTheoreticalTicketRelationships wrapped,
                                                                          ILog logger)
        {
            this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
            this.logger  = logger ?? throw new ArgumentNullException(nameof(logger));

            logger.Debug("Constructor completed");
        }
Esempio n. 3
0
 public ChangedTicketRelationshipsRule(IGetsTheoreticalTicketRelationships theoreticalRelationshipProvider,
                                       IValidatesTheoreticalTicketRelationships relationshipValidator,
                                       ILog logger)
 {
     this.theoreticalRelationshipProvider = theoreticalRelationshipProvider ?? throw new ArgumentNullException(nameof(theoreticalRelationshipProvider));
     this.relationshipValidator           = relationshipValidator ?? throw new ArgumentNullException(nameof(relationshipValidator));
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public void AreRelationshipsValid_does_not_consider_relationships_of_different_types_for_validation([HasIdentity] Ticket ticket,
                                                                                                            [HasIdentity] DirectionalRelationship rel1,
                                                                                                            [HasIdentity] DirectionalRelationship rel2,
                                                                                                            [Frozen] IValidatesTheoreticalTicketRelationships wrapped,
                                                                                                            MultipleSecondaryRelationshipPreventingValidationDecorator sut)
        {
            var identity = ticket.GetIdentity();

            rel1.Behaviour.ProhibitMultipleSecondaryRelationships = true;
            rel2.Behaviour.ProhibitMultipleSecondaryRelationships = true;

            var relationships = new[] {
                new TheoreticalRelationship {
                    SecondaryTicket = identity,
                    Relationship    = rel1,
                    Type            = TheoreticalRelationshipType.Existing,
                },
                new TheoreticalRelationship {
                    SecondaryTicket = identity,
                    Relationship    = rel2,
                    Type            = TheoreticalRelationshipType.Added,
                },
            };

            Mock.Get(wrapped)
            .Setup(x => x.AreRelationshipsValid(It.IsAny <IIdentity <Ticket> >(), It.IsAny <IEnumerable <TheoreticalRelationship> >()))
            .Returns(true);

            var result = sut.AreRelationshipsValid(identity, relationships);

            Assert.That(result, Is.True);
        }
        public void AreRelationshipsValid_returns_false_when_there_are_disallowed_relationships([HasIdentity] Ticket ticket,
                                                                                                [HasIdentity] DirectionalRelationship rel,
                                                                                                [Frozen] IValidatesTheoreticalTicketRelationships wrapped,
                                                                                                MultipleSecondaryRelationshipPreventingValidationDecorator sut)
        {
            var identity = ticket.GetIdentity();

            rel.Behaviour.ProhibitMultipleSecondaryRelationships = true;

            var relationships = new[] {
                new TheoreticalRelationship {
                    SecondaryTicket = identity,
                    Relationship    = rel,
                    Type            = TheoreticalRelationshipType.Existing,
                },
                new TheoreticalRelationship {
                    SecondaryTicket = identity,
                    Relationship    = rel,
                    Type            = TheoreticalRelationshipType.Added,
                },
            };

            Mock.Get(wrapped)
            .Setup(x => x.AreRelationshipsValid(It.IsAny <IIdentity <Ticket> >(), It.IsAny <IEnumerable <TheoreticalRelationship> >()))
            .Returns(true);

            var result = sut.AreRelationshipsValid(identity, relationships);

            Assert.That(result, Is.False);
        }
        public void AreRelationshipsValid_returns_result_from_wrapped_if_relationships_are_valid([HasIdentity] Ticket ticket,
                                                                                                 [Frozen] IValidatesTheoreticalTicketRelationships wrapped,
                                                                                                 MultipleSecondaryRelationshipPreventingValidationDecorator sut)
        {
            var identity = ticket.GetIdentity();

            var relationships = Enumerable.Empty <TheoreticalRelationship>();

            Mock.Get(wrapped)
            .Setup(x => x.AreRelationshipsValid(It.IsAny <IIdentity <Ticket> >(), It.IsAny <IEnumerable <TheoreticalRelationship> >()))
            .Returns(false);

            var result = sut.AreRelationshipsValid(identity, relationships);

            Assert.That(result, Is.False);
        }