示例#1
0
            public void ShouldUpdateVotesWhenSmsSent()
            {
                string code        = "555";
                string wordKey     = "something";
                var    smsService  = new StubSmsVotingService();
                var    stubStorage = new StubSmsVotingStorage();
                var    presenter   = new SmsVotingControlPresenter(stubStorage, smsService, code, 50);

                smsService.Send(new SmsMessage(new List <PhoneNumber>()
                {
                    new PhoneNumber(code)
                }, wordKey));

                var messageStatusUpdated = new ManualResetEvent(false);

                presenter.VotingResults.CollectionChanged += (sender, e) =>
                {
                    messageStatusUpdated.Set();
                    presenter.Unload();
                };
                presenter.Listen();

                Assert.IsTrue(messageStatusUpdated.WaitOne(TimeSpan.FromSeconds(1)));
                Assert.AreEqual(1, presenter.VotingResults.Count);
            }
示例#2
0
            public void ShouldUpdateVotingStorageWhenSmsSent()
            {
                string code        = "555";
                string voteKey     = "something";
                var    smsService  = new StubSmsVotingService();
                var    stubStorage = new StubSmsVotingStorage();
                var    presenter   = new SmsVotingControlPresenter(stubStorage, smsService, code, 50);

                smsService.Send(new SmsMessage(new List <PhoneNumber>()
                {
                    new PhoneNumber(code)
                }, voteKey));

                var messageStatusUpdated = new ManualResetEvent(false);

                presenter.VotingResults.CollectionChanged += (sender, e) =>
                {
                    messageStatusUpdated.Set();
                    presenter.Unload();
                };
                presenter.Listen();

                messageStatusUpdated.WaitOne(TimeSpan.FromMilliseconds(100));

                IEnumerable <KeyValuePair <string, int> > result = stubStorage.GetStatistics();

                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.Count());
                Assert.AreEqual(voteKey, result.First().Key);
                Assert.AreEqual(1, result.First().Value);
            }
示例#3
0
            public void ShouldAllowEmptyMessages()
            {
                string code        = "555";
                string wordKey     = String.Empty;
                var    smsService  = new StubSmsVotingService();
                var    stubStorage = new StubSmsVotingStorage();
                var    presenter   = new SmsVotingControlPresenter(stubStorage, smsService, code, 50);

                var messageStatusUpdated = new ManualResetEvent(false);

                presenter.VotingResults.CollectionChanged += (sender, e) =>
                {
                    messageStatusUpdated.Set();
                    presenter.Unload();
                };
                presenter.Listen();

                smsService.Send(new SmsMessage(new List <PhoneNumber>()
                {
                    new PhoneNumber(code)
                }, wordKey));

                messageStatusUpdated.WaitOne(TimeSpan.FromMilliseconds(200));

                IEnumerable <KeyValuePair <string, int> > result = stubStorage.GetStatistics();

                Assert.AreEqual <int>(1, result.Count());
            }
示例#4
0
            public void ShouldUpdateVotingStorageByAllSms()
            {
                string code        = "555";
                var    smsService  = new StubSmsVotingService();
                var    stubStorage = new StubSmsVotingStorage();
                var    presenter   = new SmsVotingControlPresenter(stubStorage, smsService, code, 50);

                var wordKeys = new List <string> {
                    "orange", "yellow", "brown"
                };

                foreach (var key in wordKeys)
                {
                    smsService.Send(new SmsMessage(new List <PhoneNumber>()
                    {
                        new PhoneNumber(code)
                    }, key));
                }

                var messageStatusUpdated = new ManualResetEvent(false);

                presenter.VotingResults.CollectionChanged += (sender, e) =>
                {
                    messageStatusUpdated.Set();
                    presenter.Unload();
                };
                presenter.Listen();

                messageStatusUpdated.WaitOne(TimeSpan.FromMilliseconds(100));

                IEnumerable <KeyValuePair <string, int> > result = stubStorage.GetStatistics();

                Assert.IsNotNull(result);
                Assert.AreEqual(3, result.Count());
                for (int i = 0; i < 3; i++)
                {
                    var element = result.FirstOrDefault(item => String.Equals(item.Key, wordKeys[i], StringComparison.CurrentCulture));
                    Assert.IsNotNull(element);
                    Assert.AreEqual(1, element.Value);
                }
            }