コード例 #1
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);
        }
コード例 #2
0
ファイル: TestDataStore.cs プロジェクト: bubbafat/TellHer
 public void Remove(DailyIdea lookup)
 {
     lock (_lock)
     {
         _dailyIdeas.Remove(lookup.Id);
     }
 }
コード例 #3
0
ファイル: Edit.cs プロジェクト: bubbafat/TellHer
        protected override void PerformAdmin(Domain.IncomingSmsMessage message)
        {
            int    id;
            string editedIdea;

            if (TryCrackIdMessage(message.Message, out id, out editedIdea))
            {
                IDataStore store = DataStore.GetInstance();
                DailyIdea  idea  = store.DailyIdeas.Where(i => i.Id == id).FirstOrDefault();

                if (idea != null)
                {
                    if (editedIdea.Length < 10)
                    {
                        Say(message.From, "EDIT failed.  Your idea is really short ... probably a mistake.  Want to try again?");
                    }
                    else
                    {
                        idea.Idea = editedIdea;
                        store.Save(idea);

                        Say(message.From, "Idea {0} has been updated to your new text", idea.Id);
                    }
                }
                else
                {
                    Say(message.From, "Idea {0} does not exist.  Use add to create a new idea", id);
                }
            }
            else
            {
                Say(message.From, "Unable to parse input.  Usage: EDIT <id> <new message>   Example:  EDIT 1 this is the new idea");
            }
        }
コード例 #4
0
ファイル: Add.cs プロジェクト: bubbafat/TellHer
        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());
            }
        }
コード例 #5
0
        public void DailyIdea_ScheduledDates()
        {
            IDataStore store = DataStore.GetInstance();

            for (int i = 0; i < 5; i++)
            {
                store.Save(new DailyIdea
                {
                    Idea = "This is idea " + i.ToString(),
                });
            }

            DateTime scheduled1_date = DateTime.UtcNow.AddYears(-1).Date;
            string   scheduled1_idea = "This is scheduled idea 1";

            store.Save(new DailyIdea
            {
                Idea          = scheduled1_idea,
                ScheduledDate = scheduled1_date
            });

            DateTime scheduled2_date = scheduled1_date.AddDays(1);
            string   scheduled2_idea = "This is scheduled idea 1";

            store.Save(new DailyIdea
            {
                Idea          = scheduled2_idea,
                ScheduledDate = scheduled2_date
            });

            for (int i = 0; i < 5; i++)
            {
                store.Save(new DailyIdea
                {
                    Idea = "This is idea " + (5 + i).ToString(),
                });
            }

            for (int i = 0; i < 100; i++)
            {
                DailyIdea idea = DailyIdea.TodaysIdea(DateTime.UtcNow.AddDays(i));
                Assert.IsTrue(idea.Idea.StartsWith("This is idea "));
            }

            DailyIdea sch1 = DailyIdea.TodaysIdea(scheduled1_date);

            Assert.AreEqual(scheduled1_idea, sch1.Idea);

            DailyIdea sch2 = DailyIdea.TodaysIdea(scheduled1_date);

            Assert.AreEqual(scheduled1_idea, sch2.Idea);

            for (int i = 0; i < 100; i++)
            {
                DailyIdea idea = DailyIdea.TodaysIdea(DateTime.UtcNow.AddDays(i));
                Assert.IsTrue(idea.Idea.StartsWith("This is idea "));
            }
        }
コード例 #6
0
        void IDataStore.Save(DailyIdea idea)
        {
            if (!DailyIdeas.Any(di => di.Id == idea.Id))
            {
                DailyIdeas.Add(idea);
            }

            SaveChanges();
        }
コード例 #7
0
        void IDataStore.Remove(DailyIdea lookup)
        {
            foreach (DailyIdea i in DailyIdeas.Where(l => l.Id == lookup.Id))
            {
                DailyIdeas.Remove(i);
            }

            SaveChanges();
        }
コード例 #8
0
ファイル: Today.cs プロジェクト: bubbafat/TellHer
        private void RepeatToday(Domain.IncomingSmsMessage message)
        {
            DailyIdea idea = DailyIdea.TodaysIdea(DateTime.UtcNow);

            string ideaMsg = idea == null ?
                             "ERROR: There is no idea for today!" :
                             idea.Idea;

            Say(message.From, ideaMsg);
        }
コード例 #9
0
ファイル: TestDataStore.cs プロジェクト: bubbafat/TellHer
        public void Save(DailyIdea idea)
        {
            lock (_lock)
            {
                if (idea.Id == 0)
                {
                    idea.Id = NextId();
                }

                _dailyIdeas[idea.Id] = idea;
            }
        }
