Exemplo n.º 1
0
        private static string GetCommand(IncomingSmsMessage message)
        {
            if (message == null)
            {
                return string.Empty;
            }

            if (string.IsNullOrWhiteSpace(message.Message))
            {
                return string.Empty;
            }

            string[] parts = message.Message.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
            return parts[0];
        }
Exemplo n.º 2
0
        public void Perform_ExistingUser_Skip()
        {
            Join_Accessor target = new Join_Accessor(); // TODO: Initialize to an appropriate value

            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = base.ExistingSubscriberPhone,
                Message = target.Action,
            };

            Assert.AreEqual(1, SubscriptionForNumber(message.From).Count);

            target.PerformAdmin(message);

            Assert.AreEqual(1, SubscriptionForNumber(message.From).Count);
            base.OutgoingMessageExists(message.From, SmsResponseStrings.Join_AlreadyExists());
        }
Exemplo n.º 3
0
        public void Perform(IncomingSmsMessage message)
        {
            if (message.From == _Configuration.AdminNumber)
            {
                PerformAdmin(message);
                return;
            }

            IDataStore store = DataStore.GetInstance();
            if (store.Subscriptions.Any(s => s.Phone == message.From))
            {
                PerformSubscriber(message);
                return;
            }

            PerformUnknownUser(message);
        }
Exemplo n.º 4
0
        public void Perform_RealAdmin()
        {
            Add_Accessor target = new Add_Accessor(); // TODO: Initialize to an appropriate value
            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = Configuration.GetInstance().AdminNumber,
                Message = "add This is the added message",
            };

            target.Perform(message);

            IDataStore store = DataStore.GetInstance();

            DailyIdea addedIdea = store.DailyIdeas.Where(i => i.Idea == "This is the added message").First();
            OutgoingSmsMessage response = store.OutgoingMessages.Where(o => o.Message ==  SmsResponseStrings.Add_Success_AddedNewIdea(addedIdea.Id)).First();
            Assert.AreEqual(Configuration.GetInstance().AdminNumber, response.Destination);
        }
Exemplo n.º 5
0
        public void Perform_ExistingUser()
        {
            Quit_Accessor target = new Quit_Accessor(); // TODO: Initialize to an appropriate value

            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = ExistingSubscriberPhone,
                Message = target.Action,
            };

            Assert.AreEqual(1, base.SubscriptionForNumber(message.From).Count);

            target.Perform(message);

            OutgoingMessageExists(base.ExistingSubscriberPhone, SmsResponseStrings.Quit_AllRemoved(base.ExistingSubscriberPhone));
            Assert.AreEqual(0, base.SubscriptionForNumber(message.From).Count);
        }
Exemplo n.º 6
0
 protected virtual void PerformSubscriber(IncomingSmsMessage message)
 {
     GeneralHelp(message);
 }
Exemplo n.º 7
0
 protected virtual void PerformAdmin(IncomingSmsMessage message)
 {
     GeneralHelp(message);
 }
Exemplo n.º 8
0
 protected void GeneralHelp(IncomingSmsMessage message)
 {
     Say(message.From, SmsResponseStrings.PublicHelp());
 }
Exemplo n.º 9
0
        public void Perform_ExistingUser_QueuedMessagesRemoved()
        {
            Quit_Accessor target = new Quit_Accessor(); // TODO: Initialize to an appropriate value

            IDataStore store = DataStore.GetInstance();

            // add an existing outgoing message - this should be removed when the quit is done
            store.Save(new OutgoingSmsMessage
            {
                Destination = ExistingSubscriberPhone,
                Message = "Does not matter",
            });

            // add an existing outgoing message - this should be removed when the quit is done
            store.Save(new OutgoingSmsMessage
            {
                Destination = ExistingSubscriberPhone,
                Message = "Also does not matter",
            });

            Assert.AreEqual(2, store.OutgoingMessages.Count());

            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = ExistingSubscriberPhone,
                Message = target.Action,
            };

            Assert.AreEqual(1, base.SubscriptionForNumber(message.From).Count);

            target.Perform(message);

            // there should be only one message in the outgoing queue
            Assert.AreEqual(1, store.OutgoingMessages.Count());

            // and it should be this one...
            OutgoingMessageExists(base.ExistingSubscriberPhone, SmsResponseStrings.Quit_AllRemoved(base.ExistingSubscriberPhone));

            Assert.AreEqual(0, store.Subscriptions.Count());
        }
Exemplo n.º 10
0
        public void Perform_MissingUser()
        {
            Quit_Accessor target = new Quit_Accessor(); // TODO: Initialize to an appropriate value

            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = "+11112223333",
                Message = target.Action,
            };

            target.Perform(message);

            IDataStore store = DataStore.GetInstance();

            OutgoingMessageExists(message.From, SmsResponseStrings.Quit_AllRemoved(message.From));
        }
