public void GetSpecificUserTest()
        {
            var loyalty     = new LoyaltyManager(_context);
            var createdUser = loyalty.CreateUser("George", "Bush", "*****@*****.**");

            var queriedUser = loyalty.GetUser(createdUser.UserId);

            Assert.AreEqual("George", queriedUser.FirstName);
            Assert.AreEqual("Bush", queriedUser.LastName);
            Assert.AreEqual("*****@*****.**", queriedUser.Email);
        }
        public void TransferPointsInsufficientPointsTest()
        {
            var loyalty = new LoyaltyManager(_context);
            var user    = loyalty.CreateUser("George", "Clooney", "*****@*****.**");

            Assert.AreEqual(0, user.Points);

            loyalty.TransferPoints(user.UserId, -10);
            var queriedUser = loyalty.GetUser(user.UserId);

            Assert.AreEqual(10, user.Points);
        }
        public void GetUsersTest()
        {
            var loyalty = new LoyaltyManager(_context);

            var users = loyalty.EnumerateUsers();

            Assert.AreEqual(0, users.Count());

            loyalty.CreateUser("George", "Washington", "*****@*****.**");

            users = loyalty.EnumerateUsers();
            Assert.AreEqual(1, users.Count());
        }
        public void TransferPointsTest()
        {
            var loyalty = new LoyaltyManager(_context);
            var user    = loyalty.CreateUser("George", "Orwell", "*****@*****.**");

            Assert.AreEqual(0, user.Points);

            var transfer    = loyalty.TransferPoints(user.UserId, 10);
            var queriedUser = loyalty.GetUser(user.UserId);

            Assert.AreEqual(10, user.Points);
            Assert.AreEqual(10, transfer.Amount);

            var queriedTransfer = loyalty.EnumerateTransfers(user.UserId).Last();

            Assert.AreEqual(transfer.TransferId, queriedTransfer.TransferId);
            Assert.AreEqual(10, queriedTransfer.Amount);
        }
        public object PostUser([FromBody] JObject userInfo)
        {
            if (!IsValidString(userInfo["firstName"]) ||
                !IsValidString(userInfo["lastName"]) ||
                !IsValidEmail(userInfo["email"]))
            {
                return(BadRequest("Invalid information for a new user."));
            }
            string firstName = userInfo["firstName"].ToString();
            string lastName  = userInfo["lastName"].ToString();
            string email     = userInfo["email"].ToString();

            var user = _database.CreateUser(firstName, lastName, email);

            return(Ok(new
            {
                Id = user.UserId,
                user.Email,
                user.FirstName,
                user.LastName,
                user.Points
            }));
        }