コード例 #10
0
ファイル: Say.cs プロジェクト: bubbafat/TellHer
        protected override void PerformAdmin(Domain.IncomingSmsMessage message)
        {
            int id;

            if (TryCrackId(message.Message, out id))
            {
                IDataStore store = DataStore.GetInstance();
                DailyIdea  idea  = store.DailyIdeas.Where(i => i.Id == id).FirstOrDefault();
                if (idea != null)
                {
                    Say(message.From, idea.Idea);
                }
            }
        }
コード例 #11
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);
        }
コード例 #12
0
ファイル: ProcessingLoop.cs プロジェクト: bubbafat/TellHer
        private static void ProcessSubscriptions(IOutgoingSmsQueue outgoing, IDataStore store)
        {
            DailyIdea idea = DailyIdea.TodaysIdea(DateTime.Today.ToUniversalTime());

            if (idea != null)
            {
                // now deal with the existing subscriptions
                // all where doing here is creating entries in the OutgoingSmsMessage table and updating the Next field on the
                // Subscription.  These will be picked up on the next pass through the loop by the message sender.
                IList <Subscription> toProcess = store.Subscriptions.Where(s => s.Next < DateTime.UtcNow)
                                                 .Take(outgoing.MessagesPerMinute)
                                                 .ToList();

                foreach (Subscription sub in toProcess)
                {
                    OutgoingSmsMessage msg = OutgoingSmsMessage.CreateWithDefaults(sub.Phone, idea.Idea);
                    store.ScheduleMessage(msg, sub);
                }
            }
        }
コード例 #13
0
        public void DailyIdea_DoesNotRepeat()
        {
            IDataStore store = DataStore.GetInstance();

            for (int i = 0; i < 5; i++)
            {
                store.Save(new DailyIdea
                {
                    Idea = "This is idea " + i.ToString(),
                });
            }

            DateTime fixedDate = new DateTime(2012, 1, 1, 2, 0, 0);

            HashSet <int>    ids   = new HashSet <int>();
            HashSet <string> ideas = new HashSet <string>();

            for (int i = 0; i < 5; i++)
            {
                DailyIdea idea = DailyIdea.TodaysIdea(fixedDate.AddDays(i));
                Assert.IsNotNull(idea);

                Assert.IsFalse(ids.Contains(idea.Id));
                ids.Add(idea.Id);

                Assert.IsFalse(ideas.Contains(idea.Idea));
                ideas.Add(idea.Idea);
            }

            for (int i = 0; i < 5; i++)
            {
                DailyIdea idea    = DailyIdea.TodaysIdea(fixedDate.AddDays(i));
                DailyIdea ideam1  = DailyIdea.TodaysIdea(fixedDate.AddDays(i).AddHours(-1));
                DailyIdea ideap12 = DailyIdea.TodaysIdea(fixedDate.AddDays(i).AddHours(12));

                Assert.AreEqual(idea.Id, ideam1.Id);
                Assert.AreEqual(idea.Id, ideap12.Id);
            }
        }
コード例 #14
0
        protected override void PerformAdmin(Domain.IncomingSmsMessage message)
        {
            int id;

            if (TryCrackId(message.Message, out id))
            {
                IDataStore store  = DataStore.GetInstance();
                DailyIdea  lookup = store.DailyIdeas.Where(l => l.Id == id).FirstOrDefault();

                if (lookup != null)
                {
                    store.Remove(lookup);
                    Say(message.From, "Removed idea with ID {0}", id);
                }
                else
                {
                    Say(message.From, "Idea Not Found: {0}", id);
                }
            }
            else
            {
                Say(message.From, "Unable to parse input.  Usage: REMOVE <id>   Example:  REMOVE 10");
            }
        }
