forked from umbraco/Umbraco-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskTypeTest.cs
231 lines (203 loc) · 7.24 KB
/
TaskTypeTest.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using umbraco.cms.businesslogic.task;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using System.Linq;
using umbraco.DataLayer;
namespace Umbraco.LegacyTests
{
/// <summary>
///This is a test class for TaskTypeTest and is intended
///to contain all TaskTypeTest Unit Tests
///</summary>
[TestClass()]
public class TaskTypeTest
{
/// <summary>
/// Test the constructor to throw an exception when the object is not found by id
///</summary>
[TestMethod()]
[ExpectedException(typeof(ArgumentException))]
public void TaskType_Not_Found_Constructor1()
{
TaskType u = new TaskType(-1111);
}
/// <summary>
/// Test the constructor to throw an exception when the object is not found by id
///</summary>
[TestMethod()]
[ExpectedException(typeof(ArgumentException))]
public void TaskType_Not_Found_Constructor2()
{
TaskType u = new TaskType(Guid.NewGuid().ToString("N"));
}
/// <summary>
/// Creates a new task type, creates some tasks with it, then deletes the type. ensure that all tasks associated are removed.
/// </summary>
[TestMethod()]
public void TaskType_Make_New_Assign_Tasks_And_Remove()
{
TaskType tt = new TaskType();
tt.Alias = Guid.NewGuid().ToString("N");
tt.Save();
Assert.IsTrue(tt.Id > 0);
Task t = new Task();
t.Comment = Guid.NewGuid().ToString("N");
t.Node = Document.GetRootDocuments().First();
t.ParentUser = m_User;
t.User = m_User;
t.Type = TaskType.GetAll().First();
t.Save();
//delete the task type
tt.Delete();
//ensure they're gone
Assert.AreEqual(0, Task.GetTasksByType(tt.Id).Count);
//ensure the type is gone
Assert.AreEqual(0, TaskType.GetAll().Where(x => x.Id == tt.Id).Count());
}
/// <summary>
/// Ensures that duplicate task type names are not allowed either by an update or an insert
/// </summary>
[TestMethod()]
public void TaskType_Make_Duplicate()
{
var alias = Guid.NewGuid().ToString("N");
var tt = new TaskType();
tt.Alias = alias;
tt.Save();
//try to insert a duplicate
var tt2 = new TaskType();
tt2.Alias = alias;
var hasException = false;
try
{
tt2.Save();
}
catch (SqlHelperException)
{
hasException = true;
}
Assert.IsTrue(hasException);
//try to update to a duplicate
var tt3 = new TaskType();
tt3.Alias = Guid.NewGuid().ToString("N");
tt3.Save();
tt3.Alias = alias;
hasException = false;
try
{
tt3.Save();
}
catch (SqlHelperException)
{
hasException = true;
}
Assert.IsTrue(hasException);
//now remove the ones we've created
tt.Delete();
tt3.Delete();
}
private User m_User = new User(0);
#region Tests to write
///// <summary>
/////A test for TaskType Constructor
/////</summary>
//[TestMethod()]
//public void TaskTypeConstructorTest1()
//{
// string TypeAlias = string.Empty; // TODO: Initialize to an appropriate value
// TaskType target = new TaskType(TypeAlias);
// Assert.Inconclusive("TODO: Implement code to verify target");
//}
///// <summary>
/////A test for TaskType Constructor
/////</summary>
//[TestMethod()]
//public void TaskTypeConstructorTest2()
//{
// TaskType target = new TaskType();
// Assert.Inconclusive("TODO: Implement code to verify target");
//}
///// <summary>
/////A test for GetAll
/////</summary>
//[TestMethod()]
//public void GetAllTest()
//{
// IEnumerable<TaskType> expected = null; // TODO: Initialize to an appropriate value
// IEnumerable<TaskType> actual;
// actual = TaskType.GetAll();
// Assert.AreEqual(expected, actual);
// Assert.Inconclusive("Verify the correctness of this test method.");
//}
///// <summary>
/////A test for Save
/////</summary>
//[TestMethod()]
//public void SaveTest()
//{
// TaskType target = new TaskType(); // TODO: Initialize to an appropriate value
// target.Save();
// Assert.Inconclusive("A method that does not return a value cannot be verified.");
//}
///// <summary>
/////A test for Alias
/////</summary>
//[TestMethod()]
//public void AliasTest()
//{
// TaskType target = new TaskType(); // TODO: Initialize to an appropriate value
// string expected = string.Empty; // TODO: Initialize to an appropriate value
// string actual;
// target.Alias = expected;
// actual = target.Alias;
// Assert.AreEqual(expected, actual);
// Assert.Inconclusive("Verify the correctness of this test method.");
//}
///// <summary>
/////A test for Id
/////</summary>
//[TestMethod()]
//public void IdTest()
//{
// TaskType target = new TaskType(); // TODO: Initialize to an appropriate value
// int expected = 0; // TODO: Initialize to an appropriate value
// int actual;
// target.Id = expected;
// actual = target.Id;
// Assert.AreEqual(expected, actual);
// Assert.Inconclusive("Verify the correctness of this test method.");
//}
#endregion
#region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//[ClassInitialize()]
//public static void MyClassInitialize(TestContext testContext)
//{
//}
//
//Use ClassCleanup to run code after all tests in a class have run
//[ClassCleanup()]
//public static void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//[TestInitialize()]
//public void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//[TestCleanup()]
//public void MyTestCleanup()
//{
//}
//
#endregion
}
}