public void And_WhenShowAllIsApplied_NoItemsAreFiltered()
        {
            // Arrange
            var first   = new ExpressionSpec <ItemForTest>();
            var second  = new ExpressionSpec <ItemForTest>();
            var items   = new[] { new ItemForTest("11"), new ItemForTest("22") };
            var andSpec = first.And(second);

            // Act
            var result = items.Where(x => andSpec.IsSatisfy(x)).ToArray();

            // Assert
            result
            .Should()
            .BeEquivalentTo(items.ToList());
        }
        public void Or_PassShowAllSpec_NoItemsAreFiltered()
        {
            // Arrange
            var first  = new ExpressionSpec <ItemForTest>(x => true);
            var second = new ExpressionSpec <ItemForTest>(x => x.Id.Contains("2"));
            var items  = new[] { new ItemForTest("11"), new ItemForTest("22"), new ItemForTest("33"), };
            var orSpec = first.Or(second);

            // Act
            var result = items.Where(x => orSpec.IsSatisfy(x)).ToArray();

            // Assert
            result.Should()
            .Contain(x => x.Id == "22")
            .And.HaveCount(1);
        }
        public void Not_SpecificationTest()
        {
            // Arrange
            var spec = new ExpressionSpec <ItemForTest>(x => x.Id.Contains("1"));

            var items   = new[] { new ItemForTest("11"), new ItemForTest("21"), new ItemForTest("22") };
            var notSpec = spec.Not();

            // Act
            var result = items.Where(x => notSpec.IsSatisfy(x)).ToArray();

            // Assert
            result.Should()
            .Contain(x => x.Id == "22")
            .And
            .HaveCount(1);
        }
        public void And_WhenSelectorApplicableBetweenMultipleSpecifications_ShouldCorrectlyFilterItems()
        {
            // Arrange
            var first   = new ExpressionSpec <ItemForTest>(x => x.Id.Contains("2"));
            var second  = new ExpressionSpec <SubItemForTest>(x => x != null && x.Active);
            var items   = new[] { new ItemForTest("11"), new ItemForTest("22"), new ItemForTest("22", new SubItemForTest(true)) };
            var andSpec = first.And(second, new SubItemSelector());

            // Act
            var result = items.Where(x => andSpec.IsSatisfy(x)).ToArray();

            // Assert
            result
            .Should()
            .Contain(x => x.Id == "22")
            .And
            .HaveCount(1);
        }
        public void And_WhenMultipleSpecificationsAreApplicable_ShouldCorrectlyFilterItems()
        {
            // Arrange
            var first   = new ExpressionSpec <ItemForTest>(x => x.Id.Contains("1"));
            var second  = new ExpressionSpec <ItemForTest>(x => x.Id.Contains("2"));
            var items   = new[] { new ItemForTest("11"), new ItemForTest("21"), new ItemForTest("22") };
            var andSpec = first.And(second);

            // Act
            var result = items.Where(x => andSpec.IsSatisfy(x)).ToArray();

            // Assert
            result
            .Should()
            .Contain(x => x.Id == "21")
            .And
            .HaveCount(1);
        }