dynamics_crm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +104 -0
  8. data/Rakefile +9 -0
  9. data/dynamics_crm.gemspec +28 -0
  10. data/lib/dynamics_crm/client.rb +295 -0
  11. data/lib/dynamics_crm/metadata/attribute_metadata.rb +42 -0
  12. data/lib/dynamics_crm/metadata/entity_metadata.rb +24 -0
  13. data/lib/dynamics_crm/metadata/retrieve_all_entities_response.rb +21 -0
  14. data/lib/dynamics_crm/metadata/retrieve_attribute_response.rb +16 -0
  15. data/lib/dynamics_crm/metadata/retrieve_entity_response.rb +17 -0
  16. data/lib/dynamics_crm/metadata/xml_document.rb +39 -0
  17. data/lib/dynamics_crm/response/create_result.rb +15 -0
  18. data/lib/dynamics_crm/response/execute_result.rb +26 -0
  19. data/lib/dynamics_crm/response/result.rb +78 -0
  20. data/lib/dynamics_crm/response/retrieve_multiple_result.rb +38 -0
  21. data/lib/dynamics_crm/response/retrieve_result.rb +20 -0
  22. data/lib/dynamics_crm/version.rb +3 -0
  23. data/lib/dynamics_crm/xml/attributes.rb +163 -0
  24. data/lib/dynamics_crm/xml/column_set.rb +34 -0
  25. data/lib/dynamics_crm/xml/criteria.rb +54 -0
  26. data/lib/dynamics_crm/xml/entity.rb +61 -0
  27. data/lib/dynamics_crm/xml/entity_reference.rb +56 -0
  28. data/lib/dynamics_crm/xml/fault.rb +42 -0
  29. data/lib/dynamics_crm/xml/fetch_expression.rb +27 -0
  30. data/lib/dynamics_crm/xml/message_builder.rb +222 -0
  31. data/lib/dynamics_crm/xml/message_parser.rb +68 -0
  32. data/lib/dynamics_crm/xml/orders.rb +36 -0
  33. data/lib/dynamics_crm/xml/page_info.rb +38 -0
  34. data/lib/dynamics_crm/xml/query.rb +38 -0
  35. data/lib/dynamics_crm.rb +46 -0
  36. data/spec/fixtures/associate_response.xml +17 -0
  37. data/spec/fixtures/create_response.xml +19 -0
  38. data/spec/fixtures/delete_response.xml +16 -0
  39. data/spec/fixtures/disassociate_response.xml +17 -0
  40. data/spec/fixtures/fetch_xml_response.xml +120 -0
  41. data/spec/fixtures/receiver_fault.xml +27 -0
  42. data/spec/fixtures/request_security_token_response.xml +62 -0
  43. data/spec/fixtures/retrieve_account_all_columns.xml +402 -0
  44. data/spec/fixtures/retrieve_all_entities.xml +614 -0
  45. data/spec/fixtures/retrieve_attribute_identifier_response.xml +117 -0
  46. data/spec/fixtures/retrieve_attribute_picklist_response.xml +1097 -0
  47. data/spec/fixtures/retrieve_attribute_response.xml +126 -0
  48. data/spec/fixtures/retrieve_entity_response.xml +671 -0
  49. data/spec/fixtures/retrieve_multiple_result.xml +67 -0
  50. data/spec/fixtures/sender_fault.xml +34 -0
  51. data/spec/fixtures/update_response.xml +16 -0
  52. data/spec/fixtures/who_am_i_result.xml +35 -0
  53. data/spec/lib/client_spec.rb +230 -0
  54. data/spec/lib/metadata/entity_metadata_spec.rb +24 -0
  55. data/spec/lib/metadata/retrieve_all_entities_response_spec.rb +26 -0
  56. data/spec/lib/metadata/retrieve_attribute_response_spec.rb +65 -0
  57. data/spec/lib/metadata/retrieve_entity_response_spec.rb +24 -0
  58. data/spec/lib/response/execute_result_spec.rb +20 -0
  59. data/spec/lib/response/retrieve_multiple_spec.rb +34 -0
  60. data/spec/lib/response/retrieve_result_spec.rb +67 -0
  61. data/spec/lib/xml/attributes_spec.rb +39 -0
  62. data/spec/lib/xml/column_set_spec.rb +19 -0
  63. data/spec/lib/xml/entity_reference_spec.rb +47 -0
  64. data/spec/lib/xml/entity_spec.rb +63 -0
  65. data/spec/lib/xml/fault_spec.rb +41 -0
  66. data/spec/lib/xml/query_spec.rb +43 -0
  67. data/spec/spec_helper.rb +17 -0
  68. data/spec/support/fixture_helpers.rb +14 -0
  69. metadata +240 -0
