public IEnumerable<Product> GetPopularKeyboards() { var keyboard = new GenericSpecification<Product>(product=>product.Category==ProductCategory.KeyBoard); var popular = new GenericSpecification<Product>(p=>p.AverageRatings>4); var popularKeyboard = popular.And(keyboard); return _repository.Get(popularKeyboard); }
public void And_CreatesAndSpecification() { // Arrange var spec = new GenericSpecification(false); var anotherSpec = new GenericSpecification(true); // Act var actualSpec = spec.And(anotherSpec); // Assert Assert.That(actualSpec, Is.TypeOf <AndSpecification <TestingInfrastructure.DomainModeling.TestModels.TestAggregateRoot, long> >()); }
public void And_specification_is_satisfied_when_both_expressions_are_true_for_candidate_obect() { var candidateObject = new TestClass() { DepartmentName = "Sales", Salary = 5000 }; var salarySpecification = new GenericSpecification<TestClass>(t => t.Salary > 4000); var departmentSpecification = new GenericSpecification<TestClass>(t=>t.DepartmentName=="Sales"); var andSpecification = salarySpecification.And(departmentSpecification); var isSatisfied = andSpecification.IsSatisfiedBy(candidateObject); Assert.IsTrue(isSatisfied); }