forked from ServiceStack/ServiceStack.Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoreNewUserTests.cs
More file actions
59 lines (51 loc) · 1.9 KB
/
Copy pathStoreNewUserTests.cs
File metadata and controls
59 lines (51 loc) · 1.9 KB
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
using NUnit.Framework;
using ServiceStack.Examples.ServiceInterface;
using ServiceStack.Examples.ServiceModel.Operations;
using ServiceStack.Examples.ServiceModel.Types;
using ServiceStack.OrmLite;
namespace ServiceStack.Examples.Tests
{
[TestFixture]
public class StoreNewUserTests
: TestHostBase
{
readonly StoreNewUser request = new StoreNewUser
{
UserName = "Test",
Email = "admin@test.com",
Password = "password"
};
[Test]
public void StoreNewUser_Test()
{
using (var dbConn = ConnectionFactory.OpenDbConnection())
using (var dbCmd = dbConn.CreateCommand())
{
var service = new StoreNewUserService { ConnectionFactory = ConnectionFactory };
var newUserRequest = new StoreNewUser
{
UserName = "StoreNewUser_Test",
Email = "StoreNewUser@test.com",
Password = "password"
};
var response = (StoreNewUserResponse)service.Execute(newUserRequest);
var storedUser = dbCmd.First<User>("UserName = {0}", newUserRequest.UserName);
Assert.That(storedUser.Id, Is.EqualTo(response.UserId));
Assert.That(storedUser.Email, Is.EqualTo(newUserRequest.Email));
Assert.That(storedUser.Password, Is.EqualTo(newUserRequest.Password));
}
}
[Test]
public void Existing_user_returns_error_response()
{
using (var dbConn = ConnectionFactory.OpenDbConnection())
using (var dbCmd = dbConn.CreateCommand())
{
dbCmd.Insert(new User { UserName = request.UserName });
var service = new StoreNewUserService { ConnectionFactory = ConnectionFactory };
var response = (StoreNewUserResponse)service.Execute(request);
Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("UserNameMustBeUnique"));
}
}
}
}