@@ -0,0 +1,67 @@
1
+ <?xml version="1.0"?>
2
+ <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
3
+ <s:Header>
4
+ <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultipleResponse</a:Action>
5
+ <a:RelatesTo>urn:uuid:5a111cc5-6db9-4b9d-8f90-9479732fbac4</a:RelatesTo>
6
+ <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="bbb2e7e2-7bc1-453a-b08c-1fa7a52aac7b">00000000-0000-0000-0000-000000000000</ActivityId>
7
+ <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
8
+ <u:Timestamp u:Id="_0">
9
+ <u:Created>2014-02-18T07:23:45.031Z</u:Created>
10
+ <u:Expires>2014-02-18T07:28:45.031Z</u:Expires>
11
+ </u:Timestamp>
12
+ </o:Security>
13
+ </s:Header>
14
+ <s:Body>
15
+ <RetrieveMultipleResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
16
+ <RetrieveMultipleResult xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
17
+ <b:Entities>
18
+ <b:Entity>
19
+ <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
20
+ <b:KeyValuePairOfstringanyType>
21
+ <c:key>accountid</c:key>
22
+ <c:value xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/" i:type="d:guid">7bf2e032-ad92-e311-9752-6c3be5a87df0</c:value>
23
+ </b:KeyValuePairOfstringanyType>
24
+ </b:Attributes>
25
+ <b:EntityState i:nil="true"/>
26
+ <b:FormattedValues xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
27
+ <b:Id>7bf2e032-ad92-e311-9752-6c3be5a87df0</b:Id>
28
+ <b:LogicalName>account</b:LogicalName>
29
+ <b:RelatedEntities xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
30
+ </b:Entity>
31
+ <b:Entity>
32
+ <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
33
+ <b:KeyValuePairOfstringanyType>
34
+ <c:key>accountid</c:key>
35
+ <c:value xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/" i:type="d:guid">dbe9d7c9-2c98-e311-9752-6c3be5a87df0</c:value>
36
+ </b:KeyValuePairOfstringanyType>
37
+ </b:Attributes>
38
+ <b:EntityState i:nil="true"/>
39
+ <b:FormattedValues xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
40
+ <b:Id>dbe9d7c9-2c98-e311-9752-6c3be5a87df0</b:Id>
41
+ <b:LogicalName>account</b:LogicalName>
42
+ <b:RelatedEntities xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
43
+ </b:Entity>
44
+ <b:Entity>
45
+ <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
46
+ <b:KeyValuePairOfstringanyType>
47
+ <c:key>accountid</c:key>
48
+ <c:value xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/" i:type="d:guid">8ff0325c-a592-e311-b7f3-6c3be5a8a0c8</c:value>
49
+ </b:KeyValuePairOfstringanyType>
50
+ </b:Attributes>
51
+ <b:EntityState i:nil="true"/>
52
+ <b:FormattedValues xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
53
+ <b:Id>8ff0325c-a592-e311-b7f3-6c3be5a8a0c8</b:Id>
54
+ <b:LogicalName>account</b:LogicalName>
55
+ <b:RelatedEntities xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
56
+ </b:Entity>
57
+ </b:Entities>
58
+ <b:EntityName>account</b:EntityName>
59
+ <b:MinActiveRowVersion>-1</b:MinActiveRowVersion>
60
+ <b:MoreRecords>false</b:MoreRecords>
61
+ <b:PagingCookie>&lt;cookie page="1"&gt;&lt;accountid last="{BC73E579-2D98-E311-AD92-6C3BE5A8AD70}" first="{7BF2E032-AD92-E311-9752-6C3BE5A87DF0}" /&gt;&lt;/cookie&gt;</b:PagingCookie>
62
+ <b:TotalRecordCount>-1</b:TotalRecordCount>
63
+ <b:TotalRecordCountLimitExceeded>false</b:TotalRecordCountLimitExceeded>
64
+ </RetrieveMultipleResult>
65
+ </RetrieveMultipleResponse>
66
+ </s:Body>
67
+ </s:Envelope>
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0"?>
2
+ <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
3
+ <s:Header>
4
+ <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/UpdateOrganizationServiceFaultFault</a:Action>
5
+ <a:RelatesTo>urn:uuid:372eeb52-c480-41c0-888e-75d7e9a8ef07</a:RelatesTo>
6
+ <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="8e83ee2a-cdf3-46fd-9547-eaeac43cf9c8">00000000-0000-0000-0000-000000000000</ActivityId>
7
+ <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
8
+ <u:Timestamp u:Id="_0">
9
+ <u:Created>2014-02-17T23:44:47.657Z</u:Created>
10
+ <u:Expires>2014-02-17T23:49:47.657Z</u:Expires>
11
+ </u:Timestamp>
12
+ </o:Security>
13
+ </s:Header>
14
+ <s:Body>
15
+ <s:Fault>
16
+ <s:Code>
17
+ <s:Value>s:Sender</s:Value>
18
+ </s:Code>
19
+ <s:Reason>
20
+ <s:Text xml:lang="en-US">'account' entity doesn't contain attribute with Name = 'ticketsymbol'.</s:Text>
21
+ </s:Reason>
22
+ <s:Detail>
23
+ <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
24
+ <ErrorCode>-2147217149</ErrorCode>
25
+ <ErrorDetails xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
26
+ <Message>'account' entity doesn't contain attribute with Name = 'ticketsymbol'.</Message>
27
+ <Timestamp>2014-02-17T23:44:47.6574981Z</Timestamp>
28
+ <InnerFault i:nil="true"/>
29
+ <TraceText i:nil="true"/>
30
+ </OrganizationServiceFault>
31
+ </s:Detail>
32
+ </s:Fault>
33
+ </s:Body>
34
+ </s:Envelope>
@@ -0,0 +1,16 @@
1
+ <s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
2
+ <s:Header>
3
+ <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/UpdateResponse</a:Action>
4
+ <a:RelatesTo>urn:uuid:1599ecf4-1cce-49fc-b4a1-ebc7b64db6fa</a:RelatesTo>
5
+ <ActivityId CorrelationId="57d078bd-4b8f-4278-8283-c0928e37a773" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
6
+ <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
7
+ <u:Timestamp u:Id="_0">
8
+ <u:Created>2014-02-28T20:24:26.195Z</u:Created>
9
+ <u:Expires>2014-02-28T20:29:26.195Z</u:Expires>
10
+ </u:Timestamp>
11
+ </o:Security>
12
+ </s:Header>
13
+ <s:Body>
14
+ <UpdateResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"/>
15
+ </s:Body>
16
+ </s:Envelope>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0"?>
2
+ <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
3
+ <s:Header>
4
+ <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/ExecuteResponse</a:Action>
5
+ <a:RelatesTo>urn:uuid:71c49726-deb9-40a4-ba6e-1696ee284004</a:RelatesTo>
6
+ <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="fef27b87-9ea7-4906-88cb-ae88f088a138">00000000-0000-0000-0000-000000000000</ActivityId>
7
+ <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
8
+ <u:Timestamp u:Id="_0">
9
+ <u:Created>2014-02-18T00:09:32.062Z</u:Created>
10
+ <u:Expires>2014-02-18T00:14:32.062Z</u:Expires>
11
+ </u:Timestamp>
12
+ </o:Security>
13
+ </s:Header>
14
+ <s:Body>
15
+ <ExecuteResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
16
+ <ExecuteResult xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://schemas.microsoft.com/crm/2011/Contracts" i:type="c:WhoAmIResponse">
17
+ <b:ResponseName>WhoAmI</b:ResponseName>
18
+ <b:Results xmlns:d="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
19
+ <b:KeyValuePairOfstringanyType>
20
+ <d:key>UserId</d:key>
21
+ <d:value xmlns:e="http://schemas.microsoft.com/2003/10/Serialization/" i:type="e:guid">1bfa3886-df7e-468c-8435-b5adfb0441ed</d:value>
22
+ </b:KeyValuePairOfstringanyType>
23
+ <b:KeyValuePairOfstringanyType>
24
+ <d:key>BusinessUnitId</d:key>
25
+ <d:value xmlns:e="http://schemas.microsoft.com/2003/10/Serialization/" i:type="e:guid">4e87d619-838a-e311-89a7-6c3be5a80184</d:value>
26
+ </b:KeyValuePairOfstringanyType>
27
+ <b:KeyValuePairOfstringanyType>
28
+ <d:key>OrganizationId</d:key>
29
+ <d:value xmlns:e="http://schemas.microsoft.com/2003/10/Serialization/" i:type="e:guid">0140d597-e270-494a-89e1-bd0b43774e50</d:value>
30
+ </b:KeyValuePairOfstringanyType>
31
+ </b:Results>
32
+ </ExecuteResult>
33
+ </ExecuteResponse>
34
+ </s:Body>
35
+ </s:Envelope>
@@ -0,0 +1,230 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Client do
4
+ let(:subject) { DynamicsCRM::Client.new(organization_name: "tinderboxdev")}
5
+
6
+ describe "#authenticate" do
7
+ it "authenticates with username and password" do
8
+
9
+ subject.stub(:post).and_return(fixture("request_security_token_response"))
10
+
11
+ subject.authenticate('testing', 'password')
12
+
13
+ subject.instance_variable_get("@security_token0").should start_with("tMFpDJbJHcZnRVuby5cYmRbCJo2OgOFLEOrUHj+wz")
14
+ subject.instance_variable_get("@security_token1").should start_with("CX7BFgRnW75tE6GiuRICjeVDV+6q4KDMKLyKmKe9A8U")
15
+ subject.instance_variable_get("@key_identifier").should == "D3xjUG3HGaQuKyuGdTWuf6547Lo="
16
+ end
17
+
18
+ it "raises arugment error when no parameters are passed" do
19
+ expect { subject.authenticate() }.to raise_error(ArgumentError)
20
+ end
21
+
22
+ # This is only method in this suite that actually sends a POST message to Dynamics.
23
+ # This covers the post() and fault parsing logic.
24
+ it "fails to authenticate with invalid credentials" do
25
+ begin
26
+ subject.authenticate('testuser@orgnam.onmicrosoft.com', 'qwerty')
27
+ fail("Expected Fault to be raised")
28
+ rescue DynamicsCRM::XML::Fault => f
29
+ f.code.should == "S:Sender"
30
+ f.subcode.should == "wst:FailedAuthentication"
31
+ f.reason.should == "Authentication Failure"
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#retrieve" do
37
+ it "retrieves object by id" do
38
+
39
+ subject.stub(:post).and_return(fixture("retrieve_account_all_columns"))
40
+
41
+ result = subject.retrieve("account", "93f0325c-a592-e311-b7f3-6c3be5a8a0c8")
42
+
43
+ result.should be_a(DynamicsCRM::Response::RetrieveResult)
44
+ result.type.should == "account"
45
+ result.id.should == "93f0325c-a592-e311-b7f3-6c3be5a8a0c8"
46
+ result.name.should == "Adventure Works (sample)"
47
+ end
48
+ end
49
+
50
+ describe "#retrieve_multiple" do
51
+ it "retrieves multiple entities by criteria" do
52
+
53
+ subject.stub(:post).and_return(fixture("retrieve_multiple_result"))
54
+
55
+ result = subject.retrieve_multiple("account", ["name", "Equal", "Test Account"], columns=[])
56
+
57
+ result.should be_a(DynamicsCRM::Response::RetrieveMultipleResult)
58
+ result.entities.size.should == 3
59
+ entities = result.entities
60
+
61
+ entities[0].logical_name == "account"
62
+ entities[0].id.should == "7bf2e032-ad92-e311-9752-6c3be5a87df0"
63
+ entities[0].attributes["accountid"].should == "7bf2e032-ad92-e311-9752-6c3be5a87df0"
64
+
65
+ entities[1].attributes["accountid"].should == "dbe9d7c9-2c98-e311-9752-6c3be5a87df0"
66
+ entities[2].attributes["accountid"].should == "8ff0325c-a592-e311-b7f3-6c3be5a8a0c8"
67
+ end
68
+ end
69
+
70
+ describe "#fetch" do
71
+ it "uses FetchXML to retrieve multiple" do
72
+
73
+ subject.stub(:post).and_return(fixture("fetch_xml_response"))
74
+
75
+ xml = %Q{
76
+ <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
77
+ <entity name="new_tinderboxdocument">
78
+ <attribute name="new_tinderboxdocumentid" />
79
+ <attribute name="new_name" />
80
+ <attribute name="createdon" />
81
+ <order attribute="new_name" descending="false" />
82
+ <link-entity name="systemuser" from="systemuserid" to="createdby" alias="aa">
83
+ <link-entity name="account" from="createdby" to="systemuserid" alias="ab">
84
+ <link-entity name="transactioncurrency" from="transactioncurrencyid" to="transactioncurrencyid" alias="ac"></link-entity>
85
+ </link-entity>
86
+ </link-entity>
87
+ </entity>
88
+ </fetch>
89
+ }
90
+
91
+ result = subject.fetch(xml)
92
+
93
+ result.should be_a(DynamicsCRM::Response::ExecuteResult)
94
+
95
+ result["EntityCollection"].size.should == 3
96
+
97
+ entity = result["EntityCollection"].first
98
+ entity.id.should == "9c27cf91-ada3-e311-b64f-6c3be5a87df0"
99
+ entity.logical_name.should == "new_tinderboxdocument"
100
+ entity.attributes["new_tinderboxdocumentid"].should == entity.id
101
+ entity.attributes["new_name"].should == "6 orders of Product SKU JJ202"
102
+ end
103
+ end
104
+
105
+
106
+ describe "#create" do
107
+ it "creates new entity with parameters" do
108
+
109
+ subject.stub(:post).and_return(fixture("create_response"))
110
+
111
+ result = subject.create("account", {name: "Adventure Works"})
112
+
113
+ result.should be_a(DynamicsCRM::Response::CreateResult)
114
+ result.id.should == "c4944f99-b5a0-e311-b64f-6c3be5a87df0"
115
+ result.Id.should == "c4944f99-b5a0-e311-b64f-6c3be5a87df0"
116
+ end
117
+ end
118
+
119
+ describe "#update" do
120
+ it "updates entity by id" do
121
+
122
+ subject.stub(:post).and_return(fixture("update_response"))
123
+
124
+ result = subject.update("account", "c4944f99-b5a0-e311-b64f-6c3be5a87df0", {name: "Adventure Park"})
125
+
126
+ result.should be_a(DynamicsCRM::Response::UpdateResponse)
127
+ end
128
+ end
129
+
130
+ describe "#delete" do
131
+ it "deletes entity by id" do
132
+
133
+ subject.stub(:post).and_return(fixture("update_response"))
134
+
135
+ result = subject.delete("account", "c4944f99-b5a0-e311-b64f-6c3be5a87df0")
136
+
137
+ result.should be_a(DynamicsCRM::Response::DeleteResponse)
138
+ end
139
+ end
140
+
141
+ # Metadata Requests
142
+
143
+ describe "#retrieve_all_entities" do
144
+ it "retrieve entity list" do
145
+
146
+ subject.stub(:post).and_return(fixture("retrieve_all_entities"))
147
+
148
+ result = subject.retrieve_all_entities
149
+
150
+ result.should be_a(DynamicsCRM::Metadata::RetrieveAllEntitiesResponse)
151
+ result.entities.should_not be_nil
152
+
153
+ entities = result.entities
154
+ entities.size.should == 3
155
+
156
+ entities[0].LogicalName.should == "opportunity"
157
+ entities[1].LogicalName.should == "new_tinderboxdocument"
158
+ entities[2].LogicalName.should == "new_tinderboxcontent"
159
+ end
160
+ end
161
+
162
+ describe "#retrieve_entity" do
163
+ it "retrieve entity metadata" do
164
+
165
+ subject.stub(:post).and_return(fixture("retrieve_entity_response"))
166
+
167
+ result = subject.retrieve_entity("opportunity")
168
+
169
+ result.should be_a(DynamicsCRM::Metadata::RetrieveEntityResponse)
170
+ result.entity.should_not be_nil
171
+ entity = result.entity
172
+ entity.should be_a(DynamicsCRM::Metadata::EntityMetadata)
173
+
174
+ entity.LogicalName.should == "opportunity"
175
+ entity.PrimaryIdAttribute.should == "opportunityid"
176
+ entity.PrimaryNameAttribute.should == "name"
177
+ end
178
+ end
179
+
180
+ describe "#retrieve_attribute" do
181
+ it "retrieve attribute metadata" do
182
+
183
+ subject.stub(:post).and_return(fixture("retrieve_attribute_response"))
184
+
185
+ result = subject.retrieve_attribute("new_tinderboxdocument", "new_value")
186
+
187
+ result.should be_a(DynamicsCRM::Metadata::RetrieveAttributeResponse)
188
+ result.attribute.should_not be_nil
189
+ attribute = result.attribute
190
+
191
+ attribute.EntityLogicalName.should == "new_tinderboxdocument"
192
+ attribute.LogicalName.should == "new_value"
193
+ end
194
+ end
195
+
196
+ context "many-to-many relationships" do
197
+ let(:contacts) {
198
+ [ DynamicsCRM::XML::EntityReference.new("contact", "53291AAB-4A9A-E311-B097-6C3BE5A8DD60"),
199
+ DynamicsCRM::XML::EntityReference.new("contact", "3DEDA796-4A9A-E311-B097-6C3BE5A8DD60")]
200
+ }
201
+
202
+ describe "#associate" do
203
+ it "associates contacts with account" do
204
+ subject.stub(:post).and_return(fixture("associate_response"))
205
+
206
+ subject.associate("account", "7BF2E032-AD92-E311-9752-6C3BE5A87DF0", "contact_customer_accounts", contacts)
207
+ end
208
+ end
209
+
210
+ describe "#disassociate" do
211
+ it "disassociates contacts with accounts" do
212
+ subject.stub(:post).and_return(fixture("disassociate_response"))
213
+
214
+ subject.disassociate("account", "7BF2E032-AD92-E311-9752-6C3BE5A87DF0", "contact_customer_accounts", contacts)
215
+ end
216
+ end
217
+ end
218
+
219
+ describe "#who_am_i" do
220
+ it "returns user information" do
221
+ subject.stub(:post).and_return(fixture("who_am_i_result"))
222
+
223
+ response = subject.who_am_i
224
+ response.UserId.should == "1bfa3886-df7e-468c-8435-b5adfb0441ed"
225
+ response.BusinessUnitId.should == "4e87d619-838a-e311-89a7-6c3be5a80184"
226
+ response.OrganizationId.should == "0140d597-e270-494a-89e1-bd0b43774e50"
227
+ end
228
+ end
229
+
230
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Metadata::EntityMetadata do
4
+
5
+ describe 'initialization' do
6
+ subject {
7
+ doc = REXML::Document.new(fixture("retrieve_all_entities"))
8
+ entity = doc.get_elements("//d:EntityMetadata").first
9
+ DynamicsCRM::Metadata::EntityMetadata.new(entity)
10
+ }
11
+
12
+ context "parse attributes according to their type" do
13
+ it { subject.MetadataId.should == "30b0cd7e-0081-42e1-9a48-688442277fae" }
14
+ it { subject.LogicalName.should == "opportunity" }
15
+ it { subject.ObjectTypeCode.should == "3" }
16
+ it { subject.OwnershipType.should == "UserOwned" }
17
+ it { subject.PrimaryIdAttribute.should == "opportunityid" }
18
+ it { subject.PrimaryNameAttribute.should == "name" }
19
+ it { subject.attributes.should == [] }
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Metadata::RetrieveAllEntitiesResponse do
4
+
5
+ describe 'retrieve_all_entities' do
6
+ subject {
7
+ file = fixture("retrieve_all_entities")
8
+ DynamicsCRM::Metadata::RetrieveAllEntitiesResponse.new(file)
9
+ }
10
+
11
+ context "parse execute result" do
12
+ let(:opportunity) { subject.entities.first }
13
+ it { subject.ResponseName.should == "RetrieveAllEntities" }
14
+ it { subject.entities.size.should == 3 }
15
+ it { opportunity.MetadataId.should == "30b0cd7e-0081-42e1-9a48-688442277fae" }
16
+ it { opportunity.LogicalName.should == "opportunity" }
17
+ it { opportunity.ObjectTypeCode.should == "3" }
18
+ it { opportunity.OwnershipType.should == "UserOwned" }
19
+ it { opportunity.PrimaryIdAttribute.should == "opportunityid" }
20
+ it { opportunity.PrimaryNameAttribute.should == "name" }
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Metadata::RetrieveAttributeResponse do
4
+
5
+ describe 'retrieve_attribute_response' do
6
+ subject {
7
+ file = fixture("retrieve_attribute_response")
8
+ DynamicsCRM::Metadata::RetrieveAttributeResponse.new(file)
9
+ }
10
+
11
+ context "parse execute result" do
12
+ it { subject.ResponseName.should == "RetrieveAttribute" }
13
+ it { subject.attribute.MetadataId.should == "79194881-c699-e311-9752-6c3be5a87df0" }
14
+ it { subject.attribute.AttributeType.should == "Money" }
15
+ it { subject.attribute.LogicalName.should == "new_value" }
16
+ it { subject.attribute.IsPrimaryId.should == "false" }
17
+ it { subject.attribute.AttributeTypeName.Value.should == "MoneyType" }
18
+ it { subject.attribute.DisplayName.LocalizedLabels.LocalizedLabel.Label.should == "Value" }
19
+ end
20
+
21
+ end
22
+
23
+ describe '#picklist_attribute_metadata' do
24
+ subject {
25
+ file = fixture("retrieve_attribute_picklist_response")
26
+ DynamicsCRM::Metadata::RetrieveAttributeResponse.new(file)
27
+ }
28
+
29
+ context "parse execute result" do
30
+ it { subject.ResponseName.should == "RetrieveAttribute" }
31
+ it { subject.attribute.MetadataId.should == "ae00233e-70c0-4a1f-803f-03ff723e5440" }
32
+ it { subject.attribute.AttributeType.should == "Picklist" }
33
+ it { subject.attribute.LogicalName.should == "industrycode" }
34
+ it { subject.attribute.EntityLogicalName.should == "account" }
35
+ it { subject.attribute.AttributeTypeName.Value.should == "PicklistType" }
36
+ it { subject.attribute.picklist_options.should be_a(Hash) }
37
+ it {
38
+ subject.attribute.picklist_options.should have_key(1)
39
+ subject.attribute.picklist_options[1].should == "Accounting"
40
+ }
41
+ it {
42
+ subject.attribute.picklist_options.should have_key(33)
43
+ subject.attribute.picklist_options[33].should == "Wholesale"
44
+ }
45
+ end
46
+
47
+ end
48
+
49
+ describe '#identifier_attribute_metadata' do
50
+ subject {
51
+ file = fixture("retrieve_attribute_identifier_response")
52
+ DynamicsCRM::Metadata::RetrieveAttributeResponse.new(file)
53
+ }
54
+
55
+ context "parse execute result" do
56
+ it { subject.ResponseName.should == "RetrieveAttribute" }
57
+ it { subject.attribute.MetadataId.should == "f8cd5db9-cee8-4845-8cdd-cd4f504957e7" }
58
+ it { subject.attribute.AttributeType.should == "Uniqueidentifier" }
59
+ it { subject.attribute.LogicalName.should == "accountid" }
60
+ it { subject.attribute.EntityLogicalName.should == "account" }
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Metadata::RetrieveEntityResponse do
4
+
5
+ describe 'retrieve_entity_response' do
6
+ subject {
7
+ file = fixture("retrieve_entity_response")
8
+ DynamicsCRM::Metadata::RetrieveEntityResponse.new(file)
9
+ }
10
+
11
+ context "parse execute result" do
12
+ it { subject.ResponseName.should == "RetrieveEntity" }
13
+ it { subject.entity.MetadataId.should == "30b0cd7e-0081-42e1-9a48-688442277fae" }
14
+ it { subject.entity.LogicalName.should == "opportunity" }
15
+ it { subject.entity.ObjectTypeCode.should == "3" }
16
+ it { subject.entity.OwnershipType.should == "UserOwned" }
17
+ it { subject.entity.PrimaryIdAttribute.should == "opportunityid" }
18
+ it { subject.entity.PrimaryNameAttribute.should == "name" }
19
+
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Response::ExecuteResult do
4
+
5
+ describe 'who_am_i' do
6
+ subject {
7
+ file = fixture("who_am_i_result")
8
+ DynamicsCRM::Response::ExecuteResult.new(file)
9
+ }
10
+
11
+ context "parse execute result" do
12
+ it { subject.ResponseName.should == "WhoAmI" }
13
+ it { subject.UserId.should == "1bfa3886-df7e-468c-8435-b5adfb0441ed" }
14
+ it { subject.BusinessUnitId.should == "4e87d619-838a-e311-89a7-6c3be5a80184" }
15
+ it { subject.OrganizationId.should == "0140d597-e270-494a-89e1-bd0b43774e50" }
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Response::RetrieveMultipleResult do
4
+
5
+ describe 'initialization' do
6
+ subject {
7
+ xml = fixture("retrieve_multiple_result")
8
+ DynamicsCRM::Response::RetrieveMultipleResult.new(xml)
9
+ }
10
+
11
+ context "parse attributes according to their type" do
12
+
13
+ it { subject.EntityName.should == "account" }
14
+ it { subject.MinActiveRowVersion.should == -1}
15
+ it { subject.MoreRecords.should == false }
16
+ it { subject.PagingCookie.should include("cookie page=") }
17
+ it { subject.TotalRecordCount.should == -1 }
18
+ it { subject.TotalRecordCountLimitExceeded.should == false }
19
+ it { subject.entities.size.should == 3 }
20
+
21
+ it { subject.entities.first.to_hash.should == {
22
+ :attributes => {"accountid"=>"7bf2e032-ad92-e311-9752-6c3be5a87df0"},
23
+ :entity_state => nil,
24
+ :formatted_values => nil,
25
+ :id => "7bf2e032-ad92-e311-9752-6c3be5a87df0",
26
+ :logical_name => "account",
27
+ :related_entities => nil}
28
+ }
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Response::RetrieveResult do
4
+
5
+ describe 'initialization' do
6
+ subject {
7
+ file = fixture("retrieve_account_all_columns")
8
+ DynamicsCRM::Response::RetrieveResult.new(file)
9
+ }
10
+
11
+ context "parse attributes according to their type" do
12
+
13
+ it { subject.id.should == "93f0325c-a592-e311-b7f3-6c3be5a8a0c8" }
14
+ it { subject.type.should == "account" }
15
+ it { subject.exchangerate.should == 1.0 } # decimal
16
+ it { subject.modifiedon.should be_a(Time) } # datetime
17
+ it { subject.territorycode.should == 1} # OptionType
18
+ it { subject.importsequencenumber.should == 1} # int
19
+ it { subject.donotemail.should == false} # boolean
20
+ it { subject.revenue.should == 60000.00 } # Money
21
+ it { subject.modifiedby.should == {
22
+ "Id" => "1bfa3886-df7e-468c-8435-b5adfb0441ed",
23
+ "LogicalName" => "systemuser",
24
+ "Name" => "Joe Heth"} }
25
+
26
+ it { subject["id"].should == "93f0325c-a592-e311-b7f3-6c3be5a8a0c8" }
27
+ it { subject["type"].should == "account" }
28
+ end
29
+
30
+ context "parses Attributes list" do
31
+ it { subject.name.should == "Adventure Works (sample)" }
32
+ it { subject.websiteurl.should == "http://www.adventure-works.com/" }
33
+ it { subject.address1_city.should == "Santa Cruz" }
34
+
35
+ it { subject["name"].should == "Adventure Works (sample)" }
36
+ it { subject["websiteurl"].should == "http://www.adventure-works.com/" }
37
+ it { subject["address1_city"].should == "Santa Cruz" }
38
+ end
39
+
40
+ context "assignment" do
41
+ it "should assign through hash index" do
42
+ subject[:nothing].should be_nil
43
+ subject[:nothing] = "New Value"
44
+ subject[:nothing].should == "New Value"
45
+ subject.nothing.should == "New Value"
46
+ subject.Nothing.should == "New Value"
47
+ end
48
+ end
49
+
50
+ context "respond to hash methods" do
51
+
52
+ it "should has_key?" do
53
+ subject.has_key?("name").should be_true
54
+ subject.has_key?("type").should be_true
55
+ subject.has_key?("nothing").should be_false
56
+ end
57
+
58
+ it "should return keys" do
59
+ subject.keys.should include("type", "id", "accountid", "address1_city",
60
+ "address1_stateorprovince", "address1_postalcode", "websiteurl", "name",
61
+ "address1_line1", "address1_country", "address1_composite")
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end