This repository has been archived by the owner on Mar 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIntegrationTests.cs
143 lines (129 loc) · 5.04 KB
/
IntegrationTests.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace CandyWrapperTests
{
[TestFixture]
public class IntegrationTests
{
private CandyWrapper _cw;
private const string URL = "http://demo.sugarcrm.com/sugarcrm/soap.php";
private const string USER = "will";
private const string PWD = "will";
private string _accountId;
[TestFixtureSetUp]
public void Setup()
{
_cw = new CandyWrapper(URL, USER, PWD);
}
[TestFixtureTearDown]
public void TearDown()
{
_cw.Dispose();
}
private string GetAccountId()
{
if (!string.IsNullOrEmpty(_accountId))
return _accountId;
List<SugarEntry> entries = _cw.GetEntryList(SugarModules.Accounts, string.Empty, string.Empty, 0, 1, 0);
return entries[0].Id;
}
[Test]
public void AccountListWithLargeOffsetShouldReturnNoEnteries()
{
List<SugarEntry> entries = _cw.GetEntryList(SugarModules.Accounts, string.Empty, string.Empty, 500, 0, 0);
Assert.IsNotNull(entries);
Assert.AreEqual(0, entries.Count);
}
[Test]
public void ListOfLeadsSetShouldNotSkipAnyLeads()
{
List<SugarEntry> entries1 = _cw.GetEntryList(SugarModules.Leads, string.Empty, string.Empty, 0, 3, 0);
List<SugarEntry> entries2 = _cw.GetEntryList(SugarModules.Leads, string.Empty, string.Empty, 2, 2, 0);
Assert.AreEqual(entries1[2], entries2[0]);
}
[Test]
public void SearchByModuleShouldReturnResults()
{
var modules = new List<string>();
modules.Add(SugarModules.Accounts);
modules.Add(SugarModules.Leads);
modules.Add(SugarModules.Opportunities);
//Seems to return 10 at most
List<SugarEntry> results = _cw.SearchByModule("a", modules.ToArray(), 0, 20);
Assert.IsNotNull(results);
Assert.IsNotEmpty(results);
Console.WriteLine(results.Count);
foreach (SugarEntry result in results)
Console.WriteLine(result.Id);
}
[Test]
public void SessionShouldBeValid()
{
Assert.IsNotNull(_cw.Session);
Assert.AreEqual(26, _cw.Session.Length, "Session string should be 26 characters long.");
}
[Test]
public void ShouldBeAbleToAssignedUserForAccount()
{
SugarEntry account = _cw.GetEntry(SugarModules.Accounts, GetAccountId());
string userId = account["assigned_user_id"];
Assert.IsNotEmpty(userId);
SugarEntry user = _cw.GetEntry(SugarModules.Users, userId);
Assert.IsNotNull(user);
Console.WriteLine(user);
}
[Test]
public void ShouldBeAbleToGetAccount()
{
SugarEntry entry = _cw.GetEntry(SugarModules.Accounts, GetAccountId());
Assert.IsNotNull(entry);
Assert.IsNotEmpty(entry);
Console.WriteLine(entry["name"]);
}
[Test]
public void DemonstarteUsingPattern() {
//Calls logout when done being used via IDisposable.
using (var cw = new CandyWrapper(URL, USER, PWD))
{
SugarEntry entry = cw.GetEntry(SugarModules.Accounts, GetAccountId());
Assert.IsNotNull(entry);
Assert.IsNotEmpty(entry);
Console.WriteLine(entry["name"]);
}
}
[Test]
public void ShouldBeAbleToGetAccountList()
{
List<SugarEntry> entries = _cw.GetEntryList(SugarModules.Accounts, string.Empty, string.Empty, 0, 10, 0);
Assert.IsNotNull(entries);
Assert.IsNotEmpty(entries);
foreach (SugarEntry entry in entries)
Console.WriteLine(entry["name"]);
}
[Test]
public void ShouldBeAbleToGetAvailableModules()
{
string[] modules = _cw.GetAvailableModules();
Assert.IsNotNull(modules);
Assert.IsNotEmpty(modules);
foreach (string module in modules)
Console.WriteLine(module);
}
[Test]
public void ShouldBeAbleToUpdateAccount()
{
var random = new Random();
var randonNumber = random.Next(0, 1000);
SugarEntry entry = _cw.GetEntry(SugarModules.Accounts, GetAccountId());
Assert.IsNotNull(entry);
Assert.IsNotEmpty(entry);
Console.WriteLine(entry["name"]);
entry["employees"] = randonNumber.ToString();
var test = _cw.SetEntry(entry);
Console.WriteLine(test);
entry = _cw.GetEntry(SugarModules.Accounts, GetAccountId());
Assert.AreEqual(randonNumber.ToString(), entry["employees"]);
}
}
}