public Endpoint CreateEndpoint(string rootDir, JSONDefaults globalDefaults) { var endpoint = new Endpoint(name, pathregex); var endpointDefaultsFile = Path.Combine(rootDir, "defaults.json"); var endpointDefaults = File.Exists(endpointDefaultsFile) ? JsonConvert.DeserializeObject <JSONDefaults>(File.ReadAllText(endpointDefaultsFile)) : null; foreach (var jsonResponse in responses) { if (endpointDefaults != null) { applyDefaults(endpointDefaults, jsonResponse); } if (globalDefaults != null) { applyDefaults(globalDefaults, jsonResponse); } var validatedJsonResponse = jsonResponse.Validated(); endpoint.Add(validatedJsonResponse.match.CreateRequestMatcher(), validatedJsonResponse.CreateResponseCreator(rootDir)); } endpoint.Directory = rootDir; return(endpoint); }
public Endpoint CreateEndpoint(string rootDir, JSONDefaults globalDefaults) { ThrowExceptionIfAdditionalData(); var endpoint = new Endpoint(name, pathregex) { Directory = rootDir, RecordRequests = record }; var endpointDefaultsFile = Path.Combine(rootDir, "defaults.json"); var endpointDefaults = File.Exists(endpointDefaultsFile) ? JsonConvert.DeserializeObject <JSONDefaults>(File.ReadAllText(endpointDefaultsFile)) : null; if (endpointDefaults != null) { endpointDefaults.ThrowExceptionIfAdditionalData(); } foreach (var jsonResponse in responses) { if (endpointDefaults != null) { applyDefaults(endpointDefaults, jsonResponse); } if (globalDefaults != null) { applyDefaults(globalDefaults, jsonResponse); } var validatedJsonResponse = jsonResponse.Validated(); endpoint.Add(validatedJsonResponse.match.CreateRequestMatcher(), validatedJsonResponse.CreateResponseCreator(endpoint)); } var paramsFile = Path.Combine(rootDir, "params.json"); if (File.Exists(paramsFile)) { var jsonParams = from item in JsonConvert.DeserializeObject <JSONParam[]>(File.ReadAllText(paramsFile)) select item.Validated(); foreach (var jsonParam in jsonParams) { endpoint.AddParameter(new EndpointParameter { Name = jsonParam.name, DefaultValue = jsonParam.@default, Value = jsonParam.@default, Description = jsonParam.description }); } } return(endpoint); }
private void applyDefaults(JSONDefaults defaults, JSONResponse jsonResponse) { Debug.Assert(defaults != null); Debug.Assert(jsonResponse != null); if (defaults.charset != null && jsonResponse.charset == null) { jsonResponse.charset = defaults.charset; } if (defaults.contenttype != null && jsonResponse.contenttype == null) { jsonResponse.contenttype = defaults.contenttype; } }
public static Endpoint ReadEndpoint(string jsonString, string rootDir, JSONDefaults globalDefaults) { return(JsonConvert.DeserializeObject <JSONEndpoint>(jsonString).CreateEndpoint(rootDir, globalDefaults)); }