Extract response exceptions
[smsapi-csharp.git] / smsapiTests / Contacts / GroupsTest.cs
blob0699bdbd8b498e1c7a3eefb47ac3bdf701791619
1 using Microsoft.VisualStudio.TestTools.UnitTesting;
2 using SMSApi.Api.Response;
4 namespace smsapiTests.Contacts
6 [TestClass]
7 public class GroupsTest : ContactsTestBase
9 private Group _group;
11 [TestCleanup]
12 public void Cleanup()
14 Groups groups = _factory.ListGroups().Execute();
15 foreach (Group group in groups.Collection)
17 _factory.DeleteGroup(group.Id).Execute();
21 [TestMethod]
22 public void CreateGroup()
24 Group group = _factory.CreateGroup().SetName("exampleGroup1").Execute();
26 Assert.AreEqual("exampleGroup1", group.Name);
27 Assert.IsNotNull(group.Id);
30 [TestMethod]
31 public void CreateGroupPermission()
33 GroupPermission groupPermission = _factory.CreateGroupPermission(_group.Id).
34 SetUsername(_username).
35 SetRead(true).
36 SetWrite(false).
37 SetSend(false).
38 Execute();
40 Assert.AreEqual(_username, groupPermission.Username);
43 [TestMethod]
44 public void EditGroup()
46 Group response = _factory.EditGroup(_group.Id).SetName("GroupY").Execute();
48 Assert.AreEqual(_group.Id, response.Id);
49 Assert.AreNotEqual(_group.Name, response.Name);
50 Assert.AreEqual("GroupY", response.Name);
51 Assert.AreEqual(_group.Description, response.Description);
53 if (string.IsNullOrEmpty(_group.Idx))
55 Assert.IsTrue(string.IsNullOrEmpty(response.Idx));
57 else
59 Assert.AreEqual(_group.Idx, response.Idx);
63 [TestMethod]
64 public void EditGroupPermission()
66 GroupPermission groupPermission = _factory.EditGroupPermission(_group.Id, _username).
67 SetRead(true).
68 SetWrite(true).
69 SetSend(true).
70 Execute();
72 Assert.IsTrue(groupPermission.Read);
73 Assert.IsTrue(groupPermission.Write);
74 Assert.IsTrue(groupPermission.Send);
77 [TestMethod]
78 public void GetGroup()
80 Group response = _factory.GetGroup(_group.Id).Execute();
82 Assert.AreEqual(_group.Id, response.Id);
83 Assert.AreEqual(_group.Name, response.Name);
84 Assert.AreEqual(_group.Description, response.Description);
86 if (string.IsNullOrEmpty(_group.Idx))
88 Assert.IsTrue(string.IsNullOrEmpty(response.Idx));
90 else
92 Assert.AreEqual(_group.Idx, response.Idx);
96 [TestMethod]
97 public void ListGroupPermissions()
99 _factory.ListGroupPermissions(_group.Id).Execute();
102 [TestMethod]
103 public void ListGroups()
105 _factory.ListGroups().Execute();
108 [TestMethod]
109 public void ListGroupsWithFilterByName()
111 Groups listResponse = _factory.ListGroups().SetName("exampleGroup").Execute();
113 Assert.AreEqual(1, listResponse.Collection.Count);
116 [TestMethod]
117 public void ListWithFilterByName_ShouldNotFound()
119 Groups listResponse = _factory.ListGroups().SetName("missingGroup").Execute();
121 Assert.AreEqual(0, listResponse.Collection.Count);
124 [TestInitialize]
125 public override void SetUp()
127 base.SetUp();
129 _group = _factory.CreateGroup().SetName("exampleGroup").Execute();