public void Existing_user_returns_error_response()
        {
            using (var db = ConnectionFactory.OpenDbConnection())
            {
                db.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"));
            }
        }
		public void StoreNewUser_Test()
		{
			using (var dbConn = ConnectionFactory.OpenDbConnection())
			using (var dbCmd = dbConn.CreateCommand())
			{
				var service = new StoreNewUserService { ConnectionFactory = ConnectionFactory };
				var response = (StoreNewUserResponse)service.Execute(request);

				Assert.That(response.UserId, Is.EqualTo(1));

				var storedUser = dbCmd.First<User>("UserName = {0}", request.UserName);
				Assert.That(storedUser.Email, Is.EqualTo(request.Email));
				Assert.That(storedUser.Password, Is.EqualTo(request.Password));
			}
		}
        public void StoreNewUser_Test()
        {
            using (var db = ConnectionFactory.Open())
            {
                var service = new StoreNewUserService { ConnectionFactory = ConnectionFactory };

                var newUserRequest = new StoreNewUser
                {
                    UserName = "******",
                    Email = "*****@*****.**",
                    Password = "******"
                };
                var response = (StoreNewUserResponse)service.Execute(newUserRequest);

                var storedUser = db.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));
            }
        }
		private static void DatabaseTest(IDbConnectionFactory connectionFactory)
		{
			ConfigureDatabase.Init(connectionFactory);

			var storeRequest = new StoreNewUser {
				Email = "new@email",
				Password = "******",
				UserName = "******"
			};

			var storeHandler = new StoreNewUserService { ConnectionFactory = connectionFactory };
			storeHandler.Execute(storeRequest);

			var getAllHandler = new GetAllUsersService { ConnectionFactory = connectionFactory };
			var response = (GetAllUsersResponse)getAllHandler.Execute(new GetAllUsers());

			var user = response.Users[0];

			System.Console.WriteLine("Stored and retrieved user: {0}, {1}, {2}",
				user.Id, user.UserName, user.Email);
		}