public void MultipleSpecificationsWIthNotLinqSpecificationCorrectCandidate_ReturnExpectedResultObject() { var candidate = new Event { Id = 100, Code = "Sensation Black", Name = "We interrupt this program to bring you important news", IsArchival = true }; var sut = new FavoriteItemSpecification() .Not() .And(new ActiveItemsSpecification().Not()) .And(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("NotFavoriteItemSpecification And " + "NotActiveItemsSpecification And " + "ItemBigIdSpecification", result.Trace); }
public void NotLinqSpecification_ReturnOneItem() { var sut = new FavoriteItemSpecification(); var result = _fixture.Events .Where(item => sut.IsSatisfiedBy(item)).ToList(); Assert.Single(result); Assert.Equal(1, result.First().Id); Assert.Equal("Defqon.1", result.First().Code); }
public void MultipleSpecificationsWIthNotLinqSpecification_ReturnOneItem() { var sut = new FavoriteItemSpecification() .Not() .And(new ActiveItemsSpecification().Not()) .And(new ItemBigIdSpecification()); var result = _fixture.Events .Where(item => sut.IsSatisfiedBy(item)).ToList(); Assert.Single(result); Assert.Equal(100, result.First().Id); Assert.Equal("Sensation Black", result.First().Code); }
public void MultipleSpecificationsWIthNotLinqSpecificationIncorrectCandidate_ReturnExpectedResultObject() { var candidate = new Event { Id = 1, Code = "Defqon.1", Name = "Purple Tail", IsArchival = false }; var sut = new FavoriteItemSpecification() .Not() .And(new ActiveItemsSpecification().Not()) .And(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(FavoriteItemSpecification), 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("Specification [FavoriteItemSpecification] is satisfied by candidate", result.FailedSpecifications[0].Errors[0]); Assert.Equal(typeof(ActiveItemsSpecification), result.FailedSpecifications[1].SpecificationType); Assert.Equal(0, result.FailedSpecifications[1].Parameters.Count); Assert.Equal(candidate, result.FailedSpecifications[1].Candidate); Assert.Equal(1, result.FailedSpecifications[1].Errors.Count); Assert.Equal("Item is not archival: [1]", 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("Specification [FavoriteItemSpecification] is satisfied by candidate", result.Errors[0]); Assert.Equal("Item is not archival: [1]", result.Errors[1]); Assert.Equal("Item Id is lower than 100", result.Errors[2]); Assert.False(result.OverallResult); Assert.Equal("NotFavoriteItemSpecification+Failed And " + "NotActiveItemsSpecification+Failed And " + "ItemBigIdSpecification+Failed", result.Trace); }