public void Filter_Supplier_Returns_OwnNHSD() { var orgId = Guid.NewGuid().ToString(); var org = Creator.GetOrganisation(id: orgId, primaryRoleId: PrimaryRole.ApplicationServiceProvider); var otherOrgId = Guid.NewGuid().ToString(); var otherOrg = Creator.GetOrganisation(id: otherOrgId, primaryRoleId: PrimaryRole.ApplicationServiceProvider); var nhsdOrgId = Guid.NewGuid().ToString(); var nhsd = Creator.GetOrganisation(id: nhsdOrgId, primaryRoleId: PrimaryRole.GovernmentDepartment); var cont1 = Creator.GetContact(orgId: orgId); var cont2 = Creator.GetContact(orgId: orgId); var cont3 = Creator.GetContact(orgId: otherOrgId); var cont4 = Creator.GetContact(orgId: nhsdOrgId); _organisationDatastore.Setup(x => x.ByContact(cont1.Id)).Returns(org); _organisationDatastore.Setup(x => x.ByContact(cont2.Id)).Returns(org); _organisationDatastore.Setup(x => x.ByContact(cont3.Id)).Returns(otherOrg); _organisationDatastore.Setup(x => x.ByContact(cont4.Id)).Returns(nhsd); var ctx = Creator.GetContext(orgId: orgId, role: Roles.Supplier); _context.Setup(c => c.HttpContext).Returns(ctx); var filter = new ContactsFilter(_context.Object, _organisationDatastore.Object); var contacts = new[] { cont1, cont2, cont3, cont4 }; var res = filter.Filter(contacts); res.Should().BeEquivalentTo(new[] { cont1, cont2, cont4 }); }
public ContactsResponse GetContacts(ContactsFilter filter) { return(_gateway.Retrieve(client => { var request = new RestRequest("contacts"); request.ApplyPaging(filter); if (filter.LastUpdatedFilter.HasValue) { var value = filter.LastUpdatedFilter.Value .ToUniversalTime() .ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); request.AddQueryParameter("f_lastupdated", value, false); } if (!string.IsNullOrWhiteSpace(filter.EmailFilter)) { request.AddQueryParameter("f_email", filter.EmailFilter); } if (!string.IsNullOrWhiteSpace(filter.NameFilter)) { request.AddQueryParameter("f_name", filter.NameFilter); } if (filter.TypeFilter.HasValue) { request.AddQueryParameter("f_type", filter.TypeFilter.Value.ToString().ToLowerInvariant()); } return client.Get <ContactsResponse>(request); })); }
public static IEnumerable <Contact> Filter(this IEnumerable <Contact> @this, ContactsFilter filter) { return(@this.ConditionalWhere(() => filter.Name != null, x => x.Name.Contains(filter.Name)) .ConditionalWhere(() => filter.ContactType != null, x => x.ContactType == filter.ContactType) .ConditionalWhere(() => filter.Experience != null, x => x.Experience == filter.Experience) .ConditionalWhere(() => filter.Salary != null, x => x.Salary == filter.Salary) .ConditionalWhere(() => filter.SalaryGreaterThan5000 != false, x => x.Salary > 5000) .ConditionalWhere(() => filter.ExperiencedProgrammer != false, x => x.ContactType == ContactType.Programmer && x.Experience == 5)); }
public void Filter_None_Returns_All() { var filter = new ContactsFilter(); var contacts = new[] { Creator.GetContact(), Creator.GetContact(), Creator.GetContact() }; var res = filter.Filter(contacts); res.Should().BeEquivalentTo(contacts); }
public void Filter_NonSupplier_Returns_All(string role) { var ctx = Creator.GetContext(role: role); _context.Setup(c => c.HttpContext).Returns(ctx); var filter = new ContactsFilter(_context.Object, _organisationDatastore.Object); var contacts = new[] { Creator.GetContact(), Creator.GetContact(), Creator.GetContact() }; var res = filter.Filter(contacts); res.Should().BeEquivalentTo(contacts); }
public void test_fetching_contacts() { var service = new ContactsService(_gateway); var filter = new ContactsFilter { PageSize = 1, PageNumber = 1, //LastUpdatedFilter = new DateTimeOffset(new DateTime(2018, 1, 1), TimeSpan.FromMinutes(120)), TypeFilter = ContactType.Company, EmailFilter = "aplos", NameFilter = "software" }; var contacts = service.GetContacts(filter); contacts.Data.Contacts.Count.Should().BeGreaterThan(0); var contact = service.GetContact(contacts.Data.Contacts[0].Id); }
private bool ContactsFilterPredicate(object o) { Contact contact = o as Contact; if (contact == null) { return(false); } if (string.IsNullOrEmpty(ContactsFilter)) { return(true); } IEnumerable <string> filterParts = ContactsFilter.Split(' ').Select(s => s.ToLower()).ToArray(); IEnumerable <string> personData = new string[] { contact.Name, contact.Surname, contact.City, contact.PhoneNumber }.Select(s => s.ToLower()).ToArray(); foreach (string filterPart in filterParts) { bool partMatches = false; foreach (string personDatum in personData) { if (!string.IsNullOrEmpty(personDatum) && personDatum.Contains(filterPart)) { partMatches = true; break; } } if (partMatches) { return(true); } } return(false); }