Extract response exceptions
[smsapi-csharp.git] / smsapiTests / SmsTest.cs
blob938c664c6bae39d14ab522fd6dc77af129cf4089
1 using System;
2 using System.Threading.Tasks;
3 using Microsoft.VisualStudio.TestTools.UnitTesting;
4 using SMSApi.Api;
5 using SMSApi.Api.Response;
7 namespace smsapiTests
9 [TestClass]
10 public class SmsTest : TestBase
12 private SMSFactory _factory;
14 [TestMethod]
15 public void DeletingSentMessage_ExceptionThrown()
17 Status sendResponse =
18 _factory.ActionSend().SetText("test message").SetTo(_validTestNumber).Execute();
20 string[] ids = new string[sendResponse.Count];
22 for (int i = 0; i < sendResponse.List.Count; i++)
24 ids[i] = sendResponse.List[i].ID;
27 Assert.ThrowsException<ActionException>(() => _factory.ActionDelete().Id(ids[0]).Execute());
30 [TestMethod]
31 public void ScheduledSend_Get_Delete()
33 Status sendResponse =
34 _factory.ActionSend().
35 SetText("test message").
36 SetTo(_validTestNumber).
37 SetDateSent(DateTime.Now.AddHours(2)).
38 Execute();
40 Assert.AreEqual(1, sendResponse.Count);
41 Assert.IsTrue(sendResponse.List[0].Points > 0, "Points must be greather then 0");
42 Assert.IsNotNull(sendResponse.Message);
43 Assert.IsNotNull(sendResponse.Parts);
45 string[] ids = new string[sendResponse.Count];
47 for (int i = 0, l = 0; i < sendResponse.List.Count; i++)
49 if (!sendResponse.List[i].isError())
51 //Nie wystąpił błąd podczas wysyłki (numer|treść|parametry... prawidłowe)
52 if (!sendResponse.List[i].isFinal())
54 //Status nie jest koncowy, może ulec zmianie
55 ids[l] = sendResponse.List[i].ID;
56 l++;
61 Status getResponse =
62 _factory.ActionGet().Ids(ids).Execute();
64 Assert.AreEqual(sendResponse.Count, getResponse.Count);
65 Assert.AreEqual(_validTestNumber, getResponse.List[0].Number);
66 Assert.AreEqual(sendResponse.List[0].ID, getResponse.List[0].ID);
67 Assert.AreEqual(sendResponse.List[0].IDx, getResponse.List[0].IDx);
68 Assert.AreEqual(sendResponse.List[0].Points, getResponse.List[0].Points);
69 Assert.AreEqual(sendResponse.List[0].Status, getResponse.List[0].Status);
71 Countable deletedResponse =
72 _factory.ActionDelete().Id(ids[0]).Execute();
74 Assert.AreEqual(sendResponse.Count, deletedResponse.Count);
77 [TestMethod]
78 public void SendMessageWithParams()
80 Status sendResponse =
81 _factory.ActionSend().
82 SetText("test [%1%] message [%2%]").
83 SetTo(_validTestNumber).
84 SetParam(0, "par1").
85 SetParam(1, "par2").
86 SetTest().
87 Execute();
89 Assert.AreEqual(1, sendResponse.Count);
90 Assert.IsTrue(sendResponse.List[0].Points > 0, "Points must be greather then 0");
91 Assert.IsNotNull(sendResponse.List[0].ID);
94 [TestInitialize]
95 public override void SetUp()
97 base.SetUp();
98 _factory = new SMSFactory(_client, _proxyAddress);