public static Specification <EFCustomer> GetCustomerByFilter(CustomerQueryCriteria criteria) { Specification <EFCustomer> specProfile = new TrueSpecification <EFCustomer>(); if (!string.IsNullOrEmpty(criteria.UserName)) { specProfile &= new DirectSpecification <EFCustomer>( p => p.UserName.Contains(criteria.UserName)); } if (!string.IsNullOrEmpty(criteria.StreetName)) { specProfile &= new DirectSpecification <EFCustomer>( p => p.Address.Street.Contains(criteria.StreetName)); } if (!string.IsNullOrEmpty(criteria.Email)) { specProfile &= new DirectSpecification <EFCustomer>( p => p.Email.Contains(criteria.Email)); } if (!string.IsNullOrEmpty(criteria.Phone)) { specProfile &= new DirectSpecification <EFCustomer>( p => p.Email == criteria.Phone); } return(specProfile); }
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); }
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; }
public void Specification_OrOperator_Test() { //Arrange DirectSpecification <TEntity> leftAdHocSpecification; DirectSpecification <TEntity> rightAdHocSpecification; Expression <Func <TEntity, bool> > leftSpec = s => s.Id == 0; Expression <Func <TEntity, bool> > rightSpec = s => s.SampleProperty.Length > 2; Expression <Func <TEntity, bool> > expected = null; Expression <Func <TEntity, bool> > actual = null; //Act leftAdHocSpecification = new DirectSpecification <TEntity>(leftSpec); rightAdHocSpecification = new DirectSpecification <TEntity>(rightSpec); ISpecification <TEntity> orSpec = leftAdHocSpecification | rightAdHocSpecification; orSpec = leftAdHocSpecification || rightAdHocSpecification; //Assert InvocationExpression invokedExpr = Expression.Invoke(rightSpec, leftSpec.Parameters.Cast <Expression>()); expected = Expression.Lambda <Func <TEntity, bool> >(Expression.Or(leftSpec.Body, invokedExpr), leftSpec.Parameters); actual = orSpec.SatisfiedBy(); }
public void CreateAndSpecificationTest() { //Arrange var identifier = Guid.NewGuid(); var leftAdHocSpecification = new DirectSpecification <SampleEntity>(s => s.Id == identifier); var rightAdHocSpecification = new DirectSpecification <SampleEntity>(s => s.SampleProperty.Length > 2); //Act var composite = new AndSpecification <SampleEntity>(leftAdHocSpecification, rightAdHocSpecification); //Assert Assert.NotNull(composite.SatisfiedBy()); Assert.Equal(leftAdHocSpecification, composite.LeftSideSpecification); Assert.Equal(rightAdHocSpecification, composite.RightSideSpecification); var list = new List <SampleEntity>(); var sampleA = new SampleEntity(identifier) { SampleProperty = "1" }; var sampleB = new SampleEntity(identifier) { SampleProperty = "the sample property" }; list.AddRange(new[] { sampleA, sampleB }); var result = list.AsQueryable().Where(composite.SatisfiedBy()).ToList(); Assert.True(result.Count == 1); }
public static Specification <Usuario> ConsultaNomeUsuario(string nomeUsuario) { nomeUsuario = nomeUsuario.Trim(); Specification <Usuario> spec = new DirectSpecification <Usuario>(c => c.NomeUsuario.ToLower() == nomeUsuario.ToLower()); return(spec); }
public static Specification <Apropriacao> DataPeriodoTituloReceberMenorOuIgualPendentesRelApropriacaoPorClasse(string tipoPesquisa, DateTime?data) { Specification <Apropriacao> specification = new TrueSpecification <Apropriacao>(); DateTime dataUltimaHora = new DateTime(data.Value.Year, data.Value.Month, data.Value.Day, 23, 59, 59); if (tipoPesquisa.ToUpper() == "E") { if (data.HasValue) { var directSpecification = new DirectSpecification <Apropriacao>(l => l.TituloReceber.DataEmissaoDocumento <= dataUltimaHora); specification &= directSpecification; } } else { if (data.HasValue) { var directSpecification = new DirectSpecification <Apropriacao>(l => l.TituloReceber.DataVencimento <= dataUltimaHora); specification &= directSpecification; } } return(specification); }
/// <summary> /// <see cref=" Microsoft.Samples.NLayerApp.Domain.Core.Specification.Specification{TEntity}"/> /// </summary> /// <returns><see cref=" Microsoft.Samples.NLayerApp.Domain.Core.Specification.Specification{TEntity}"/></returns> public override System.Linq.Expressions.Expression <Func <Order, bool> > SatisfiedBy() { Specification <Order> beginSpec = new TrueSpecification <Order>(); if (_ShippingName != null) { beginSpec &= new DirectSpecification <Order>(o => o.ShippingName != null && o.ShippingName.Contains(_ShippingName)); } if (_ShippingAddress != null) { beginSpec &= new DirectSpecification <Order>(o => o.ShippingAddress != null && o.ShippingAddress.Contains(_ShippingAddress)); } if (_ShippingCity != null) { beginSpec &= new DirectSpecification <Order>(o => o.ShippingCity != null && o.ShippingCity.Contains(_ShippingCity)); } if (_ShippingZip != null) { beginSpec &= new DirectSpecification <Order>(o => o.ShippingZip != null && o.ShippingZip.Contains(_ShippingZip)); } return(beginSpec.SatisfiedBy()); }
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); }
public override System.Linq.Expressions.Expression <Func <Asegurado, bool> > SatisfiedBy() { Specification <Asegurado> spec = new TrueSpecification <Asegurado>(); if (!string.IsNullOrEmpty(_RFC)) { spec &= new DirectSpecification <Asegurado>(c => c.RFC.Contains(_RFC)); } if (!string.IsNullOrEmpty(_RazonSocial)) { spec &= new DirectSpecification <Asegurado>(c => c.RazonSocial.Contains(_RazonSocial)); } if (!string.IsNullOrEmpty(_Nombre)) { spec &= new DirectSpecification <Asegurado>(c => c.Nombres.Contains(_Nombre)); } if (!string.IsNullOrEmpty(_Apellido1)) { spec &= new DirectSpecification <Asegurado>(c => c.Apellido1.Contains(_Apellido1)); } if (!string.IsNullOrEmpty(_Apellido2)) { spec &= new DirectSpecification <Asegurado>(c => c.Apellido2.Contains(_Apellido2)); } return(spec.SatisfiedBy()); }
public override global::System.Linq.Expressions.Expression <Func <AdminLog, bool> > SatisfiedBy() { Specification <AdminLog> spec = new TrueSpecification <AdminLog>(); if (!string.IsNullOrEmpty(_optContent) && !string.IsNullOrEmpty(_optContent.Trim())) { spec &= new DirectSpecification <AdminLog>(o => o.OptContent.Contains(_optContent)); } if (!string.IsNullOrEmpty(_userName) && !string.IsNullOrEmpty(_userName.Trim())) { spec &= new DirectSpecification <AdminLog>(o => o.UserName == _userName); } if (_fromOptTime.HasValue) { spec &= new DirectSpecification <AdminLog>(o => o.OptTime >= (_fromOptTime ?? DateTime.MinValue)); } if (_toOptTime.HasValue) { spec &= new DirectSpecification <AdminLog>(o => o.OptTime <= (_toOptTime ?? DateTime.MaxValue)); } return(spec.SatisfiedBy()); }
IEnumerable <SellRecord> ISellRecordMgr.GetByDomain(string domain) { var result = new List <SellRecord>(); ISpecification <SellRecord> spec = null; switch (domain) { case "day": spec = new DirectSpecification <SellRecord>(p => (DateTime.Now.Day - p.SellDate.Day) < 1); break; case "month": spec = new DirectSpecification <SellRecord>(p => (DateTime.Now.Month - p.SellDate.Month) < 1); break; case "year": spec = new DirectSpecification <SellRecord>(p => (DateTime.Now.Year - p.SellDate.Year) < 1); break; default: throw new ArgumentException("domain could ontly be one of day, month or year."); } result = _purchaseRepository.FindBySpecification(spec).ToList(); return(result); }
public void Where() { var spec = new DirectSpecification <string>(str => str.Length >= 2); var result = new[] { "aa", "a", "", "aaa" }.Where(spec).ToArray(); Assert.That(result, Is.EquivalentTo(new[] { "aa", "aaa" })); }
public void First() { var spec = new DirectSpecification <string>(str => str.Length > 2); var result = new[] { "aa", "a", "aaa", "aa" }.First(spec); Assert.That(result, Is.EqualTo("aaa")); }
public bool IsSatisfied_Reverses_Original_One(bool origResult) { var originalSpec = new DirectSpecification <object>(obj => origResult); var spec = new NotSpecification <object>(originalSpec); return(spec.IsSatisfiedBy(new object())); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Domain.Core.Specification.Specification{TEntity}"/> /// </summary> /// <returns><see cref="Microsoft.Samples.NLayerApp.Domain.Core.Specification.Specification{TEntity}"/></returns> public override System.Linq.Expressions.Expression <Func <Order, bool> > SatisfiedBy() { Specification <Order> spec = new TrueSpecification <Order>(); spec &= new DirectSpecification <Order>(order => order.CustomerId == _CustomerId); return(spec.SatisfiedBy()); }
public override System.Linq.Expressions.Expression <Func <Asegurado, bool> > SatisfiedBy() { Specification <Asegurado> spec = new TrueSpecification <Asegurado>(); spec &= new DirectSpecification <Asegurado>(c => c.RFC.Equals(_RFC)); return(spec.SatisfiedBy()); }
public void CreateNotSpecificationFromNegationOperator() { var spec = new DirectSpecification<SampleEntity>(s=>s.Name==EntityName); ISpecification<SampleEntity> notSpec = !spec; Assert.IsNotNull(notSpec); }
public void TestaSpecification() { Expression <Func <ClienteStub, bool> > specification = s => string.IsNullOrWhiteSpace(s.Nome) == false; var directSpecification = new DirectSpecification <ClienteStub>(specification); Assert.ReferenceEquals(new PrivateObject(directSpecification).GetField("_MatchingCriteria"), specification); }
public static Specification<Usuario> Consulte() { Specification<Usuario> spec = new DirectSpecification<Usuario>(c => true); spec &= new DirectSpecification<Usuario>(c => true); return spec; }
public int NewArcitle(BlogArticle model, int cateid) { ISpecification <BlogCategory> condition = new DirectSpecification <BlogCategory>(x => x.CateID == cateid); model.BlogCategory = categoryRepository.GetByCondition(condition); return(this.NewSave(model)); }
public override System.Linq.Expressions.Expression <Func <CotizacionCoberturaUbicacion, bool> > SatisfiedBy() { Specification <CotizacionCoberturaUbicacion> spec = new TrueSpecification <CotizacionCoberturaUbicacion>(); spec &= new DirectSpecification <CotizacionCoberturaUbicacion>(c => c.bk_tr_CotizacionCobertura.CotizacionID == _CotizacionID); return(spec.SatisfiedBy()); }
public override System.Linq.Expressions.Expression <Func <Usuario, bool> > SatisfiedBy() { Specification <Usuario> spec = new TrueSpecification <Usuario>(); spec &= new DirectSpecification <Usuario>(c => c.NombreUsuario == _UserName); return(spec.SatisfiedBy()); }
public override System.Linq.Expressions.Expression <Func <workflow, bool> > SatisfiedBy() { Specification <workflow> spec = new TrueSpecification <workflow>(); spec &= new DirectSpecification <workflow>(c => c.procesoID == _Id && c.orden == _Order); return(spec.SatisfiedBy()); }
public bool Operator_Not(bool originalResult) { var original = new DirectSpecification <object>(o => originalResult); var spec = !original; return(spec.IsSatisfiedBy(new object())); }
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); }
public override System.Linq.Expressions.Expression <Func <Ubicacion, bool> > SatisfiedBy() { Specification <Ubicacion> spec = new TrueSpecification <Ubicacion>(); spec &= new DirectSpecification <Ubicacion>(c => c.AseguradoID == _AseguradoID); return(spec.SatisfiedBy()); }
public void CreateDirectSpecificationNullSpecThrowArgumentNullExceptionTest() { //Arrange DirectSpecification<SampleEntity> adHocSpecification; Expression<Func<SampleEntity, bool>> spec = null; //Act adHocSpecification = new DirectSpecification<SampleEntity>(spec); }
public void CreateDirectSpecificationNullSpecThrowArgumentNullExceptionTest() { //Arrange DirectSpecification <SampleEntity> adHocSpecification; Expression <Func <SampleEntity, bool> > spec = null; //Act adHocSpecification = new DirectSpecification <SampleEntity>(spec); }
public static Specification <TituloMovimento> SaoClassesExistentes(string[] codigosClasse) { Specification <TituloMovimento> specification = new TrueSpecification <TituloMovimento>(); var idSpecification = new DirectSpecification <TituloMovimento>(l => codigosClasse.Any(o => o == l.TituloCredCob.VerbaCobranca.CodigoClasse)); specification &= idSpecification; return(specification); }
public ActionResult PostView(int id) { ISpecification <BlogArticle> condition = new DirectSpecification <BlogArticle>(x => x.ArticleID == id); BlogArticle model = _articleService.GetByCondition(condition); ViewData["model"] = model; return(View()); }
public void DirectSpecification_Constructor_NullSpecThrowArgumentNullException_Test() { //Arrange DirectSpecification <TEntity> adHocSpecification; Expression <Func <TEntity, bool> > spec = null; //Act adHocSpecification = new DirectSpecification <TEntity>(spec); }
/// <summary> /// 数据分页的方法 (基于基本条件之上返回的数据) /// </summary> /// <typeparam name="S"></typeparam> /// <param name="PageIndex">当前页码</param> /// <param name="PageSize">每页显示条数</param> /// <param name="condition">数据查询条件表达式</param> /// <param name="orderByExpression">排序的条件表达式</param> /// <param name="IsDESC">是否为倒序</param> /// <returns></returns> public PageData <BlogArticle> Find <S>(int PageIndex, int PageSize, ISpecification <BlogArticle> condition, Expression <Func <BlogArticle, S> > orderByExpression, bool IsDESC) { //合并两个规约条件中的表达式 ISpecification <BlogArticle> baseCondition = new DirectSpecification <BlogArticle>(x => x.State == 1); condition = new AndSpecification <BlogArticle>(condition, baseCondition); return(this.FindAll <S>(PageIndex, PageSize, condition, orderByExpression, IsDESC)); }
public bool Operator_Or(bool leftResult, bool rightResult) { var left = new DirectSpecification <object>(o => leftResult); var right = new DirectSpecification <object>(o => rightResult); var spec = left | right; return(spec.IsSatisfiedBy(new object())); }
public void DirectSpecification_Constructor_NullSpecThrowArgumentNullException_Test() { //Arrange DirectSpecification<TEntity> adHocSpecification; Expression<Func<TEntity, bool>> spec = null; //Act adHocSpecification = new DirectSpecification<TEntity>(spec); }
public void CriaSpecificationComLambdaNullEThrowArgumentNullExceptionTest() { //Arrange DirectSpecification <ClienteStub> adHocSpecification; Expression <Func <ClienteStub, bool> > spec = null; //Act adHocSpecification = new DirectSpecification <ClienteStub>(spec); }
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); }
public static Specification<Usuario> ConsultaEmail(string email) { if (email != null) { email = email.Trim(); } Specification<Usuario> spec = new DirectSpecification<Usuario>(c => true); return spec; }
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; }
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; }
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); }
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); }
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 })); }
/// <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; }
/// <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; }
/// <summary> /// Specification for menu with application code like to <paramref name="text"/> /// </summary> /// <param name="text">The text to search</param> /// <returns>Associated specification for this criterion</returns> public static ISpecification<User> UserName(string userName) { Specification<User> specification = new TrueSpecification<User>(); if (!string.IsNullOrWhiteSpace(userName)) { var nameSpecification = new DirectSpecification<User>(c => c.UserName.ToLower() == userName.ToLower()); specification &= nameSpecification; } return specification; }
public static ISpecification<Place> ByAddress(Guid addressId) { Specification<Place> specification = new TrueSpecification<Place>(); if (addressId != Guid.Empty) { specification &= new DirectSpecification<Place>( p => p.AddressId == addressId ); } return specification; }
/// <summary> /// Specification for menu with application code like to <paramref name="text"/> /// </summary> /// <param name="text">The text to search</param> /// <returns>Associated specification for this criterion</returns> public static ISpecification<Menu> ApplicationCodeFullText(string text) { Specification<Menu> specification = new TrueSpecification<Menu>(); if(!String.IsNullOrWhiteSpace(text)) { var nameSpecification = new DirectSpecification<Menu>(c => c.ApplicationCode.ToLower().Contains(text)); specification &= nameSpecification; } return specification; }
public void DirectSpecification_Constructor_Test() { //Arrange DirectSpecification<Entity> adHocSpecification; Expression<Func<Entity,bool>> spec = s => s.Id==0; //Act adHocSpecification = new DirectSpecification<Entity>(spec); //Assert var expectedValue = adHocSpecification.GetType().GetField("_MatchingCriteria", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(adHocSpecification); Assert.AreSame(expectedValue, spec); }
public void CheckNotSpecificationOperators() { var spec = new DirectSpecification<SampleEntity>(s=>s.Name==EntityName); var notSpec = !spec; ISpecification<SampleEntity> resultAnd = notSpec && spec; ISpecification<SampleEntity> resultOr = notSpec || spec; Assert.IsNotNull(notSpec); Assert.IsNotNull(resultAnd); Assert.IsNotNull(resultOr); }
public static ISpecification<Place> ByCategory(Guid categoryId) { Specification<Place> specification = new TrueSpecification<Place>(); if (categoryId != Guid.Empty) { specification &= new DirectSpecification<Place>( p => p.CategoryId == categoryId ); } return specification; }
public static ISpecification<Place> ByName(string name) { Specification<Place> specification = new TrueSpecification<Place>(); if (!string.IsNullOrWhiteSpace(name)) { specification &= new DirectSpecification<Place>( p => p.Name.ToLower().Contains(name.ToLower()) ); } return specification; }
public void Sepcification_OfType_And_Composite_Test() { //初始化 var inheritSpec = new DirectSpecification<InheritEntity>(be => be.SampleProperty == "Test"); var baseSpec = new DirectSpecification<BaseEntity>(be => be.Id == 1).OfType<InheritEntity>(); //操作 var result = inheritSpec & baseSpec.OfType<InheritEntity>(); //验证 Assert.IsNotNull(inheritSpec); Assert.IsTrue(inheritSpec.SatisfiedBy().Compile()( new InheritEntity() { Id = 1, SampleProperty = "Test" })); }
/// <summary> /// Customer with firstName or LastName equal to <paramref name="text" /> /// </summary> /// <param name="text">The firstName or lastName to find</param> /// <returns>Associated specification for this creterion</returns> public static Specification<Customer> CustomerFullText(string text) { Specification<Customer> specification = new DirectSpecification<Customer>(c => c.IsEnabled); if (!String.IsNullOrWhiteSpace(text)) { var firstNameSpec = new DirectSpecification<Customer>(c => c.FirstName.ToLower().Contains(text)); var lastNameSpec = new DirectSpecification<Customer>(c => c.LastName.ToLower().Contains(text)); specification &= (firstNameSpec || lastNameSpec); } return specification; }
/// <summary> /// Specification for country with name or iso code like to <paramref name="text"/> /// </summary> /// <param name="text">The text to search</param> /// <returns>Associated specification for this criterion</returns> public static ISpecification<Country> CountryFullText(string text) { Specification<Country> specification = new TrueSpecification<Country>(); if (!String.IsNullOrWhiteSpace(text)) { var nameSpecification = new DirectSpecification<Country>(c => c.CountryName.ToLower().Contains(text)); var isoCodeSpecification = new DirectSpecification<Country>(c => c.CountryISOCode.ToLower().Contains(text)); specification &= (nameSpecification || isoCodeSpecification); } return specification; }
public static ISpecification<Person> NameFullText(string text) { Specification<Person> specification = new TrueSpecification<Person>(); if (!string.IsNullOrWhiteSpace(text)) { var firstNameSpecification = new DirectSpecification<Person>(c => c.FirstName.ToLower().Contains(text.ToLower())); var lastNameSpecification = new DirectSpecification<Person>(c => c.LastName.ToLower().Contains(text.ToLower())); specification &= (firstNameSpecification || lastNameSpecification); } return specification; }
/// <summary> /// Profile with firstName or LastName or Email equal to /// </summary> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="email"></param> /// <returns>Associated specification for this creterion</returns> public static Specification<Profile> GetProfileByFilter(string firstName, string lastName, string email) { Specification<Profile> specProfile = new TrueSpecification<Profile>(); if ( !string.IsNullOrEmpty(firstName)) specProfile &= new DirectSpecification<Profile>(p => p.FirstName.Contains(firstName)); if (!string.IsNullOrEmpty(lastName)) specProfile &= new DirectSpecification<Profile>(p => p.LastName.Contains(lastName)); if (!string.IsNullOrEmpty(email)) specProfile &= new DirectSpecification<Profile>(p => p.Email.Contains(email)); return specProfile; }
/// <summary> /// The product full text specification /// </summary> /// <param name="text">the text to find in title or product description</param> /// <returns>Associated specification for this criterion</returns> public static ISpecification<Product> ProductFullText(string text) { Specification<Product> fullTextSpecification = new TrueSpecification<Product>(); if (!String.IsNullOrWhiteSpace(text)) { var left = new DirectSpecification<Product>(p => p.Title.ToLower().Contains(text.ToLower())); var right = new DirectSpecification<Product>(p => p.Description.ToLower().Contains(text.ToLower())); fullTextSpecification &= new OrSpecification<Product>(left, right); } return fullTextSpecification; }
public void CreateAndSpecificationNullRightSpecThrowArgumentNullExceptionTest() { //Arrange DirectSpecification<SampleEntity> leftAdHocSpecification; DirectSpecification<SampleEntity> rightAdHocSpecification; Expression<Func<SampleEntity, bool>> rightSpec = s => s.Id == IdentityGenerator.NewSequentialGuid(); Expression<Func<SampleEntity, bool>> leftSpec = s => s.SampleProperty.Length > 2; leftAdHocSpecification = new DirectSpecification<SampleEntity>(leftSpec); rightAdHocSpecification = new DirectSpecification<SampleEntity>(rightSpec); //Act AndSpecification<SampleEntity> composite = new AndSpecification<SampleEntity>(leftAdHocSpecification, null); }
public void AndSpecification_Creation_NullRightSpecThrowArgumentNullException_Test() { //Arrange DirectSpecification<TEntity> leftAdHocSpecification; DirectSpecification<TEntity> rightAdHocSpecification; Expression<Func<TEntity, bool>> rightSpec = s=>s.Id==0; Expression<Func<TEntity, bool>> leftSpec = s => s.SampleProperty.Length > 2; leftAdHocSpecification = new DirectSpecification<TEntity>(leftSpec); rightAdHocSpecification = new DirectSpecification<TEntity>(rightSpec); //Act AndSpecification<TEntity> composite = new AndSpecification<TEntity>(leftAdHocSpecification, null); }