public void Projection_Mapping_Fails_For_Missing_To_Attribute_In_Xml() { string xmlCfg = "<otis-mapping>" + "<class name=\"Otis.Tests.XmlUserDTO, Otis.Tests\" source=\"Otis.Tests.Entity.User, Otis.Tests\" >" + " <member name=\"Gender\" expression=\"$UserGender\">" + " <map from=\"['W']\" to=\"\" />" + " </member>;" + "</class>" + "</otis-mapping>"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlCfg); XmlNodeList nodes = xmlDoc.SelectNodes("//member")[0].SelectNodes("map"); try { XmlMappingDescriptionProvider.BuildProjections(null, nodes); } catch (OtisException e) { if (e.Message.Contains("Invalid projection. Attribute 'to' in XML projection mapping must not be empty")) { return; // success } } Assert.Fail("Tested method didn't throw an exception!"); }
private void BuildXmlProjections(string xmlCfg) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlCfg); XmlNodeList xmlGender = xmlDoc.SelectNodes("//member")[0].SelectNodes("map"); ProjectionInfo projections = XmlMappingDescriptionProvider.BuildProjections(m_desc, xmlGender); }
public void Parse_Valid_Xml_Mapping() { string xmlCfg = "<otis-mapping>" + "<class name=\"Otis.Tests.XmlUserDTO, Otis.Tests\" source=\"Otis.Tests.Entity.User, Otis.Tests\" >" + " <member name=\"Gender\" expression=\"$UserGender\">" + " <map from=\"['M']\" to=\"Male\" />" + " <map from=\"['W']\" to=\"Female\" />" + " </member>" + " <member name=\"GenderCode\" expression=\"$UserGender\">" + " <map to=\"['M']\" />" + " <map to=\"['W']\" />" + " </member>;" + "</class>" + "</otis-mapping>"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlCfg); XmlNodeList members = xmlDoc.SelectNodes("//member"); XmlNodeList xmlGender = members[0].SelectNodes("map"); ProjectionInfo projections = XmlMappingDescriptionProvider.BuildProjections(m_desc, xmlGender); Assert.AreEqual(2, projections.Count); Assert.AreEqual("Otis.Tests.Gender.Male", projections["\"M\""]); Assert.AreEqual("Otis.Tests.Gender.Female", projections["\"W\""]); m_desc.Type = typeof(string); m_desc.OwnerType = typeof(XmlUserDTO); m_desc.Member = "GenderCode"; XmlNodeList xmlGenderCode = members[1].SelectNodes("map"); projections = XmlMappingDescriptionProvider.BuildProjections(m_desc, xmlGenderCode); Assert.AreEqual(2, projections.Count); Assert.AreEqual("\"M\"", projections["\"M\""]); Assert.AreEqual("\"W\"", projections["\"W\""]); }