Esempio n. 1
0
        public void GetMetadata_returns_metadata_which_does_not_match_a_criterion_for_predicate_equals()
        {
            // Arrange
            var criterion = Criterion.FromElementPredicateAndConstantValue("ticket", "=", "foo");
            var sut       = TicketIsOpenClosedConversionStrategy.GetMetadata();

            // Act
            var result = sut.CanConvert(criterion);

            // Assert
            Assert.That(result, Is.False);
        }
        public void ConvertToSpecification_returns_a_spec_when_converting_a_predicate_and_value([Frozen] IGetsStoryPointsComparisonSpec specFactory,
                                                                                                [Frozen] IResolvesValue resolver,
                                                                                                ISpecificationExpression <Ticket> spec,
                                                                                                StoryPointsConversionStrategy sut,
                                                                                                int value)
        {
            Mock.Get(specFactory).Setup(x => x.GetFromPredicateName(PredicateName.GreaterThan, value)).Returns(spec);
            var criterion = Criterion.FromElementPredicateAndConstantValue(ElementName.StoryPoints, PredicateName.GreaterThan, value.ToString());

            Mock.Get(resolver).Setup(x => x.Resolve <int>(((PredicateAndValue)criterion.Test).Value)).Returns(value);
            Assert.That(() => sut.ConvertToSpecification(criterion), Is.SameAs(spec));
        }
        public void GetMetadata_returns_metadata_which_matches_a_criterion_for_label_equals_a_constant()
        {
            // Arrange
            var criterion = Criterion.FromElementPredicateAndConstantValue("label", "=", "one");
            var sut       = HasLabelConversionStrategy.GetMetadata();

            // Act
            var result = sut.CanConvert(criterion);

            // Assert
            Assert.That(result, Is.True);
        }
Esempio n. 4
0
        public void GetMetadata_returns_metadata_which_matches_a_criterion_for_ticket_is_and_one_parameter()
        {
            // Arrange
            var criterion = Criterion.FromElementPredicateAndConstantValue("ticket", "is", "foo");
            var sut       = TicketIsOpenClosedConversionStrategy.GetMetadata();

            // Act
            var result = sut.CanConvert(criterion);

            // Assert
            Assert.That(result, Is.True);
        }
Esempio n. 5
0
        public void ConvertToSpecification_returns_instance_of_IsOpen_if_value_is_not_closed([Frozen] IResolvesValue resolver,
                                                                                             TicketIsOpenClosedConversionStrategy sut,
                                                                                             string inputValue)
        {
            // Arrange
            Mock.Get(resolver)
            .Setup(x => x.Resolve <string>(It.IsAny <Value>()))
            .Returns("somethingelse");
            var criterion = Criterion.FromElementPredicateAndConstantValue("ticket", "is", inputValue);

            // Act
            var result = sut.ConvertToSpecification(criterion);

            // Assert
            Assert.That(result, Is.InstanceOf <IsOpen>());
        }
Esempio n. 6
0
        IReadOnlyCollection <Ticket> GetAllTickets(string labelName, bool open)
        {
            var openClosed = open ? WellKnownValue.Open : WellKnownValue.Closed;

            var listRequest = new TicketListRequest {
                SearchModel = new Search {
                    CriteriaRoot = new CriteriaRoot {
                        Criteria = new [] {
                            Criterion.FromElementPredicateAndConstantValue(ElementName.Label, PredicateName.Equals, labelName),
                            Criterion.FromElementPredicateAndConstantValue(ElementName.Ticket, PredicateName.Is, openClosed)
                        }
                    }
                }
            };

            return(ticketLister.GetTickets(listRequest));
        }
        public void GetMetadata_indicates_it_can_convert_for_all_supported_predicate_names_and_values(StoryPointsConversionStrategy sut, int value)
        {
            var supportedPredicates = new[] {
                PredicateName.Equals,
                PredicateName.NotEquals,
                PredicateName.GreaterThan,
                PredicateName.GreaterThanOrEqual,
                PredicateName.LessThan,
                PredicateName.LessThanOrEqual,
            };

            foreach (var predicate in supportedPredicates)
            {
                var criterion = Criterion.FromElementPredicateAndConstantValue(ElementName.StoryPoints, predicate, value.ToString());
                Assert.That(() => sut.GetMetadata().CanConvertAsPredicateWithValue(criterion), Is.True, $"Can convert for predicate '{predicate}'");
            }
        }
        public void ConvertToSpecification_from_const_initialises_label_names_with_resolved_values([Frozen] IResolvesValue resolver,
                                                                                                   HasLabelConversionStrategy sut,
                                                                                                   string inputValue,
                                                                                                   string resolvedValue)
        {
            // Arrange
            Mock.Get(resolver)
            .Setup(x => x.Resolve <string>(It.IsAny <Value>()))
            .Returns(resolvedValue);
            var criterion = Criterion.FromElementPredicateAndConstantValue("label", "=", inputValue);

            // Act
            var result = sut.ConvertToSpecification(criterion);

            // Assert
            Assert.That((result as HasLabel)?.LabelNames, Is.EqualTo(new [] { resolvedValue }));
        }
        public void ConvertToSpecification_from_const_returns_instance_of_spec([Frozen] IResolvesValue resolver,
                                                                               HasLabelConversionStrategy sut,
                                                                               string inputValue,
                                                                               string resolvedValue)
        {
            // Arrange
            Mock.Get(resolver)
            .Setup(x => x.Resolve <string>(It.IsAny <Value>()))
            .Returns(resolvedValue);
            var criterion = Criterion.FromElementPredicateAndConstantValue("label", "=", inputValue);

            // Act
            var result = sut.ConvertToSpecification(criterion);

            // Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.InstanceOf <HasLabel>());
        }
        public void ConvertToSpecification_from_const_resolves_value_using_resolver([Frozen] IResolvesValue resolver,
                                                                                    HasLabelConversionStrategy sut,
                                                                                    string inputValue,
                                                                                    string resolvedValue)
        {
            // Arrange
            Mock.Get(resolver)
            .Setup(x => x.Resolve <string>(It.IsAny <Value>()))
            .Returns(resolvedValue);
            var criterion     = Criterion.FromElementPredicateAndConstantValue("label", "=", inputValue);
            var expectedParam = ConstantValue.FromConstant(inputValue);

            // Act
            sut.ConvertToSpecification(criterion);

            // Assert
            Mock.Get(resolver).Verify(x => x.Resolve <string>(expectedParam), Times.Once);
        }