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()); } }
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); }