using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using Org.XmlUnit.Builder; using Org.XmlUnit.Diff; using Org.XmlUnit.Input; using Org.XmlUnit.Validation; using XmlUnit = Org.XmlUnit; using CRIF.ACTion.Configuration; namespace CRIF.ACTion.Tests { public static class TestCommon { public static CrifSettings GetTestSettings() { var settings = new CrifSettings { ApiSettings = new ApiConnectionSettings { Username = "LandmarkCUImportUser", InterfaceId = 600002, OrgCode = "LandmarkCU", OrgId = 4, }, SourceChannels = new SourceChannelSettings { DefaultSourceChannelId = 2399724, CreditCardSourceChannelId = 2294092, }, ProductIds = new ProductIdSettings { CC_CashBack = 132, CC_Rewards = 133, CC_Student = 134, CC_Secure = 136, EQ_HELOC_Flex = 139, EQ_Home_Equity_Fixed = 148, EQ_Mtg_Refi_Express = 149, EQ_Mfg_Home_And_Land = 146, V_Vehicle = 125, V_VehiclePreapproval = 126, M_Boat = 129, P_Powersport = 131, T_TrailerMotorhome = 130, S_Signature = 140 }, ServicingChannels = new ServicingChannelSettings { DefaultServicingChannel = 1698432, }, CustomFieldMappings = new CustomFieldMappings { LoanTypeToPromoId = new Dictionary() { { "132", "-119" }, { "133", "-119" }, { "134", "-119" }, { "136", "-119" }, { "139", "-115" }, { "148", "-115" }, { "149", "-115" }, { "146", "-115" }, { "125", "-116" }, { "126", "-116" }, { "129", "-116" }, { "131", "-116" }, { "130", "-116" }, { "140", "-118" } } }, CustomFields = new CustomFieldConfigs { CustomPropertyRenovationFieldData = new List() { { new CustomPropertyStatusData { CustomFieldId = "-109", ProductCategoryId = "28", SortOrder = "1", YesId = "270", NoId = "269", NaId = "301" } } }, CustomPropertySaleFieldData = new List() { { new CustomPropertyStatusData { CustomFieldId = "-110", ProductCategoryId = "28", SortOrder = "2", YesId = "272", NoId = "271", NaId = "302" } } }, CustomJointCreditFieldData = [ new CustomJointCreditData { CustomFieldId = "-127", ProductCategoryId = "28", SortOrder = "25", IndividuallyId = "314", JointlyId = "315" }, new CustomJointCreditData { CustomFieldId = "-126", ProductCategoryId = "27", SortOrder = "25", IndividuallyId = "312", JointlyId = "313" }, new CustomJointCreditData { CustomFieldId = "-125", ProductCategoryId = "26", SortOrder = "25", IndividuallyId = "310", JointlyId = "311" }, new CustomJointCreditData { CustomFieldId = "-124", ProductCategoryId = "24", SortOrder = "25", IndividuallyId = "308", JointlyId = "309" }, new CustomJointCreditData { CustomFieldId = "-122", ProductCategoryId = "25", SortOrder = "25", IndividuallyId = "303", JointlyId = "304" } ], ProductIdToCategoryId = new Dictionary() { {"107" , "22"}, {"108" , "22"}, {"109" , "22"}, {"110" , "22"}, {"111" , "22"}, {"112" , "22"}, {"113" , "22"}, {"114" , "23"}, {"115" , "22"}, {"116" , "22"}, {"117" , "22"}, {"118" , "22"}, {"119" , "22"}, {"120" , "22"}, {"121" , "22"}, {"122" , "22"}, {"123" , "22"}, {"124" , "22"}, {"125" , "27"}, {"126" , "27"}, {"127" , "27"}, {"128" , "27"}, {"129" , "27"}, {"130" , "27"}, {"131" , "27"}, {"132" , "24"}, {"133" , "24"}, {"134" , "24"}, {"135" , "24"}, {"136" , "24"}, {"137" , "24"}, {"138" , "24"}, {"139" , "28"}, {"140" , "25"}, {"141" , "26"}, {"142" , "26"}, {"143" , "25"}, {"144" , "25"}, {"145" , "25"}, {"146" , "28"}, {"147" , "28"}, {"148" , "28"}, {"149" , "28"}, {"150" , "27"}, {"151" , "24"} } } }; return settings; } public static ICollection Compare(XElement xml1, XElement xml2) { var source1 = Input.FromNode(xml1).Build(); var source2 = Input.FromNode(xml2).Build(); return Compare(source1, source2); } public static ICollection Compare(XElement xml1, string xmlLocation) { var source1 = Input.FromNode(xml1).Build(); var source2 = Input.FromFile(xmlLocation).Build(); return Compare(source1, source2); } private static ICollection Compare(XmlUnit.ISource source1, XmlUnit.ISource source2) { var diff = DiffBuilder.Compare(source2) .WithTest(source1) .CheckForIdentical() .Build(); var similar = diff.Differences.Where(x => x.Result == ComparisonResult.SIMILAR).ToList(); var different = diff.Differences.Where(x => x.Result == ComparisonResult.DIFFERENT).ToList(); //TODO #243: Apparently this will be false if elements are in different orders, but diff.Differences will have data -_- var result = diff.HasDifferences(); return different; } public static IEnumerable Validate(XNode xmlData) { Validator v = Validator.ForLanguage(Languages.W3C_XML_SCHEMA_NS_URI); v.SchemaSources = [ new StreamSource("XSDs" + System.IO.Path.DirectorySeparatorChar + "actionAPI.XSD"), new StreamSource("XSDs" + System.IO.Path.DirectorySeparatorChar + "appSchema.xsd"), new StreamSource("XSDs" + System.IO.Path.DirectorySeparatorChar + "commonSchema.xsd"), new StreamSource("XSDs" + System.IO.Path.DirectorySeparatorChar + "maintSchema.xsd"), new StreamSource("XSDs" + System.IO.Path.DirectorySeparatorChar + "msgSchema.xsd"), new StreamSource("XSDs" + System.IO.Path.DirectorySeparatorChar + "qoSchema.xsd"), new StreamSource("XSDs" + System.IO.Path.DirectorySeparatorChar + "utilSchema.xsd"), ]; ValidationResult r = v.ValidateInstance( Input.FromNode(xmlData) .Build()); return r.Problems; // return r.Valid; } } }