예제 #1
0
        public void NotSpecificationTest(string name)
        {
            var trueSpec = new SpecificationBase <SimpleTestObject>(t => t.Name == name);

            var falseSpec = !trueSpec;

            Assert.True(trueSpec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
            Assert.False(falseSpec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));

            Assert.True(trueSpec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
            Assert.False(trueSpec.Not().IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
        }
예제 #2
0
 /// <summary>
 /// Queries the context based on the provided specification and returns results that
 /// are only satisfied by the specification.
 /// </summary>
 /// <typeparam name="TEntity">The type of the entity.</typeparam>
 /// <param name="specification">A <see cref="SpecificationBase{TEntity}"/> instance used to filter results
 /// that only satisfy the specification.</param>
 /// <returns>
 /// A <see cref="IQueryable{TEntity}"/> that can be used to enumerate over the results
 /// of the query.
 /// </returns>
 public IQueryable <TEntity> AllMatching(SpecificationBase <TEntity> specification)
 {
     return(_Context.Set <TEntity>().Where(specification.IsSatisfiedBy()));
 }
예제 #3
0
 /// <summary>
 /// Queries the context based on the provided specification and returns results that
 /// are only satisfied by the specification.
 /// </summary>
 /// <typeparam name="TEntity">The type of the entity.</typeparam>
 /// <param name="entities">The entities.</param>
 /// <param name="specification">
 /// A <see cref="SpecificationBase{TEntity}" /> instance used to filter results that only satisfy the specification.
 /// </param>
 /// <returns>A <see cref="IQueryable{TEntity}" /> that can be used to enumerate over the results
 /// of the query.</returns>
 /// <paramref name="entities" />
 public static IEnumerable <TEntity> AllMatching <TEntity>(this IEnumerable <TEntity> entities, SpecificationBase <TEntity> specification)
     where TEntity : class, IEntity
 {
     return(entities.AsQueryable().Where(specification.IsSatisfiedBy()));
 }
예제 #4
0
        public void SingleSpecificationWorked()
        {
            var spec = new SpecificationBase <SimpleTestObject>(t => t.Name == "Name");

            Assert.True(spec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
        }