public override Specification <Country> GetSpecification() { var spec = new Specification <Country>(); if (!Ids.IsEmpty()) { int[] ids = ArrayHelpers.StringToIntArray(Ids); if (ids != null && ids.Length > 0) { spec.And(c => ids.Contains(c.Id)); } } if (!Name.IsEmpty()) { spec.And(c => c.Name.StartsWith(Name)); } if (!Abbreviation.IsEmpty()) { spec.And(c => c.Abbreviation.StartsWith(Abbreviation)); } if (!ShowAll) { spec.And(c => c.Enabled == true); } return(spec); }
public override Specification <Mapping> GetSpecification() { var spec = new Specification <Mapping>(); if (!Ids.IsEmpty()) { int[] ids = ArrayHelpers.StringToIntArray(Ids); if (ids != null && ids.Length > 0) { spec.And(c => ids.Contains(c.Id)); } } if (!ProductIds.IsEmpty()) { int[] ids = ArrayHelpers.StringToIntArray(ProductIds); if (ids != null && ids.Length > 0) { spec.And(c => ids.Contains(c.ProductId)); } } if (StoreId.HasValue) { spec.And(m => m.StoreId.Equals(StoreId.Value)); } if (!Sku.IsEmpty()) { spec.And(m => m.Product.Sku.StartsWith(Sku)); } if (!StoreSku.IsEmpty()) { spec.And(m => m.StoreSku.StartsWith(StoreSku)); } return(spec); }
public override Specification <ReportGroupItem> GetSpecification() { var spec = new Specification <ReportGroupItem>(); if (!Ids.IsEmpty()) { int[] ids = ArrayHelpers.StringToIntArray(Ids); if (ids != null && ids.Length > 0) { spec.And(c => ids.Contains(c.Id)); } } if (ReportGroupId.HasValue) { spec.And(i => i.ReportGroupId == ReportGroupId.Value); } if (!Sku.IsEmpty()) { spec.And(i => i.Product.Sku.StartsWith(Sku)); } if (!Name.IsEmpty()) { spec.And(i => i.Product.Name.Contains(Name)); } return(spec); }
private Specification <Jugador> GetJugadorSpecification() { Specification <Jugador> specification = Specification <Jugador> .All; specification = specification.And(new JugadoresDelanterosSpecification()); specification = specification.And(new JugadorClubBySpecification("UNIVERSITARIO DE DEPORTES")); return(specification); }
public SaleLead FindOrCreateSaleLead(CustomerDTO cus, int orderNo, EmployeeDTO emp) { var cusSpec = new Specification<SalePositionLead>(c => c.SaleLead.CustomerId == cus.CustomerId); var saleSpec = new Specification<SalePositionLead>(s => s.SaleLead.Sale.OrderNumber == orderNo); var cusAndSale = cusSpec.And(saleSpec); var lead = _repoSalePositionLead.Find(cusAndSale); if (lead == null) { var cusNameSpec = new Specification<SalePositionLead>(c => c.SaleLead.Customer.Name == cus.CustomerName); var cusNameAndSale = cusNameSpec.And(saleSpec); lead = _repoSalePositionLead.Find(cusNameAndSale); if(lead == null) { var empSpec = new Specification<SalePositionLead>(x => x.EmployeeInSalePosition.Employee.Id == emp.EmployeeId); var otherCusSpec = new Specification<SalePositionLead>(v => v.SaleLead.Customer.Id == cus.CustomerId); var otherAndEmp = empSpec.And(otherCusSpec); lead = _repoSalePositionLead.Find(otherAndEmp); if(lead==null) { var cusNameAndEmpSpec = empSpec.And(cusNameSpec); lead = _repoSalePositionLead.Find(cusNameAndEmpSpec); if(lead == null) { var customer = _repoCustomer.Get(cus.CustomerId); var state = _repoSaleLeadState.AsQueryable().FirstOrDefault(x => x.Id > 0); var l = CreateSaleLead(customer.Id, state.Id, 0, DateTime.Now); _repoSaleLead.Add(l); return l; } else { return lead.SaleLead; } } else { return lead.SaleLead; } } else { return lead.SaleLead; } } else { return lead.SaleLead; } }
protected override ISpecification <OtherDocumentItemDto> ToSpecification(IWorkItemStrategy workItemStrategy) { var specification = new Specification <OtherDocumentItemDto>(); if (!(workItemStrategy is OtherDocumentItemWorkItemStrategy strategy)) { return(specification); } if (strategy.WithNestedItems) { if (strategy.NestedItemWorkItemStrategy.WithOneMoreNestedItems) { specification.FetchStrategy.Add(w => w.Include(x => x.NestedItemDtos) .ThenInclude(x => x.OneMoreNestedItemDtos)); } else { specification.FetchStrategy.Add(w => w.Include(x => x.NestedItemDtos)); } } if (!strategy.WithDeleted) { specification.And(OnlyNotDeletedSpecification); } return(specification); }
public void EfCore_FindAll_With_Include_And_Predicate_In_Specs_LazyLoads_Email() { var repository = new EfCoreRepository <Contact, string>(dbContext); var findAllBySpec = new Specification <Contact>(obj => obj.ContactId == "1") .And(obj => obj.EmailAddresses.Any(m => m.Email == "*****@*****.**")); var specification = new Specification <Contact>(obj => obj.Name == "Test User 1"); findAllBySpec.FetchStrategy = new GenericFetchStrategy <Contact>(); findAllBySpec.FetchStrategy .Include(obj => obj.EmailAddresses); // NOTE: This line will erase my FetchStrategy from above if (null != specification) { findAllBySpec = findAllBySpec.And(specification); } var contact = repository.FindAll(findAllBySpec).First(); contact.Name.ShouldBe("Test User 1"); dbContext.QueryLog.Count(filterSelects).ShouldBe(2); contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**"); dbContext.QueryLog.Count(filterSelects).ShouldBe(2); repository.FindAll(findAllBySpec).Count().ShouldBe(1); }
public IPagingList <ProjectTargetCostDto> GetTargetCosts(ProjectQueryRequest queryRequest) { var specification = new Specification <VIProjectTargetCost>(); if (!string.IsNullOrEmpty(queryRequest.Code)) { specification.And(n => n.Code.Contains(queryRequest.Code)); } if (!string.IsNullOrEmpty(queryRequest.Name)) { specification.And(n => n.Name.Contains(queryRequest.Name)); } specification.SetPage(queryRequest); return(repository.PagingList(specification).ProjectedAsPagingList <ProjectTargetCostDto>()); }
private Specification <Employee> GetFindByUsername(string Username) { Specification <Employee> specification = Specification <Employee> .All; specification = specification.And(new FindByUsernameBySpecification(Username)); return(specification); }
private Specification <Employee> GetLogingSpecification(string usu, string clave) { Specification <Employee> specification = Specification <Employee> .All; specification = specification.And(new LoginBySpecification(usu, clave)); return(specification); }
public void And_IsSatisfiedBy_ShouldBeFalseWith(int value) { var specification = new Specification <int>(v => v > 0); var secondSpec = new Specification <int>(v => v < 10); Assert.False(specification.And(secondSpec).IsSatisfiedBy(value)); }
private Specification <Product> GetLikeSearchByName(string ProductName) { Specification <Product> specification = Specification <Product> .All; specification = specification.And(new LikeSearchByNameSpecification(ProductName)); return(specification); }
private Specification <Product> GetFindByCategory(long Category_id) { Specification <Product> specification = Specification <Product> .All; specification = specification.And(new FindByCategoryBySpecification(Category_id)); return(specification); }
private Specification <Customer> GetById(long CustomerId) { Specification <Customer> specification = Specification <Customer> .All; specification = specification.And(new GetByIdBySpecification(CustomerId)); return(specification); }
private Specification <Customer> GetFindByDocumentNumber(string DocumentNumber) { Specification <Customer> specification = Specification <Customer> .All; specification = specification.And(new FindByDocumentNumberBySpecification(DocumentNumber)); return(specification); }
private Specification <Movie> GetMovieSpecification(bool forKidsOnly, bool onCD) { Specification <Movie> specification = Specification <Movie> .All; if (forKidsOnly) { specification = specification.And(new MovieForKidsSpecification()); } if (onCD) { specification = specification.And(new AvailableOnCDSpecification()); } specification = specification.And(new MovieDirectedBySpecification("Bill Condon")); //spec = new MovieDirectedBySpecification("Marc Webb"); return(specification); }
protected override ISpecification <DocumentDto> ToSpecification(IWorkItemStrategy documentWorkItemStrategy) { var specification = new Specification <DocumentDto>(); specification.FetchStrategy.Add(w => w.Include(x => x.OtherDocumentDto)); // add Inlcude all inherited types.. if (!(documentWorkItemStrategy is DocumentWorkItemStrategy strategy)) { return(specification); } if (strategy.WithAttachments) { specification.FetchStrategy.Add( w => w.Include(x => x.AttachmentLinkDtos) .ThenInclude(x => x.AttachmentDto) ); } if (!strategy.WithDeleted) { specification.And(OnlyNotDeletedSpecification); } return(specification); }
private Specification <Product> GetById(long ProductId) { Specification <Product> specification = Specification <Product> .All; specification = specification.And(new GetByIdBySpecification(ProductId)); return(specification); }
private Specification <Product> GetFindByName(string ProductName) { Specification <Product> specification = Specification <Product> .All; specification = specification.And(new FindByNameBySpecification(ProductName)); return(specification); }
private Specification <Provider> GetFindByName(string Name) { Specification <Provider> specification = Specification <Provider> .All; specification = specification.And(new FindByNameSpecification(Name)); return(specification); }
private Specification <Producto> GetProductospecification(bool?all) { Specification <Producto> specification = Specification <Producto> .All; specification = specification.And(new ProductoNameBySpecification("Leche Gloria Deslactosada 400gm")); return(specification); }
public override bool IsSatisfiedBy(Order candidate) { return(domesticOrderSpec .And(highValueSpec) .And(inStockSpec) .And(hazardousSpec.Not()) .IsSatisfiedBy(candidate)); }
private void Search() { Specification <Movie> spec = Specification <Movie> .All; if (ForKidsOnly) { spec = spec.And(new MovieForKidsSpecification()); } if (OnCD) { spec = spec.And(new AvailableOnCDSpecification()); } Movies = _repository.GetList(spec, MinimumRating); Notify(nameof(Movies)); }
private Pagination <Game> MyGameList(int page, Specification <Game> statusSpec) { return(_gameRepository.Paginate( page, PAGE_SIZE, statusSpec.And(new ContainsPlayerSpecification(AuthContext.UserId)), new GameIdSort() )); }
public Specification <TEntity> ValidSpec <TEntity>(Specification <TEntity> spec) where TEntity : class, IEntity, new() { var nameSpecType = typeof(NameSpec <>).MakeGenericType(typeof(TEntity)); var nameSpec = Activator.CreateInstance(nameSpecType); //Specification<TEntity> nameSpec = (Specification<TEntity>)(object)new NameSpec<TEntity>(); var newSpec = nameSpec as Specification <TEntity>; return(spec == null ? newSpec : spec.And(newSpec)); }
public IPagingList <SupplierDto> GetPagingList(SupplierQueryRequest filterRequest) { Specification <Supplier> specification = new Specification <Supplier>(); specification.SetPage(filterRequest); if (!string.IsNullOrEmpty(filterRequest.Name)) { specification.And(n => n.Name.Contains(filterRequest.Name)); } if (!string.IsNullOrEmpty(filterRequest.ManName)) { specification.And(n => n.ManName.Contains(filterRequest.ManName)); } int total = 0; var list = repository.PageList(specification, ref total); return(list.ProjectedAsPagingList <SupplierDto>(total, filterRequest)); }
public override Expression <Func <T, bool> > ToExpression() { var notLeftAndRight = _left.Not().And(_right); var leftAndNotRight = _left.And(_right.Not()); var xOr = notLeftAndRight.Or(leftAndNotRight); return(xOr.ToExpression()); }
public override Specification <ReportGroup> GetSpecification() { var spec = new Specification <ReportGroup>(); if (!Ids.IsEmpty()) { int[] ids = ArrayHelpers.StringToIntArray(Ids); if (ids != null && ids.Length > 0) { spec.And(c => ids.Contains(c.Id)); } } if (!Name.IsEmpty()) { spec.And(c => c.Name.StartsWith(Name)); } return(spec); }
private void Search() { // Specification<Movie> spec = null; // diyemeyiz çünkü alttaki ifadeler spec üzerinde çalışıyorlar. Specification <Movie> spec = Specification <Movie> .All; if (ForKidsOnly) { spec = spec.And(new MovieForKidsSpecification()); } if (OnCD) { spec = spec.And(new AvailableOnCDSpecification()); } Movies = _repository.GetList(spec, MinimumRating); Notify(nameof(Movies)); }
public void InvokeAnd_ReturnAndSpecification() { var left = MockComplexSpecification.True(); var right = MockComplexSpecification.False(); var expected = new AndSpecification <object>(left, right); var sut = Specification.And(left, right); Assert.Equal(expected, sut, new SpecificationComparer()); }
public void AndShouldNotAllowNull() { // arrange ISpecification<string> other = null; var target = new Specification<string>( s => true ); // act var ex = Assert.Throws<ArgumentNullException>( () => target.And( other ) ); // assert Assert.Equal( "other", ex.ParamName ); }
public void AndShouldReturnCombinedSpecification() { // arrange var s1 = new Specification<string>( s => true ); var s2 = new Specification<string>( s => false ); // act var actual = s1.And( s2 ); // assert Assert.NotNull( actual ); }
public void It_should_return_zero_entities_not_matching_any_specifications() { // ARRANGE var repository = Fixture.CreateRepository(); var nonExistingAge = -999; var existingLastName = "Tran"; // ACT var over30Match = new Specification<Customer>(p => p.Age == nonExistingAge); var lastNameMatch = new Specification<Customer>(p => p.LastName == existingLastName); var entities = repository.FindAll<Customer>(over30Match.And(lastNameMatch)).ToList(); // ASSERT Assert.AreEqual(0, entities.Count); }
public void It_should_return_entities_matching_all_specifications() { // ARRANGE var repository = Fixture.CreateRepository(); var existingAge = 40; var existingLastName = "Tran"; // ACT var over30Match = new Specification<Customer>(p => p.Age > existingAge); var lastNameMatch = new Specification<Customer>(p => p.LastName == existingLastName); var entities = repository.FindAll<Customer>(over30Match.And(lastNameMatch)).ToList(); // ASSERT Assert.AreEqual(1, entities.Count); Assert.AreEqual("Peter Tran", entities[0].GetFullName()); }
public void Should_return_itself_on_adding_and_operator_when_other_specification_is_null() { var expected = new Specification<string>(s => s.Contains("a")); var target = expected.And(null); Assert.That(target, Is.SameAs(expected)); }