public IEnumerable <CustomerInfo> GetListByPage(string tel, string name, string webchatId, int pageSize, int pageIndex, int status = 1) { CustomerSpecification cSpec = new CustomerSpecification(new CustomerInfo { Csr_Tel = tel, Csr_Name = name, WeChat_Id = webchatId, Status = status }); return(_customerInfoRepository.GetBySpec(cSpec, pageIndex, pageSize, a => a.CreateTime)); }
public IEnumerable <CustomerInfo> GetList(string tel, string name, string webchatId, int status = 1) { CustomerSpecification cSpec = new CustomerSpecification(new CustomerInfo { Csr_Tel = tel, Csr_Name = name, WeChat_Id = webchatId, Status = status }); return(_customerInfoRepository.GetBySpec(cSpec)); }
public void CustomerName_Optional_IsValid() { var customer = new Customer(); var spec = new CustomerSpecification(); spec.Check(cust => cust.Name).Optional(); List<ValidationResult> notification = spec.Validate(customer); Assert.IsEmpty(notification); }
public IEnumerable <CustomerDto> GetCustomers(string code, string name, string gender, string phone, int pageIndex, int pageSize, out int count) { CustomerSpecification spec = new CustomerSpecification(code, name, gender, phone, pageIndex, pageSize); CustomerSpecification spec1 = new CustomerSpecification(code, name, gender, phone); var customer = _unitOfWork.Customers.Find(spec); count = _unitOfWork.Customers.Count(spec1); return(_mapper.Map <IEnumerable <Customer>, IEnumerable <CustomerDto> >(customer)); }
public void CustomerName_OptionalAndLength_IsNotValid() { var customer = new Customer() { Name = "A"}; var spec = new CustomerSpecification(); spec.Check(cust => cust.Name).Optional().LengthBetween(2, 100); List<ValidationResult> notification = spec.Validate(customer); Assert.IsNotEmpty(notification); Assert.AreEqual(1, notification.Count); }
public void CustomerAddressCountry_Required_IsValid() { var customer = new Customer() { Address = new Address() { Country = new Country() } }; var spec = new CustomerSpecification(); spec.Check(cust => cust.Address.Country.Name).Required(); List<ValidationResult> notification = spec.Validate(customer); Assert.That(notification, Is.Not.Empty); Assert.That(notification.Count, Is.EqualTo(1)); Assert.That(notification[0].Message, Is.EqualTo("Address Country Name is required.")); }
public async Task <Pagination <Customer> > FindCustomersAsync(CustomerParams customerParams) { var specification = new CustomerSpecification(customerParams); var countSpecification = new CustomerFilterForCountSpecification(customerParams); int totalItems = await _customerRepository.CountAsync(countSpecification); var data = await _customerRepository.FindListAsync(specification); return(new Pagination <Customer>(customerParams.PageIndex, customerParams.PageSize, totalItems, data)); }
public void Specification_WithWarn_ReturnsValidationResultAsWarn() { var spec = new CustomerSpecification(); spec.Check(c => c.Name).Required(); spec.Warn(c => c.Address).Required().Specification<AddressSpecification>(); var customer = new Customer(); var validationResults = spec.Validate(customer); var addressValidationResult = validationResults.Errors.Where(vr => vr.Property.Name == "Address").First(); var nameValidationResult = validationResults.Errors.Where(vr => vr.Property.Name == "Name").First(); Assert.That(addressValidationResult.Level == ValidationLevelType.Warn); Assert.That(nameValidationResult.Level == ValidationLevelType.Error); }
public void CustomerContacts_Lambda_IsNotValid() { var contact1 = new Contact() { DateOfBirth = DateTime.Now.AddYears(-19) }; var contact2 = new Contact() { DateOfBirth = DateTime.Now.AddYears(-22) }; var customer = new Customer() { Contacts = new List<Contact> { contact1, contact2 } }; var spec = new CustomerSpecification(); spec.Check( c => from contact in c.Contacts where contact.DateOfBirth < DateTime.Now.AddYears(-20) select contact) .Optional() .ForEach(c => ((Contact)c).Active, "All contacts under age of 20 must be active."); List<ValidationResult> notification = spec.Validate(customer); Assert.IsNotEmpty(notification); Assert.AreEqual(1, notification.Count); }
public void Should_Compose_rule_and_Apply_All() { CustomerSpecification specification = new CustomerSpecification(); specification.ApplyRules(new Customer { PurchasedAmount = 100001 }).customerType.Should().Be(CustomerType.Premium); }
public void CustomerName_RequiredAndNotMinLength_InvalidLength_IsNotValid() { var customer = new Customer { Name = string.Empty.PadLeft(105, 'X') }; var spec = new CustomerSpecification(); spec.Check(cust => cust.Name).Required().Not.MinLength(100); List<ValidationResult> notification = spec.Validate(customer); Assert.IsNotEmpty(notification); Assert.AreEqual(1, notification.Count); }
public void When_Customer_Contacts_IsInitializeButEmpty_And_DefinedRequired_IsInvalid() { var customer = new Customer { Contacts = new List<Contact>() }; var spec = new CustomerSpecification(); spec.Check(cust => cust.Contacts).Required(); List<ValidationResult> notifications = spec.Validate(customer); Assert.IsNotEmpty(notifications); }
public void PastCustomerPromotionDate_IsInFuture_IsNotValid() { var customer = new Customer() { PromotionDate = DateTime.Now.AddDays(-1) }; var spec = new CustomerSpecification(); spec.Check(c => c.PromotionDate).Optional().IsInFuture(); List<ValidationResult> notification = spec.Validate(customer); Assert.That(notification, Is.Not.Empty); }
public void CustomerName_Required_IsNotValid() { var customer = new Customer(); var spec = new CustomerSpecification(); spec.Check(cust => cust.Name).Required(); List<ValidationResult> notification = spec.Validate(customer); Assert.IsNotEmpty(notification); }
public Customer Get(Guid id) { var spec = new CustomerSpecification(id); return(_repository.GetSingleBySpec(spec)); }
public async Task <Customer> GetCustomerById(int id) { var specification = new CustomerSpecification(id); return(await _customerRepository.FindAsync(specification)); }
public Customer GetByWill(Will will) { var spec = new CustomerSpecification(will); return(_repository.GetSingleBySpec(spec)); }
public async Task <ActionResult <CustomerRepresentation> > CreateCustomer([FromBody] CustomerSpecification spec) { var customer = await this._customers.AddAsync(spec.Name); return(this.Ok(CustomerRepresentation.FromEntity(customer))); }