//[TestMethod, TestCategory("Mapping")] //public void AcmeEmployeeCrmEmployeeContact() //{ // string message = string.Empty; // if (!CompareInputOutputJSON( // sourcesystem: "acme", // sourcejsonpath: @"json\AcmeEmployee_input.json", // destinationsystem: "crm", // destinationjsonpath: @"json\AcmeEmployeeCrmEmployeeContact_output.json", // entity: "employee.contact", // checkSchema: true, // message: out message)) // Assert.Fail(message); //} /// <summary> /// /// </summary> /// <param name="sourcesystem">source system</param> /// <param name="sourcejsonpath">input json</param> /// <param name="destinationsystem">destination system</param> /// <param name="destinationjsonpath">expected output json</param> /// <param name="entity">mapped entity</param> /// <param name="message">output warning message</param> /// <param name="checkSchema">JSON schema validation on result</param> /// <returns></returns> private bool CompareInputOutputJSON(string sourcesystem, string sourcejsonpath, string destinationsystem, string destinationjsonpath, string entity, out string message, bool checkSchema = true) { mapper.SourceSystem = sourcesystem; mapper.DestinationSystem = destinationsystem; var reference = mapper.DestinationSystem + "." + entity; var input = JObject.Parse(File.ReadAllText(sourcejsonpath)); var expected_ouput = JObject.Parse(File.ReadAllText(destinationjsonpath)); var output = mapper.Map <JObject, JObject>(entity, input); message = string.Empty; var successful = true; successful &= EqualJSON(expected_ouput, output, out message); // if failing, let's drop the actual output for easier debugging if (!successful) { File.WriteAllText(reference + ".json", output.ToString()); } if (!checkSchema) { return(successful); } // json schema validation // only acme json is checked, either input or output // for 1 ... N system mapping : ACME employee -> CRM systemuser & CRM contact // entity name after "." is ignored var entityname = entity.Contains('.') ? entity.Substring(0, entity.IndexOf('.')) : entity; var schema = schemas[entityname]; var acmeerrors = schema.Validate(sourcesystem == "acme" ? input : output); if (acmeerrors.Count > 0) { successful &= false; message += schema.DocumentPath + " " + schema.ExtensionData["version"].ToString() + Environment.NewLine; message += string.Join(Environment.NewLine, acmeerrors.Select(s => s.ToString()).ToArray()); } return(successful); }
public void MappingWithMethodInvokeNull() { var mapper = new acmemapper.Mapper(sourceSystem: "systemA", destinationSystem: "systemB", skipLoadingFromMaps: true); var rules = new JObject( new JProperty("entity", new JArray(new JObject( new JProperty("systemA", new JObject(new JProperty("property", "sourceproperty"))), new JProperty("systemB", new JObject( new JProperty("property", "destinationproperty"), new JProperty("invoke", "ToLowerInvariant") )) ) ))); mapper.LoadMapping(rules); var output = mapper.Map <JObject, JObject>("entity", new JObject(new JProperty("sourceproperty", null))); // does this test, due to explicit cast of Value<int>() make sense ? Assert.AreEqual(output["destinationproperty"].Type, JTokenType.Null); }