public void NegationMultipleSpecificationsCorrectCandidate_ReturnExpectedResultObject() { var candidate = new Event { Id = 5, Code = "Defqon.1 Australia", Name = "All aboard, this is easy for real", IsArchival = false }; var sut = new ActiveItemsSpecification() .And(new CodeStartsWithSpecification("Defqon.1")) .And(new NameContainsSpecification("easy")) .Not(); var overall = sut.IsSatisfiedBy(candidate, out var result); Assert.False(overall); Assert.Equal(3, result.TotalSpecificationsCount); Assert.Equal(0, result.FailedSpecificationsCount); Assert.Equal(0, result.FailedSpecifications.Count); Assert.Equal(0, result.Errors.Count); Assert.False(result.OverallResult); Assert.Equal("Not(ActiveItemsSpecification And " + "CodeStartsWithSpecification And " + "NameContainsSpecification)", result.Trace); }
public void MultipleAndSpecificationsIncorrectCandidate_ReturnExpectedResultObject() { var candidate = new Event { Id = 1, Code = "Defqon.1", Name = "Purple Tail", IsArchival = false }; var sut = new ActiveItemsSpecification() .And(new CodeStartsWithSpecification("Defqon.1")) .And(new NameContainsSpecification("easy")); var overall = sut.IsSatisfiedBy(candidate, out var result); Assert.False(overall); Assert.Equal(3, result.TotalSpecificationsCount); Assert.Equal(1, result.FailedSpecificationsCount); Assert.Equal(1, result.FailedSpecifications.Count); Assert.Equal(typeof(NameContainsSpecification), result.FailedSpecifications[0].SpecificationType); Assert.Equal(1, result.FailedSpecifications[0].Parameters.Count); Assert.Equal("easy", result.FailedSpecifications[0].Parameters["Filter"]); Assert.Equal(candidate, result.FailedSpecifications[0].Candidate); Assert.Equal(1, result.FailedSpecifications[0].Errors.Count); Assert.Equal("Item [Purple Tail] not contains: [easy]", result.FailedSpecifications[0].Errors[0]); Assert.Equal(1, result.Errors.Count); Assert.Equal("Item [Purple Tail] not contains: [easy]", result.Errors.First()); Assert.False(result.OverallResult); Assert.Equal("ActiveItemsSpecification And " + "CodeStartsWithSpecification And " + "NameContainsSpecification+Failed", result.Trace); }
public void MultipleAndSpecifications_ReturnOneItem() { var sut = new ActiveItemsSpecification() .And(new CodeStartsWithSpecification("Defqon.1")) .And(new NameContainsSpecification("easy")); var result = _fixture.Events .Where(item => sut.IsSatisfiedBy(item)).ToList(); Assert.Single(result); Assert.Equal(5, result.First().Id); Assert.Equal("Defqon.1 Australia", result.First().Code); }
public void NegationMultipleSpecifications_ReturnAllExceptOneItem() { var sut = new ActiveItemsSpecification() .And(new CodeStartsWithSpecification("Defqon.1")) .And(new NameContainsSpecification("easy")) .Not(); var notExpected = _fixture.Events.Single(i => i.Id == 5); var result = _fixture.Events .Where(item => sut.IsSatisfiedBy(item)).ToList(); Assert.Equal(9, result.Count); Assert.DoesNotContain(notExpected, result); }