private CriterionData GenerateCriterion(SearchCriteria criterion) { var operators = fieldTypeToOperatorMap[criterion.Type]; var searchOperator = random.PickFromList(operators); var value = GenerateValue(criterion); return new CriterionData { FilterType = (int) criterion.Type, Operator = (int) searchOperator, Value = value }; }
private string GenerateStringValue(SearchCriteria criterion) { switch (criterion.InternalName) { case LocationSearchCriteria.City: return random.PickFromList(TownData.Data).Town; case LocationSearchCriteria.Region: return random.PickFromList(TownData.Data).Region; case LocationSearchCriteria.PostalCode: return new AddressGenerator().RandomPostalCode(); case CampaignSearchCriteria.DonatedToCampaign: //TODO: work out what this represents return "random"; default: throw new NotSupportedException("Unsupported search criterion: " + criterion.InternalName); } }
private string GenerateValue(SearchCriteria criterion) { switch (criterion.Type) { case SearchFieldType.Bool: return random.Bool().ToString(); case SearchFieldType.Double: case SearchFieldType.Int: return random.NextInt(1, 1000).ToString(); case SearchFieldType.SelectList: case SearchFieldType.String: return GenerateStringValue(criterion); case SearchFieldType.Date: return random.NextDateTime().ToString("u"); default: throw new NotSupportedException("Unsupported search criterion type: " + criterion.Type); } }