-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlertServiceTest.cs
128 lines (101 loc) · 4.86 KB
/
AlertServiceTest.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
using LetsBuyLocal.SDK.Services;
using LetsBuyLocal.SDK.Shared;
using LetsBuyLocal.SDK.Tests.Shared;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LetsBuyLocal.SDK.Tests
{
[TestClass]
public class AlertServiceTest
{
[TestMethod]
public void CreateAlertTest()
{
var svc = new AlertService();
//Create a new store for this test.
var userSvc = new UserService();
var owner = TestingHelper.NewUser(userSvc, true);
string category = TestingHelper.GetRandomStoreCategory();
var store = TestingHelper.NewStore(category, Colors.Green, Colors.DarkOrange, owner.Id);
//Create 3 different types of alerts for this test.
var alertS = TestingHelper.NewAlert(svc, AlertTypes.StoreAlert, store.Id);
var alertD = TestingHelper.NewAlert(svc, AlertTypes.DealAlert, store.Id);
var alertC = TestingHelper.NewAlert(svc, AlertTypes.CouponAlert, store.Id);
Assert.IsNotNull(alertS);
Assert.IsNotNull(alertD);
Assert.IsNotNull(alertC);
}
[TestMethod]
public void GetAlertByIdTest()
{
var svc = new AlertService();
//Create new store for this test.
var userSvc = new UserService();
var owner = TestingHelper.NewUser(userSvc, true);
string category = TestingHelper.GetRandomStoreCategory();
var store = TestingHelper.NewStore(category, Colors.Green, Colors.DarkOrange, owner.Id);
//Create 3 different types of alerts for this test.
var alertS = TestingHelper.NewAlert(svc, AlertTypes.StoreAlert, store.Id);
var alertD = TestingHelper.NewAlert(svc, AlertTypes.DealAlert, store.Id);
var alertC = TestingHelper.NewAlert(svc, AlertTypes.CouponAlert, store.Id);
//Get the 3 different types of alerts
var respS = svc.GetAlertById(alertS.Id);
var respD = svc.GetAlertById(alertD.Id);
var respC = svc.GetAlertById(alertC.Id);
Assert.IsNotNull(respS.Object);
Assert.IsNotNull(respD.Object);
Assert.IsNotNull(respC.Object);
}
[TestMethod]
public void GetAlertListForStoreByTypeTest()
{
var svc = new AlertService();
//Create a new store & alert for this test.
var userSvc = new UserService();
var owner = TestingHelper.NewUser(userSvc, true);
string category = TestingHelper.GetRandomStoreCategory();
var store = TestingHelper.NewStore(category, Colors.Green, Colors.Blue, owner.Id);
var alertA = TestingHelper.NewAlert(svc, AlertTypes.StoreAlert, store.Id);
var resp = svc.GetAlertListForStoreByType(store.Id, alertA.Type);
Assert.IsNotNull(resp.Object);
}
[TestMethod]
public void GetAlertListForUserByStoreByTypeTest()
{
var svc = new AlertService();
//Create a user for this test
var userSvc = new UserService();
var user = TestingHelper.NewUser(userSvc, false);
//Create a new store
var owner = TestingHelper.NewUser(userSvc, true);
string category = TestingHelper.GetRandomStoreCategory();
var store = TestingHelper.NewStore(category, Colors.Green, Colors.DarkOrange, owner.Id);
//Create 2 types of alerts for the store
//Should get
var storeAlertA = TestingHelper.NewAlert(svc, AlertTypes.StoreAlert, store.Id);
var storeAlertB = TestingHelper.NewAlert(svc, AlertTypes.StoreAlert, store.Id);
//Should not get
var couponAlert = TestingHelper.NewAlert(svc, AlertTypes.CouponAlert, store.Id);
//Alerts created above are not reduntant code. Creating conditions of test.
var resp = svc.GetAlertListForUserByStoreByType(store.Id, AlertTypes.StoreAlert, user.Id);
Assert.IsNotNull(resp.Object);
Assert.AreEqual(2, resp.Object.Count);
}
[TestMethod]
public void DeleteUserAlertTest()
{
var svc = new AlertService();
//Create a user for this test
var userSvc = new UserService();
var user = TestingHelper.NewUser(userSvc, false);
//Create a new store
var owner = TestingHelper.NewUser(userSvc, true);
string category = TestingHelper.GetRandomStoreCategory();
var store = TestingHelper.NewStore(category, Colors.Green, Colors.DarkOrange, owner.Id);
//Create an alert for the store
var alert = TestingHelper.NewAlert(svc, AlertTypes.StoreAlert, store.Id);
//Now delete it
var resp = svc.DeleteUserAlert(alert.Id, user.Id);
Assert.IsTrue(resp.Object);
}
}
}