本文整理汇总了C#中DirectSpecification类的典型用法代码示例。如果您正苦于以下问题:C# DirectSpecification类的具体用法?C# DirectSpecification怎么用?C# DirectSpecification使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectSpecification类属于命名空间,在下文中一共展示了DirectSpecification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ByAddress
public static ISpecification<Place> ByAddress(Address address)
{
Specification<Place> specification = new TrueSpecification<Place>();
if (address != null)
{
var stspec = new DirectSpecification<Place>(
p => p.Address.Street.ToLower().Contains(
address.Street.ToLower()
)
);
var dtspec = new DirectSpecification<Place>(
p => p.Address.District.ToLower().Contains(
address.District.ToLower()
)
);
var zpspec = new DirectSpecification<Place>(
p => p.Address.ZipCode == address.ZipCode
);
specification &= stspec || dtspec || zpspec;
}
return specification;
}
示例2: CreateAndSpecificationTest
public void CreateAndSpecificationTest()
{
//Arrange
DirectSpecification<SampleEntity> leftAdHocSpecification;
DirectSpecification<SampleEntity> rightAdHocSpecification;
var identifier = Guid.NewGuid();
Expression<Func<SampleEntity, bool>> leftSpec = s => s.Id == identifier;
Expression<Func<SampleEntity, bool>> rightSpec = s => s.SampleProperty.Length > 2;
leftAdHocSpecification = new DirectSpecification<SampleEntity>(leftSpec);
rightAdHocSpecification = new DirectSpecification<SampleEntity>(rightSpec);
//Act
AndSpecification<SampleEntity> composite = new AndSpecification<SampleEntity>(leftAdHocSpecification, rightAdHocSpecification);
//Assert
Assert.IsNotNull(composite.SatisfiedBy());
Assert.ReferenceEquals(leftAdHocSpecification, composite.LeftSideSpecification);
Assert.ReferenceEquals(rightAdHocSpecification, composite.RightSideSpecification);
var list = new List<SampleEntity>();
var sampleA = new SampleEntity() { SampleProperty = "1" };
sampleA.ChangeCurrentIdentity(identifier);
var sampleB = new SampleEntity() { SampleProperty = "the sample property" };
sampleB.ChangeCurrentIdentity(identifier);
list.AddRange(new SampleEntity[] { sampleA, sampleB });
var result = list.AsQueryable().Where(composite.SatisfiedBy()).ToList();
Assert.IsTrue(result.Count == 1);
}
示例3: CreateNotSpecificationFromNegationOperator
public void CreateNotSpecificationFromNegationOperator()
{
var spec = new DirectSpecification<SampleEntity>(s=>s.Name==EntityName);
ISpecification<SampleEntity> notSpec = !spec;
Assert.IsNotNull(notSpec);
}
示例4: MyAdList
public ActionResult MyAdList()
{
int userId= WebSecurity.GetUserId(User.Identity.Name);
ISpecification<Advertisement> myAdSpec = new DirectSpecification<Advertisement>(ad => ad.OwnerID == userId );
var lst = productRepository.GetAdvertisementsList(myAdSpec);
ViewBag.IsEditable = true;
return View("AdList",lst);
}
示例5: DirectSpecification_Constructor_NullSpecThrowArgumentNullException_Test
public void DirectSpecification_Constructor_NullSpecThrowArgumentNullException_Test()
{
//Arrange
DirectSpecification<TEntity> adHocSpecification;
Expression<Func<TEntity, bool>> spec = null;
//Act
adHocSpecification = new DirectSpecification<TEntity>(spec);
}
示例6: CreateDirectSpecificationNullSpecThrowArgumentNullExceptionTest
public void CreateDirectSpecificationNullSpecThrowArgumentNullExceptionTest()
{
//Arrange
DirectSpecification<SampleEntity> adHocSpecification;
Expression<Func<SampleEntity, bool>> spec = null;
//Act
adHocSpecification = new DirectSpecification<SampleEntity>(spec);
}
示例7: ConsultaCategoriaProduto
public static Specification<CategoriaProduto> ConsultaCategoriaProduto(string texto)
{
Specification<CategoriaProduto> spec = new DirectSpecification<CategoriaProduto>(c => true);
if (!string.IsNullOrEmpty(texto))
{
spec = new DirectSpecification<CategoriaProduto>(c => c.Nome.Contains(texto));
}
return spec;
}
示例8: ConsultaEmail
public static Specification<Usuario> ConsultaEmail(string email)
{
if (email != null)
{
email = email.Trim();
}
Specification<Usuario> spec = new DirectSpecification<Usuario>(c => true);
return spec;
}
示例9: ConsultaTexto
public static Specification<Usuario> ConsultaTexto(string texto)
{
Specification<Usuario> spec = new DirectSpecification<Usuario>(c => true);
if (!string.IsNullOrWhiteSpace(texto))
{
spec &= new DirectSpecification<Usuario>(c => c.NomeUsuario.ToUpper().Contains(texto.ToUpper()));
}
return spec;
}
示例10: CriaAndSpecificationComLambdaRightNullEThrowArgumentNullExceptionTest
public void CriaAndSpecificationComLambdaRightNullEThrowArgumentNullExceptionTest()
{
//Arrange
CompositeSpecification<ClienteStub> compoSpecification;
Expression<Func<ClienteStub, bool>> lambda = s => s.Nome != string.Empty;
DirectSpecification<ClienteStub> direct = new DirectSpecification<ClienteStub>(lambda);
//Act
compoSpecification = new AndSpecification<ClienteStub>(direct, null);
}
示例11: OrderFromDateRange
/// <summary>
/// The orders in a date range
/// </summary>
/// <param name="startDate">The start date </param>
/// <param name="endDate">The end date</param>
/// <returns>Related specification for this criteria</returns>
public static ISpecification<Order> OrderFromDateRange(DateTime? startDate, DateTime? endDate)
{
Specification<Order> spec = new TrueSpecification<Order>();
if (startDate.HasValue)
spec &= new DirectSpecification<Order>(o => o.OrderDate > (startDate ?? DateTime.MinValue));
if (endDate.HasValue)
spec &= new DirectSpecification<Order>(o => o.OrderDate < (endDate ?? DateTime.MaxValue));
return spec;
}
示例12: CreateNewDirectSpecificationTest
public void CreateNewDirectSpecificationTest()
{
//Arrange
DirectSpecification<SampleEntity> adHocSpecification;
Expression<Func<SampleEntity, bool>> spec = s => s.Id == Guid.NewGuid();
//Act
adHocSpecification = new DirectSpecification<SampleEntity>(spec);
//Assert
Assert.ReferenceEquals(new PrivateObject(adHocSpecification).GetField("_MatchingCriteria"), spec);
}
示例13: DirectSpecification_Constructor_Test
public void DirectSpecification_Constructor_Test()
{
//Arrange
DirectSpecification<TEntity> adHocSpecification;
Expression<Func<TEntity,bool>> spec = s => s.Id==0;
//Act
adHocSpecification = new DirectSpecification<TEntity>(spec);
//Assert
Assert.ReferenceEquals(new PrivateObject(adHocSpecification).GetField("_MatchingCriteria"), spec);
}
示例14: BankAccountIbanNumber
/// <summary>
/// Specification for bank accounts with number like to <paramref name="ibanNumber" />
/// </summary>
/// <param name="ibanNumber">The bank account number</param>
/// <returns>Associated specification</returns>
public static ISpecification<BankAccount> BankAccountIbanNumber(string ibanNumber)
{
Specification<BankAccount> specification = new TrueSpecification<BankAccount>();
if (!String.IsNullOrWhiteSpace(ibanNumber))
{
specification &= new DirectSpecification<BankAccount>(
(b) => b.Iban.ToLower().Contains(ibanNumber.ToLower()));
}
return specification;
}
示例15: Sepcification_OfType_Test
public void Sepcification_OfType_Test()
{
//初始化
var baseSpec = new DirectSpecification<BaseEntity>(be => be.Id == 1);
//操作
var inheritSpec = baseSpec.OfType<InheritEntity>();
//验证
Assert.IsNotNull(inheritSpec);
Assert.IsTrue(inheritSpec.SatisfiedBy().Compile()(new InheritEntity() { Id = 1 }));
}