|
Title: resultset list assertions Post by: Christoph Schwarz on April 29, 2008, 03:27:10 pm Hi,
i am doing some assertions for a resultset that is a list that looks like this: <a:ResultSet xmlns:a="http://schemas.datacontract.org/2004/07/SecondTravel.Global.DataContract.Licence.v1_0" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://SecondTravel.Global.ServiceContract.Licence.v1_0.ILicence" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <a:LicenceDCResultItem> <a:FunctionalityCode>Users</a:FunctionalityCode> </a:LicenceDCResultItem> <a:LicenceDCResultItem> <a:FunctionalityCode>Global_Codes</a:FunctionalityCode> </a:LicenceDCResultItem> <a:LicenceDCResultItem> <a:FunctionalityCode>Global_Subscribe</a:FunctionalityCode> </a:LicenceDCResultItem> </a:ResultSet> now depending on the GUID in the database the order of the <a:FunctionalityCode> items change. is there a assertion except "Contains" that validates for the items and doesnt care about the order? i tried match content and Xpath match bot both are failing when the order changes. thanks Christoph Title: Re: resultset list assertions Post by: omatzura on April 29, 2008, 03:41:10 pm Hi Christoph,
you can use the XQuery assertion for this; create an XQuery that selects an ordered list of the items you want to test, and specify the expected results.. Get to grips with XQuery with something like http://www.w3schools.com/xquery/default.asp regards, /Ole eviware.com Title: Re: resultset list assertions Post by: Christoph Schwarz on May 07, 2008, 04:50:26 pm Thanks Ole,
this is working great now. here is the exact result and the according XQuery: <GetListResponse xmlns="http://SecondTravel.Global.ServiceContract.Licence.v1_0Package.ILicencePackage"> <GetListResult xmlns:a="http://schemas.datacontract.org/2004/07/SecondTravel.Global.DataContract.Licence.v1_0" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <ResultCode xmlns="http://schemas.datacontract.org/2004/07/SecondTravel.Library.Instrumentation.Errors">Successful</ResultCode> <Errors xmlns="http://schemas.datacontract.org/2004/07/SecondTravel.Library.Instrumentation.Errors"/> <Infos xmlns="http://schemas.datacontract.org/2004/07/SecondTravel.Library.Instrumentation.Errors"/> <Warnings xmlns="http://schemas.datacontract.org/2004/07/SecondTravel.Library.Instrumentation.Errors"/> <TransactionHandleName xmlns="http://schemas.datacontract.org/2004/07/SecondTravel.Library.Instrumentation.Errors"/> <a:ResultSet xmlns:a="http://schemas.datacontract.org/2004/07/SecondTravel.Global.DataContract.Licence.v1_0" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://SecondTravel.Global.ServiceContract.Licence.v1_0.ILicence" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <a:LicenceDCResultItem> <a:FunctionalityCode>Users</a:FunctionalityCode> </a:LicenceDCResultItem> <a:LicenceDCResultItem> <a:FunctionalityCode>Global_Codes</a:FunctionalityCode> </a:LicenceDCResultItem> <a:LicenceDCResultItem> <a:FunctionalityCode>Global_Subscribe</a:FunctionalityCode> </a:LicenceDCResultItem> </a:ResultSet> XQuery: declare namespace a='http://schemas.datacontract.org/2004/07/SecondTravel.Global.DataContract.Licence.v1_0'; declare namespace ns1='http://SecondTravel.Global.ServiceContract.Licence.v1_0Package.ILicencePackage'; <Licences> { for $z in //ns1:GetListResult/a:ResultSet/a:LicenceDCResultItem/a:FunctionalityCode/text() order by $z return <FunctionalityCodes>{data($z)}</FunctionalityCodes> } </Licences> this returns all functionalitycodes in a ordered list that then is compared with the expected result (in the same ordered list) hope this helps others finding into XQuery faster regards Christoph Title: Re: resultset list assertions Post by: omatzura on May 08, 2008, 02:21:47 am cool! Thanks for sharing!
/Ole eviware.com |