コード例 #15
0
ファイル: Configuration.cs プロジェクト: bubbafat/TellHer
        protected override void Seed(TellHer.Data.TellHerDb context)
        {
            List <string> ideas = new List <string> {
                "Your first words of the morning matter.  Don\'t grunt and fart.  Instead, try \"good morning, beautiful.\"",
                "Get up a few minutes early and surprise her with a quick breakfast in bed.  Those 5 minutes will stay with her all day.",
                "Spend 10 minutes cleaning your bedroom tonight.  She will be able to relax a lot more with less clutter in sight.",
                "Tonight you make dinner – and afterwards you clean the dishes.  No kids?  Do them naked.",
                "Come home 15 minutes early and use the time to clean the house.",
                "Give her a night off from you and the kids.  Take them out so she can spend some time on a hobby or just relaxing.",
                "Invite her on a walk.  Hold her hand.  Ask about her day.  Listen to her.",
                "When she is telling you about a problem don\'t try to solve it.  Listen then ask if you can help.  Believe her answer.",
                "Have 15 minutes to kill?  Clean the bathroom – including the toilet.",
                "Out of shape?  Take care of yourself.  Make regular exercise a priority.  You might even invite her to join you.",
                "Knock something off the honey-do list without being asked.  Find a 15 minute job and do it.  You have the time.",
                "Find something to compliment her about daily and then actually say it.",
                "Notice her hair today.  She put effort into making it right.  She did that for you – appreciate it!",
                "Notice her eyes today.  Tell her how beautiful they look.",
                "Notice her smile today.  Tell her how it makes you feel to see her happy.",
                "Going out?  Compliment what she is wearing.  She picked it as much for you as for her.  Let her know you noticed.",
                "When she gets a new outfit be sure to notice it.  Clueless?  Look for hints (bags, receipts, etc).",
                "If you know she went to the hair salon then for the love of all that is holy you had better compliment her hair.",
                "Leave a simple love note in her purse when you leave in the morning.  You\'ll know when she finds it.",
                "Leaving early?  Put a little a love note on the bathroom counter for her to find later.",
                "Every once in a while send her a text message saying you miss her.  Not every day, though.  Make it special, not routine.",
                "Is she having a rough day?  Send her an encouraging text or email.",
                "Leave a note for her on her steering wheel.",
                "Write her an honest-to-god love poem.  Long, short, rhymes or not ... doesn\'t matter.",
                "Traveling apart?  Send her a postcard with a note saying how much you miss her.",
                "Tell her you love her.  Right now.  Take her hand, look her in the eyes and say it!  Now!",
                "Tell her how happy you are to have married her.  Don\'t assume she knows it.  Let her hear it.",
                "Tell her that you missed her today and how happy you are to be with her now.",
                "When she accomplishes something make sure to actually say \"I\'m proud of you\"",
                "Tell her that you appreciate her and what she does for you and your family.",
                "Stop calling her \"dude\" and \"man\".  Just stop it.",
                "Meet her at the door once in a while.  Make her feel like you were waiting just for her to come home.",
                "Hold her hand in public.  Don\'t wait for her to grab yours.",
                "Hands full?  Stick out your elbow and let her lock arms with you.  Let her know that her touch matters to you.",
                "When sitting at a table let those feet wander a bit.  Play footsie with her.",
                "Walking single file?  Put your hand gently on the small of her back.  Let her know you\'re with her.",
                "Don\'t be afraid to give her a little kiss in public.  She\'s beautiful.  You\'re proud of her.  Let everyone know it.",
                "Be a gentleman.  Always let her sit down first.",
                "Be a gentleman.  On your next date why not open the car door for her?",
                "Be a gentleman.  Open the door for her.  Little gestures go a long way.",
                "Put your arm around her waist when you are walking in public.",
                "Does she have a pinterest board?  Check out her pins every once in a while.  Learn something about her interests.",
                "Does she have a hobby you don\'t understand?  Ask her to teach you.",
                "Make her a mixtape.  Spend 20 minutes thinking about songs that make you think of her.  Make sure \"your\" song is on it.",
                "When she says her feet are killing her that\'s your cue to offer a foot rub.",
                "Sitting on the couch together?  Offer her a neck rub.",
                "Man Tip: Spend 15 minutes learning about back and neck massage online and remember to always start gently.",
                "Sometimes it\'s less about where you touch as how you touch.  Ask her what she likes.",
                "It\'s much more enjoyable to be touched by someone with groomed nails.  File those bad boys a little.",
                "When was the last time you walked up behind her, put your arms around her and hugged her?",
                "Find somewhere new to kiss her.  No ... I don\'t mean there.  How about her knee?  Elbow?  Hip?  Have a little fun.",
                "Cuddling is not always a prelude to sex.  Do it without expectation and you may find it leads there more often.",
                "Make tonight a movie-in-bed date night.  Ask her out.  Let her pick the movie.  You make a snack.  Relax and unwind.",
                "Ask her out for a picnic.  Check the weather, pick a location, pack the meal – all she has to do it show up and enjoy.",
                "Take her hiking.  It doesn\'t have to be extreme.  A 1 or 2 mile walk around a lake is a great way to unwind.",
                "When was the last time you asked her out on a date as if you were still a new couple?  She misses that.",
                "Is there a movie she wants to see but you don\'t?  Take her anyway.  She\'ll appreciate it more than you think.",
                "Take her out for karaoke and sing her a love song.  Super cheesy but she\'ll remember it for a long time.",
                "Surprise her with a simple bouquet of her favorite flowers.  (You know her favorite flower, right?)",
                "Stop and pick up a card for no reason at all.  Make it a little funny and a little sappy.  Just let her know you care.",
            };

            ideas.Shuffle();

            foreach (string ideaStr in ideas)
            {
                DailyIdea idea = new DailyIdea
                {
                    Idea = ideaStr,
                };

                if (!context.DailyIdeas.Any(i => i.Idea == idea.Idea))
                {
                    context.DailyIdeas.AddOrUpdate(idea);
                }
            }
        }