-
-
Save distributedlife/7446021 to your computer and use it in GitHub Desktop.
distributedlife.com blog post code snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lr_save_string (MyCharStarString, "MyParameter") ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SetParameterValue ("whoIsAwesome", "SomeBodyElse") ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MyAwesomeService_ExtractResult_IsAwesome (void) | |
| { | |
| //always make sure we reset our values before use | |
| lr_set ("", "ResultValue") ; | |
| lr_xml_get_values | |
| ( | |
| "XML={response}", | |
| "ValueParam=ResultValue", | |
| "Query=/Envelope/Body/{Response}/{Result}", | |
| LAST | |
| ) ; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lr_get ("{ResultValue}") ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MyAwesomeService_ExtractResult_GetAwesomePerson (void) | |
| { | |
| lr_set ("", "Result_Name") ; | |
| lr_set ("", "Result_Address") ; | |
| lr_set ("", "Result_MobileNumber") ; | |
| lr_xml_get_values | |
| ( | |
| "XML={response}", | |
| "ValueParam=Result_Name", | |
| "Query=/Envelope/Body/{Response}/{Result}/Name", | |
| LAST | |
| ) ; | |
| lr_xml_get_values | |
| ( | |
| "XML={response}", | |
| "ValueParam=Result_Address", | |
| "Query=/Envelope/Body/{Response}/{Result}/Address", | |
| LAST | |
| ) ; | |
| lr_xml_get_values | |
| ( | |
| "XML={response}", | |
| "ValueParam=Result_MobileNumber", | |
| "Query=/Envelope/Body/{Response}/{Result}/MobileNumber", | |
| LAST | |
| ) ; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MyAwesomeService_ExtractResult_GetAwesomePeople(void) | |
| { | |
| //the result is an array (the AwesomePeople node is arrayed) | |
| //Parameters are stored using the name: Result_AwesomePeople_i_FieldName | |
| // i is the index number in the array | |
| // FieldName is the name of the property attached to the returned object | |
| unsigned int ResultCount = 0 ; | |
| unsigned int i = 0 ; | |
| ResultCount = lr_xml_extract | |
| ( | |
| "XML={response}", | |
| "Query=/Envelope/Body/{Response}/{Result}/AwesomePeople", | |
| "XMLFragmentParam=__Ignore", "NotFound=Continue", "SelectAll=Yes", | |
| LAST | |
| ) ; | |
| //save the result count for use in the test | |
| lr_save_int (ResultCount, "ResultCount") ; | |
| //don't extract results if we don't have any | |
| if (ResultCount == 0) | |
| { | |
| return ; | |
| } | |
| for (i = 1; i <= ResultCount; i++) | |
| { | |
| //build parameter name prefix | |
| lr_save_int (i, "__i") ; | |
| lr_set ("", lr_get ("Result_AwesomePeople_{__i}_Name")) ; | |
| lr_set ("", lr_get ("Result_AwesomePeople_{__i}_Address")) ; | |
| lr_set ("", lr_get ("Result_AwesomePeople_{__i}_MobileNumber")) ; | |
| lr_xml_get_values | |
| ( | |
| "XML={response}", | |
| lr_get ("ValueParam=Result_AwesomePeople_{__i}_Name"), | |
| lr_get ("Query=/Envelope/Body/{Response}/{Result}/AwesomePeople[{__i}]/Name"), | |
| LAST | |
| ) ; | |
| lr_xml_get_values | |
| ( | |
| "XML={response}", | |
| lr_get ("ValueParam=Result_AwesomePeople_{__i}_Address"), | |
| lr_get ("Query=/Envelope/Body/{Response}/{Result}/AwesomePeople[{__i}]/Address"), | |
| LAST | |
| ) ; | |
| lr_xml_get_values | |
| ( | |
| "XML={response}", | |
| lr_get ("ValueParam=Result_AwesomePeople_{__i}_MobileNumber"), | |
| lr_get ("Query=/Envelope/Body/{Response}/{Result}/AwesomePeople[{__i}]/MobileNumber"), | |
| LAST | |
| ) ; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Result_ + ObjectName_ + i_ + FieldName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Result_ + ObjectName_ + i_ ChildObjectName_ + j_ + FieldName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lr_get ("{Result_AwesomePeople_1_Name}") ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Fixtures | |
| SetDefaultParameters () ; | |
| SetParameterValue ("WhoIsAwesome", "Distributedlife") ; | |
| CallService () ; | |
| ... | |
| ExtractResult () ; | |
| //Result Validation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MyCharStarString = lr_eval_string ("{MyParameter}") ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MyConstCharStarString = lr_eval_string ("SELECT {column} FROM {table}") ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| web_service_call | |
| ( | |
| "StepName={Service}::{Method}", | |
| "SOAPMethod={Service}|{Binding}|{Method}", | |
| "ResponseParam=response", | |
| "Service={Service}", | |
| "ExpectedResponse=SoapResult", | |
| BEGIN_ARGUMENTS, | |
| END_ARGUMENTS, | |
| BEGIN_RESULT, | |
| END_RESULT, | |
| LAST | |
| ); | |
| //Validate results | |
| lr_xml_extract | |
| ( | |
| "XML={response}", | |
| "FastQuery=Envelope/Body/{Response}/{Result}/path/to/node", | |
| "XMLFragmentParam=XmlBlob", | |
| LAST | |
| ); | |
| success = lr_xml_find | |
| ( | |
| "XML={response}", | |
| "Query=/Envelope/Body/{Response}/{Result}/path/to/node", | |
| "Value=VerifiedAgainstMe", | |
| "NotFound=Continue", | |
| LAST | |
| ); | |
| if (!success) | |
| { | |
| lr_error_message (“all aboard the failboat!”) ; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SetDefaultParameters () ; | |
| CallService () ; | |
| ... | |
| ExtractResult () ; | |
| VerifyStringsAreEqual (“Result_Path_To_Node”, “VerifiedAgainstMe”) ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void CallService (void) | |
| { | |
| if (StringsAreEqual (lr_get ("{Service}"), "MyAwesomeService")) | |
| { | |
| MyAwesomeService () ; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MyAwesomeService (void) | |
| { | |
| if (StringsAreEqual (lr_get ("{Method}"), "IsAwesome")) | |
| { | |
| MyAwesomeService_IsAwesome () ; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MyAwesomeService_IsAwesome (void) | |
| { | |
| web_service_call | |
| ( | |
| "StepName={Service}::{Method}", | |
| "SOAPMethod={Service}|{Binding}|{Method}", | |
| "ResponseParam=response", | |
| "Service={Service}", | |
| "ExpectedResponse=AnySoap", | |
| BEGIN_ARGUMENTS, | |
| "whoIsAwesome={whoIsAwesome}”, | |
| END_ARGUMENTS, | |
| BEGIN_RESULT, | |
| END_RESULT, | |
| LAST | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MyAwesomeService_SetDefaultParameters_IsAwesome (void) | |
| { | |
| lr_set ("distributedlife", "whoIsAwesome"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment