private void EnsureUserIsKnown(IncomingSmsMessage message, Models.User user)
        {
            if (user == null)
            {
                string errorMessage = String.Format(
                    "No such user: \"{0}\".", message.From);

                var response = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(errorMessage),
                    ReasonPhrase = errorMessage
                };

                Trace.TraceError(errorMessage);
                throw new HttpResponseException(response);
            }
        }
        private void QueueUser(IncomingSmsMessage message, QBase qbase, User user)
        {
            var q = qbase.GetQueueByShortCode(message.Content);

            this.EnsureQueueIsKnown(message, q);

            string status = null;

            if (user == null)
            {
                user = qbase.AddAnonymousUser(message.From);
                // TODO: status = "registering";
                status = "joined";
            }
            else
            {
                /*
                var usersInQueue = qbase.GetUsersInQueue(q.queueId);

                if (usersInQueue.Count(each => each.userId == user.userId) != 0)
                {
                    string warningMessage = String.Format(
                        "User \"{0}\" is already in queue \"{1}\". User will not be added again.",
                        user.userId,
                        q.queueId);

                    Trace.TraceWarning(warningMessage);
                    return;
                }
                */

                status = "joined";
            }

            qbase.AddUserToQueue(q.queueId, new QUser
            {
                userId = user.userId,
                status = status
            });
        }
        public void User_Full_Name_Is_Updated()
        {
            // Arrange.
            var controller = new Incoming_SmsController();

            controller.Request = new HttpRequestMessage();
            controller.ModelState.Clear();

            var incomingSmsMessage = new IncomingSmsMessage
            {
                From = "4455523456789",
                To = "447860033153",
                Msg_Id = Convert.ToString(Guid.NewGuid()),
                Content = "NAME Alice Bong"
            };

            // Act.
            var response = controller.Get(incomingSmsMessage);

            // Assert.
            Assert.IsTrue(response.IsSuccessStatusCode);
        }
        public void Receives_Sms_And_Adds_User_To_Queue()
        {
            // Arrange.
            var controller = new Incoming_SmsController();

            controller.Request = new HttpRequestMessage();
            controller.ModelState.Clear();

            var incomingSmsMessage = new IncomingSmsMessage
            {
                From = "4455523456789",
                To = "447860033153",
                Msg_Id = Convert.ToString(Guid.NewGuid()),
                Content = "HELI"
            };

            // Act.
            var response = controller.Get(incomingSmsMessage);

            // Assert.
            Assert.IsTrue(response.IsSuccessStatusCode);
        }
 private bool IsUpdateUserMessage(IncomingSmsMessage message)
 {
     return message.Content.ToUpper().StartsWith(NameTag);
 }
        private void UpdateUser(IncomingSmsMessage message, QBase qbase, User user)
        {
            string fullName = message.Content.Substring(NameTag.Length).Trim();

            user.fullName = fullName;
            user.status = "registered";

            qbase.UpdateUser(user);

            Trace.TraceInformation(
                "Updated user.fulName for \"{0}\" to \"{1}\"", user.userId, user.fullName);
        }
        private void EnsureQueueIsKnown(IncomingSmsMessage message, Q q)
        {
            if (q == null)
            {
                string errorMessage = String.Format(
                    "No such queue: \"{0}\".", message.Content);

                var response = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(errorMessage),
                    ReasonPhrase = errorMessage
                };

                Trace.TraceError(errorMessage);
                throw new HttpResponseException(response);
            }
        }