Exemplo n.º 11
0
        private void ProcessReceivedMessage(IncomingSmsMessage message)
        {
            if (NumberBlocker.IsBlocked(message.From))
            {
                LogManager.Log.Info("SMS received from blocked number {0}.  Message: {1}",
                    message.From,
                    message.Message);

                // skip it entirely
                return;
            }

            string command = GetCommand(message);
            ClientAction action = GetActionOrHelp(command);
            action.Perform(message);
        }
Exemplo n.º 12
0
 private void ReceivedMessageFailed(IncomingSmsMessage message, Exception ex)
 {
     LogManager.Log.Error(string.Format(CultureInfo.InvariantCulture, "Error processing message ({0} - {1})", message.From, message.Message), ex);
 }
Exemplo n.º 13
0
        public void Perform_RealAdmin_Help()
        {
            string destination = Configuration.GetInstance().AdminNumber;
            Add_Accessor target = new Add_Accessor(); // TODO: Initialize to an appropriate value
            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = destination,
                Message = "add",
            };

            target.Perform(message);

            IDataStore store = DataStore.GetInstance();

            Assert.AreEqual(0, store.DailyIdeas.Count());
            OutgoingMessageExists(destination, SmsResponseStrings.Add_Help());
        }
Exemplo n.º 14
0
        public void Perform_RealAdmin_ExistingIdea()
        {
            Add_Accessor target = new Add_Accessor(); // TODO: Initialize to an appropriate value

            IDataStore store = DataStore.GetInstance();

            DailyIdea idea = new DailyIdea
            {
                 Idea = "This is the added message",
            };

            store.Save(idea);

            Assert.AreNotEqual(0, idea.Id);

            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = Configuration.GetInstance().AdminNumber,
                Message = string.Format(CultureInfo.InvariantCulture, "add {0}", idea.Idea),
            };

            target.Perform(message);

            Assert.AreEqual(1, store.DailyIdeas.Count(i => i.Idea == idea.Idea));
            OutgoingSmsMessage response = store.OutgoingMessages.Where(o => o.Message == SmsResponseStrings.Add_Failed_ExistingIdea(idea.Id)).First();
            Assert.AreEqual(Configuration.GetInstance().AdminNumber, response.Destination);
        }
Exemplo n.º 15
0
        public void Perform_UnknownUser()
        {
            string destinationNumber = "+11112223333";

            Add_Accessor target = new Add_Accessor(); // TODO: Initialize to an appropriate value
            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = destinationNumber,
                Message = "add This is the added message",
            };

            target.Perform(message);

            IDataStore store = DataStore.GetInstance();

            Assert.IsFalse(store.DailyIdeas.Any());
            OutgoingSmsMessage response = store.OutgoingMessages.Where(o => o.Message == SmsResponseStrings.PublicHelp()).First();
            Assert.AreEqual(destinationNumber, response.Destination);
        }
Exemplo n.º 16
0
        public void Perform_Subscriber()
        {
            IDataStore store = DataStore.GetInstance();

            Add_Accessor target = new Add_Accessor(); // TODO: Initialize to an appropriate value
            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = ExistingSubscriberPhone,
                Message = "add This is the added message",
            };

            target.Perform(message);

            Assert.IsFalse(store.DailyIdeas.Any());
            OutgoingMessageExists(ExistingSubscriberPhone, SmsResponseStrings.PublicHelp());
        }
Exemplo n.º 17
0
 protected virtual void PerformUnknownUser(IncomingSmsMessage message)
 {
     GeneralHelp(message);
 }
Exemplo n.º 18
0
        public void Perform_MissingUser_BetaFull_Sorry()
        {
            Join_Accessor target = new Join_Accessor(); // TODO: Initialize to an appropriate value

            IDataStore store = DataStore.GetInstance();
            IConfiguration config = Configuration.GetInstance();

            int count = 0;

            while(store.Subscriptions.Count() < config.BetaLimit)
            {
                store.Save(new Subscription
                {
                    Next = DateTime.UtcNow,
                    Phone = string.Format(CultureInfo.InvariantCulture, "+1111222{0}", count++),
                });
            }

            IncomingSmsMessage message = new IncomingSmsMessage
            {
                From = base.NonSubscriberPhone,
                Message = target.Action,
            };

            Assert.AreEqual(config.BetaLimit, store.Subscriptions.Count());

            target.PerformAdmin(message);

            Assert.AreEqual(config.BetaLimit, store.Subscriptions.Count());

            base.OutgoingMessageExists(message.From, SmsResponseStrings.Join_SorryBetaFull());
            base.OutgoingMessageExists(config.AdminNumber, SmsResponseStrings.Join_AdminBetaReject());
        }
Exemplo n.º 19
0
 private void ReceivedMessageComplete(IncomingSmsMessage message)
 {
     // nothing to do just yet
 }
Exemplo n.º 20
0
 public void Add(IncomingSmsMessage message)
 {
     _messageProcessor.Add(message);
 }