Пример #1
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 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);
        }