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()); }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { string newIdea; if (TryCrackMessage(message.Message, out newIdea)) { IDataStore store = DataStore.GetInstance(); DailyIdea idea = store.DailyIdeas.Where(i => i.Idea == newIdea).FirstOrDefault(); if (idea == null) { idea = new DailyIdea { Idea = newIdea, }; store.Save(idea); Say(message.From, SmsResponseStrings.Add_Success_AddedNewIdea(idea.Id)); } else { Say(message.From, SmsResponseStrings.Add_Failed_ExistingIdea(idea.Id)); } } else { Say(message.From, SmsResponseStrings.Add_Help()); } }
private static void DoQuit(Domain.IncomingSmsMessage message) { IDataStore store = DataStore.GetInstance(); store.RemoveAllForPhone(message.From); Say(message.From, SmsResponseStrings.Quit_AllRemoved(message.From)); }
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()); }
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()); }
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); }
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)); }
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()); }
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()); }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { string action; if (TryCrackMessage(message.Message, out action)) { switch (action.ToLowerInvariant()) { case "error": SayLastError(message); break; case "log": SayLostLog(message); break; default: Say(message.From, SmsResponseStrings.Last_Help()); break; } } }
protected override void PerformUnknownUser(Domain.IncomingSmsMessage message) { IDataStore store = DataStore.GetInstance(); IConfiguration config = Configuration.GetInstance(); if (store.Subscriptions.Count() < config.BetaLimit) { Subscription s = new Subscription { Phone = message.From, Next = DateTime.UtcNow, }; store.Save(s); Say(message.From, SmsResponseStrings.Join_Created()); } else { Say(message.From, SmsResponseStrings.Join_SorryBetaFull()); Say(config.AdminNumber, SmsResponseStrings.Join_AdminBetaReject()); } }
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); }
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); }
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); }
protected void GeneralHelp(IncomingSmsMessage message) { Say(message.From, SmsResponseStrings.PublicHelp()); }
protected override void PerformSubscriber(Domain.IncomingSmsMessage message) { Say(message.From, SmsResponseStrings.Join_AlreadyExists()); }