public void TestClassInitialize() { // Create an instance of JiraRestClient to cause all static constructors in JIRC to be executed. // We need this so that JsonDataContractDeserializer will call JIRC's custom parsing handlers when parsing Issue from string. var client = JiraRestClientFactory.CreateWithBasicHttpAuth( new Uri("http://mock"), "mock", "mock"); // Register a converter for custom Issue field type. Func <string, object> customTypeParser = (string json) => { JsonObject parsed = JsonObject.Parse(json); CustomType custom = new CustomType(); custom.CustomStringProperty = parsed["customstring"]; custom.CustomIntProperty = int.Parse(parsed["customint"]); return(custom); }; Func <object, string> customTypeSerializer = (object obj) => { JsonObject serialized = new JsonObject(); serialized.Add("customstring", (obj as CustomType).CustomStringProperty); serialized.Add("customint", (obj as CustomType).CustomIntProperty.ToString()); return(serialized.ToJson()); }; CustomFieldTypes.Register(TestRegisteredCustomFieldName, customTypeParser, customTypeSerializer); }
/// <summary> /// Generates the JSON. /// </summary> /// <param name="fieldChanges">The changes to make to the issue.</param> /// <returns>The JSON.</returns> internal static JsonObject Generate(IList <UpdateFieldInput> fieldChanges) { var jsonObject = new JsonObject(); var list = new JsonObject(); if (fieldChanges != null) { foreach (var change in fieldChanges) { // Serialize any custom fields using their custom converters if they are defined. // Default conversion calls .ToString() otherwise on non-null values, and returns null on null values. list.Add(change.FieldName, change.Elements.ConvertAll(a => new JsonObject { { a.Operation.ToRestString(), CustomFieldTypes.Serialize(change.FieldName, a.Value) } }).ToJson()); } } jsonObject.Add("update", list.ToJson()); return(jsonObject); }
public void TestRegisterConverterForInvalidFieldName() { CustomFieldTypes.Register("myfield", (string json) => { return(new CustomType()); }, (object obj) => { return(string.Empty); }); }
public void TestRegisterNullConverter() { CustomFieldTypes.Register("customfield_another", null, null); }