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);
        }
        public void NegationMultipleSpecificationsWithGroupIncorrectCandidate_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)
                      .And(new NameContainsSpecification("some grace"))
                      .Not();

            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("Not(NotActiveItemsSpecification+Failed And " +
                         "(CodeStartsWithSpecification+Failed Or " +
                         "CodeStartsWithSpecification+Failed Or " +
                         "CodeStartsWithSpecification) And " +
                         "NameContainsSpecification+Failed)", result.Trace);
        }
        public void MultipleOrSpecifications_ReturnTwoItems()
        {
            var specification = new CodeStartsWithSpecification("Qlimax")
                                .Or(new CodeStartsWithSpecification("Nothing"))
                                .Or(new ItemBigIdSpecification());
            var sut = specification.GetExpression();

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

            Assert.Equal(2, result.Count);
            Assert.Equal(2, result.First().Id);
            Assert.Equal("Qlimax", result.First().Code);
            Assert.Equal(100, result.Last().Id);
            Assert.Equal("Sensation Black", result.Last().Code);
        }
Exemplo n.º 4
0
        public void MultipleOrSpecifications_ReturnTwoItems()
        {
            var sut = new CodeStartsWithSpecification("Qlimax")
                      .Or(new CodeStartsWithSpecification("Nothing"))
                      .Or(new ItemBigIdSpecification());

            var result = _fixture.Events
                         .Where(item => sut.IsSatisfiedBy(item)).ToList();

            Assert.Equal(2, result.Count);
            Assert.Equal(2, result.First().Id);
            Assert.Equal("Qlimax", result.First().Code);
            Assert.Equal(100, result.Last().Id);
            Assert.Equal("Sensation Black", result.Last().Code);
        }
        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);
        }
Exemplo n.º 6
0
        public void MultipleSpecificationsWithGroup_ReturnOneItem()
        {
            var notActiveItems = new ActiveItemsSpecification()
                                 .Not();
            var codeSpecifications = new CodeStartsWithSpecification("Qountdown")
                                     .Or(new CodeStartsWithSpecification("Hard"))
                                     .Or(new CodeStartsWithSpecification("Defqon.1"));
            var sut = notActiveItems
                      .And(codeSpecifications)
                      .And(new NameContainsSpecification("some grace"));

            var result = _fixture.Events
                         .Where(item => sut.IsSatisfiedBy(item)).ToList();

            Assert.Single(result);
            Assert.Equal(9, result.First().Id);
            Assert.Equal("Qountdown", result.First().Code);
        }
        public void NegationMultipleSpecificationsWithGroup_ReturnAllExceptOneItem()
        {
            var notActiveItems = new ActiveItemsSpecification()
                                 .Not();
            var codeSpecifications = new CodeStartsWithSpecification("Qountdown")
                                     .Or(new CodeStartsWithSpecification("Hard"))
                                     .Or(new CodeStartsWithSpecification("Defqon.1"));
            var specification = notActiveItems
                                .And(codeSpecifications)
                                .And(new NameContainsSpecification("some grace"))
                                .Not();
            var sut = specification.GetExpression();

            var notExpected = Context.Events.Single(i => i.Id == 9);
            var result      = Context.Events.Where(sut).ToList();

            Assert.Equal(9, result.Count);
            Assert.DoesNotContain(notExpected, result);
        }
        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);
        }
        public void MultipleOrSpecificationsIncorrectCandidate_ReturnExpectedResultObject()
        {
            var candidate = new Event {
                Id = 1, Code = "Defqon.1", Name = "Purple Tail", IsArchival = false
            };
            var sut = new CodeStartsWithSpecification("Qlimax")
                      .Or(new CodeStartsWithSpecification("Nothing"))
                      .Or(new ItemBigIdSpecification());

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

            Assert.False(overall);
            Assert.Equal(3, result.TotalSpecificationsCount);
            Assert.Equal(3, result.FailedSpecificationsCount);
            Assert.Equal(3, result.FailedSpecifications.Count);
            Assert.Equal(typeof(CodeStartsWithSpecification), result.FailedSpecifications[0].SpecificationType);
            Assert.Equal(1, result.FailedSpecifications[0].Parameters.Count);
            Assert.Equal("Qlimax", result.FailedSpecifications[0].Parameters["Code"]);
            Assert.Equal(candidate, result.FailedSpecifications[0].Candidate);
            Assert.Equal(1, result.FailedSpecifications[0].Errors.Count);
            Assert.Equal("Item code [Defqon.1] is not starts by [Qlimax]", result.FailedSpecifications[0].Errors[0]);
            Assert.Equal(typeof(CodeStartsWithSpecification), result.FailedSpecifications[1].SpecificationType);
            Assert.Equal(1, result.FailedSpecifications[1].Parameters.Count);
            Assert.Equal("Nothing", result.FailedSpecifications[1].Parameters["Code"]);
            Assert.Equal(candidate, result.FailedSpecifications[1].Candidate);
            Assert.Equal(1, result.FailedSpecifications[1].Errors.Count);
            Assert.Equal("Item code [Defqon.1] is not starts by [Nothing]", result.FailedSpecifications[1].Errors[0]);
            Assert.Equal(typeof(ItemBigIdSpecification), result.FailedSpecifications[2].SpecificationType);
            Assert.Equal(0, result.FailedSpecifications[2].Parameters.Count);
            Assert.Equal(candidate, result.FailedSpecifications[2].Candidate);
            Assert.Equal(1, result.FailedSpecifications[2].Errors.Count);
            Assert.Equal("Item Id is lower than 100", result.FailedSpecifications[2].Errors[0]);
            Assert.Equal(3, result.Errors.Count);
            Assert.Equal("Item code [Defqon.1] is not starts by [Qlimax]", result.Errors[0]);
            Assert.Equal("Item code [Defqon.1] is not starts by [Nothing]", result.Errors[1]);
            Assert.Equal("Item Id is lower than 100", result.Errors[2]);
            Assert.False(result.OverallResult);
            Assert.Equal("CodeStartsWithSpecification+Failed Or " +
                         "CodeStartsWithSpecification+Failed Or " +
                         "ItemBigIdSpecification+Failed", result.Trace);
        }
        public void MultipleOrSpecificationsCorrectCandidate_ReturnExpectedResultObject()
        {
            var candidate = new Event {
                Id = 2, Code = "Qlimax", Name = "The Power Of The Mind", IsArchival = false
            };
            var sut = new CodeStartsWithSpecification("Qlimax")
                      .Or(new CodeStartsWithSpecification("Nothing"))
                      .Or(new ItemBigIdSpecification());

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

            Assert.True(overall);
            Assert.Equal(3, 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("CodeStartsWithSpecification Or " +
                         "CodeStartsWithSpecification+Failed Or " +
                         "ItemBigIdSpecification+Failed", result.Trace);
        }