- Log in to post comments
User bio
404 bio not found
Member since Nov 9, 2021
Posts:
Amaury has not published any posts yet.
Replies:
Certifications & Credly badges:
Amaury has no Certifications & Credly badges yet.
Followers:
Amaury has no followers yet.
Following:
Amaury has not followed anybody yet.
Hello Corentin,
I took your code as base and improved it a bit to compare complex object:
ClassMethod CompareObjects(expectedObject As%RegisteredObject, actualObject As%RegisteredObject) As%Status { Set status= $$$OKSet returnValue = 1Try{ // check if same class Set className = $CLASSNAME(expectedObject) If (className '= $CLASSNAME(actualObject)) { Set returnValue = 0Set ^||differences(expectedObject,actualObject) = "not same class" } If (returnValue) { // Get the definition to browse propertiesSet classDef = ##class(%Library.ClassDefinition).%OpenId(className) Set propertiesDef = classDef.Properties // Check the value for each propertyFor i = 1:1:propertiesDef.Count() { Set propertyName = propertiesDef.GetAt(i).Name Set propertyValueExpected = $PROPERTY(expectedObject,propertyName) Set propertyValueActual=$PROPERTY(actualObject,propertyName) // if different, supply the variable difference with the name of property + valueIf$ISOBJECT(propertyValueExpected){ If propertyValueExpected.%Extends("%Collection.Super"){ For ii=1:1:propertyValueExpected.Count(){ Set tSC= ..CompareObjects(propertyValueExpected.GetAt(ii),propertyValueActual.GetAt(ii)) } } Else{ Set tSC= ..CompareObjects(propertyValueExpected,propertyValueActual) } } Else{ If ((propertyValueExpected '= "") && (propertyValueExpected '= propertyValueActual)) { Set ^||differences(expectedObject,propertyName)=propertyValueExpected _ " != " _ propertyValueActual } } } } }Catch e{ Set status=e.AsStatus() } Quit status } ClassMethod AssertObjectEquals(expectedObject As%RegisteredObject, actualObject As%RegisteredObject, Output msg) As%Status { Set status=$$$OKSet status=..CompareObjects(expectedObject,actualObject) If$DATA(^||differences){ Set key=$ORDER(^||differences("")) Set key2=$ORDER(^||differences(key,"")) Set msg=""While key'=""{ While key2'=""{ Set msg = msg_"; "_key2_": "_^||differences(key,key2) Set key2=$ORDER(^||differences(key,key2)) } Set key=$ORDER(^||differences(key)) Set:(key'="") key2=$ORDER(^||differences(key,"")) } If$LENGTH(msg){ Quit$$$ERROR(1,"Objects not equal") } } Quit status }Please give me your opinion if there's anything to improve