public void MultipleSpecificationsWithGroupNegationCorrectCandidate_ReturnExpectedResultObject()
        {
            var candidate = new Event {
                Id = 4, Code = "In Qontrol", Name = "The Last City On Earth", IsArchival = true
            };
            var notActiveItems = new ActiveItemsSpecification()
                                 .Not();
            var codeSpecifications = new CodeStartsWithSpecification("Qountdown")
                                     .Or(new CodeStartsWithSpecification("Hard"))
                                     .Or(new CodeStartsWithSpecification("Defqon.1"));
            var sut = notActiveItems
                      .And(codeSpecifications.Not())
                      .And(new NameContainsSpecification("City On Earth"));

            var overall = sut.IsSatisfiedBy(candidate, out var result);

            Assert.True(overall);
            Assert.Equal(5, result.TotalSpecificationsCount);
            Assert.Equal(0, result.FailedSpecificationsCount);
            Assert.Equal(0, result.FailedSpecifications.Count);
            Assert.Equal(0, result.Errors.Count);
            Assert.True(result.OverallResult);
            Assert.Equal("NotActiveItemsSpecification And " +
                         "Not(CodeStartsWithSpecification+Failed Or " +
                         "CodeStartsWithSpecification+Failed Or " +
                         "CodeStartsWithSpecification+Failed) And " +
                         "NameContainsSpecification", result.Trace);
        }
コード例 #2
0
        public void MultipleSpecificationsWithGroupNegation_ReturnOneItem()
        {
            var notActiveItems = new ActiveItemsSpecification()
                                 .Not();
            var codeSpecifications = new CodeStartsWithSpecification("Qountdown")
                                     .Or(new CodeStartsWithSpecification("Hard"))
                                     .Or(new CodeStartsWithSpecification("Defqon.1"));
            var specification = notActiveItems
                                .And(codeSpecifications.Not())
                                .And(new NameContainsSpecification("City On Earth"));
            var sut = specification.GetExpression();

            var result = Context.Events.Where(sut).ToList();

            Assert.Single(result);
            Assert.Equal(4, result.First().Id);
            Assert.Equal("In Qontrol", result.First().Code);
        }
        public void MultipleSpecificationsWithGroupNegationIncorrectCandidate_ReturnExpectedResultObject()
        {
            var candidate = new Event {
                Id = 1, Code = "Defqon.1", Name = "Purple Tail", IsArchival = false
            };
            var notActiveItems = new ActiveItemsSpecification()
                                 .Not();
            var codeSpecifications = new CodeStartsWithSpecification("Qountdown")
                                     .Or(new CodeStartsWithSpecification("Hard"))
                                     .Or(new CodeStartsWithSpecification("Defqon.1"));
            var sut = notActiveItems
                      .And(codeSpecifications.Not())
                      .And(new NameContainsSpecification("City On Earth"));

            var overall = sut.IsSatisfiedBy(candidate, out var result);

            Assert.False(overall);
            Assert.Equal(5, result.TotalSpecificationsCount);
            Assert.Equal(2, result.FailedSpecificationsCount);
            Assert.Equal(2, result.FailedSpecifications.Count);
            Assert.Equal(typeof(ActiveItemsSpecification), result.FailedSpecifications[0].SpecificationType);
            Assert.Equal(0, result.FailedSpecifications[0].Parameters.Count);
            Assert.Equal(candidate, result.FailedSpecifications[0].Candidate);
            Assert.Equal(1, result.FailedSpecifications[0].Errors.Count);
            Assert.Equal("Item is not archival: [1]", result.FailedSpecifications[0].Errors[0]);
            Assert.Equal(typeof(NameContainsSpecification), result.FailedSpecifications[1].SpecificationType);
            Assert.Equal(1, result.FailedSpecifications[1].Parameters.Count);
            Assert.Equal("City On Earth", result.FailedSpecifications[1].Parameters["Filter"]);
            Assert.Equal(candidate, result.FailedSpecifications[1].Candidate);
            Assert.Equal(1, result.FailedSpecifications[1].Errors.Count);
            Assert.Equal("Item [Purple Tail] not contains: [City On Earth]", result.FailedSpecifications[1].Errors[0]);
            Assert.Equal(2, result.Errors.Count);
            Assert.Equal("Item is not archival: [1]", result.Errors[0]);
            Assert.Equal("Item [Purple Tail] not contains: [City On Earth]", result.Errors[1]);
            Assert.False(result.OverallResult);
            Assert.Equal("NotActiveItemsSpecification+Failed And " +
                         "Not(CodeStartsWithSpecification+Failed Or " +
                         "CodeStartsWithSpecification+Failed Or " +
                         "CodeStartsWithSpecification) And " +
                         "NameContainsSpecification+Failed", result.Trace);
        }