-
Notifications
You must be signed in to change notification settings - Fork 72
/
ActionTests.cs
112 lines (87 loc) · 4.45 KB
/
ActionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using System.Dynamic;
using System.Collections.Generic;
namespace Xrm.Tools.WebAPI.Test
{
[TestClass]
public class ActionTests : UnitTestBaseClass
{
[TestMethod]
public void TestWinOpportunity()
{
Task.Run(async () =>
{
var api = GetAPI();
dynamic account = new ExpandoObject();
account.name = "test " + DateTime.Now.ToString();
Guid accountID = await api.Create("accounts", account);
dynamic contact = new ExpandoObject();
contact.firstname = "test " + DateTime.Now.ToString();
contact.lastname = "test " + DateTime.Now.ToString();
Guid contactID = await api.Create("contacts", contact);
dynamic opportunity = new ExpandoObject();
var oppIndexer = opportunity as IDictionary<string, Object>;
opportunity.name = "Test opportunity " + DateTime.Now.ToString();
oppIndexer["customerid_account@odata.bind"] = "/accounts(" + accountID.ToString() + ")";
oppIndexer["parentcontactid@odata.bind"] = "/contacts(" + contactID.ToString() + ")";
Guid oppID = await api.Create("opportunities", opportunity);
dynamic opportClose = new ExpandoObject();
var opportCloseIndexer = opportClose as IDictionary<string, Object>;
opportClose.subject = "Won Opportunity";
opportCloseIndexer["opportunityid@odata.bind"] = "/opportunities(" + oppID.ToString() + ")";
dynamic lostOpportParams = new ExpandoObject();
lostOpportParams.Status = 3;
lostOpportParams.OpportunityClose = opportClose;
await api.ExecuteAction("WinOpportunity", lostOpportParams);
System.Diagnostics.Trace.WriteLine("finished");
}).Wait();
}
[TestMethod]
public void TestLostOpportunity()
{
Task.Run(async () =>
{
var api = GetAPI();
dynamic account = new ExpandoObject();
account.name = "test " + DateTime.Now.ToString();
Guid accountID = await api.Create("accounts", account);
dynamic contact = new ExpandoObject();
contact.firstname = "test " + DateTime.Now.ToString();
contact.lastname = "test " + DateTime.Now.ToString();
Guid contactID = await api.Create("contacts", contact);
dynamic opportunity = new ExpandoObject();
var oppIndexer = opportunity as IDictionary<string, Object>;
opportunity.name = "Test opportunity " + DateTime.Now.ToString();
oppIndexer["customerid_account@odata.bind"] = "/accounts(" + accountID.ToString() + ")";
oppIndexer["parentcontactid@odata.bind"] = "/contacts(" + contactID.ToString() + ")";
Guid oppID = await api.Create("opportunities", opportunity);
dynamic opportClose = new ExpandoObject();
var opportCloseIndexer = opportClose as IDictionary<string, Object>;
opportClose.subject = "Lost Opportunity";
opportCloseIndexer["opportunityid@odata.bind"] = "/opportunities(" + oppID.ToString() +")";
dynamic lostOpportParams = new ExpandoObject();
lostOpportParams.Status = 4;
lostOpportParams.OpportunityClose = opportClose;
await api.ExecuteAction("LoseOpportunity", lostOpportParams);
System.Diagnostics.Trace.WriteLine("finished");
}).Wait();
}
[TestMethod]
public void TestCalculateRollup()
{
Task.Run(async () =>
{
var api = GetAPI();
dynamic voteCountUpdate = new ExpandoObject();
voteCountUpdate.Target = new ExpandoObject();
var ivote = voteCountUpdate.Target as IDictionary<string, Object>;
ivote["@odata.id"] = "ctccrm_ideas(19dc848b-1c5e-e711-8112-e0071b66aea1)";
voteCountUpdate.FieldName = "ctccrm_votes";
await api.ExecuteFunction("CalculateRollupField", voteCountUpdate);
System.Diagnostics.Trace.WriteLine("finished");
}).Wait();
}
}
}