Exemplo n.º 1
0
        public void UpdateSignStatusOnLogin()
        {
            var    context = VoiceTestContext.GetDefault <VoiceTestContext>();
            string dem     = "1234";

            var otherMember = new MemberLookupResult {
                Id = "alternate", Name = "Fuzzy Bunny"
            };

            context.SignIns.Add(new MemberSignIn {
                MemberId = otherMember.Id, TimeIn = DateTime.Now.AddMinutes(-5), Id = 5
            });
            context.MembersMock.Setup(f => f.LookupMemberDEM(dem)).Returns(Task.Factory.StartNew <MemberLookupResult>(() => otherMember));

            var result = Task.Run(() => context.DoApiCall("http://localhost/api/voice/dologin", digits: dem)).Result.ToXDocument();

            Console.WriteLine(result);

            var element = result.Root.FirstNode as XElement;

            Assert.AreEqual("Gather", element.Name.LocalName, "expected gather step");

            var url = element.Attribute("action").Value;

            Assert.True(url.Contains(VoiceController.QueryFields.SignedInKey + "=1"), "action has isSignedIn query value: " + url);

            string firstOption = element.Descendants("Say").First().Value;

            Assert.True(firstOption.Contains("sign out"), firstOption + " contains text 'sign out'");
            Assert.True(firstOption.Contains(otherMember.Name), firstOption + " contains new member name");
        }
Exemplo n.º 2
0
        public void LoginForSignin()
        {
            var context      = VoiceTestContext.GetDefault <VoiceTestContext>();
            var memberNumber = "28594";

            context.MembersMock.Setup(f => f.LookupMemberDEM(memberNumber)).Returns(() => Task.FromResult(context.Member));
            context.MembersMock.Setup(f => f.LookupMemberPhone(It.IsAny <string>())).Returns(() => Task.FromResult <MemberLookupResult>(null));

            Assert.AreEqual(0, context.SignIns.Count(), "initial signins");

            // Setup: Unknown caller has dialed and initial message/menu has been presented.
            Task.Run(() => context.DoApiCall(VoiceTestContext.AnswerUrl));
            // Member now hits "1" to sign in:
            var result = Task.Run(() => context.DoApiCall("http://localhost/api/voice/DoMenu", digits: "1")).Result.ToXDocument();

            // System says "Enter your DEM followed by the pound sign"
            var menuItem = result.Descendants("Say").Where(f => f.Value == Speeches.DEMPrompt).First();
            var url      = menuItem.Parent.Attribute("action").Value;
            var action   = context.GetActionMethod(url).Name;

            Assert.AreEqual("DoLogin", action, "login action");

            // User enters their number:
            result = Task.Run(() => context.DoApiCall(url, memberNumber)).Result.ToXDocument();

            var signinConfirm = result.Descendants("Say").First().Value;

            Assert.IsTrue(signinConfirm.StartsWith(string.Format(Speeches.SignedInUnassignedTemplate, context.Member.Name, string.Empty)), "sign in confirmation");

            Assert.IsNotNull(context.SignIns.SingleOrDefault(f => f.EventId == null &&
                                                             f.MemberId == context.Member.Id &&
                                                             f.Name == context.Member.Name &&
                                                             f.TimeOut == null
                                                             ));
        }
Exemplo n.º 3
0
        public void RecordInMenu()
        {
            var context = VoiceTestContext.GetDefault <VoiceTestContext>();

            var result = Task.Run(() => context.DoApiCall(VoiceTestContext.AnswerUrl)).Result;

            Assert.IsTrue(result.ToString().Contains(string.Format(Speeches.PromptRecordMessageTemplate, RecordMessageKey)), "answer menu has record prompt");
        }
Exemplo n.º 4
0
        public void AnswerKnownCallerNoMissions()
        {
            var context = VoiceTestContext.GetDefault <VoiceTestContext>();

            string expectedText = GetKnownMemberSigninPrompt(context)
                                  + string.Format(Speeches.PromptRecordMessageTemplate, 3)
                                  + string.Format(Speeches.PromptChangeResponder, 8)
                                  + string.Format(Speeches.PromptAdminMenu, 9);

            AnswerCallCheckResult(context, expectedText);
        }
Exemplo n.º 5
0
        public void SigninPromptsForEvent()
        {
            var context   = VoiceTestContext.GetDefault <VoiceTestContext>();
            var eventList = new List <SarEvent>();

            eventList.Add(new SarEvent {
                Id = 5, Name = "First Event"
            });
            eventList.Add(new SarEvent {
                Id = 6, Name = "Second Event"
            });
            context.EventsServiceMock.Setup(f => f.ListActive()).Returns(() => Task.Factory.StartNew(() => eventList));

            var result = Task.Run(() => context.DoApiCall(VoiceTestContext.AnswerUrl, (string)null)).Result.ToXDocument();

            Assert.AreEqual(1, context.Calls.Count(), "rows in call table");
            Assert.AreEqual(context.From, context.Calls.Single().Number, "stored phone number");
            Assert.AreEqual(0, context.SignIns.Count(), "rows in signin table");

            var menuAction = (from e in result.Descendants("Gather") select e.Attribute("action").Value).FirstOrDefault();

            Assert.IsTrue(menuAction.StartsWith("http://localhost/api/voice/DoMenu"), "action is DoMenu");

            result = Task.Run(() => context.DoApiCall(menuAction, "1")).Result.ToXDocument();

            var element = result.Root.FirstNode as XElement;

            Assert.AreEqual("Gather", element.Name.LocalName, "expected gather step 1");
            var url = element.Attribute("action").Value;

            // Should ask for more information
            Assert.AreEqual("SetEvent", context.GetActionMethod(url).Name, "next prompt is set time out");

            StringAssert.Contains(string.Format("Press {0} then pound for {1}.", 1, "First Event"), element.ToString(), "includes prompt for mission");
            Assert.AreEqual(1, context.SignIns.Count(), "sign in rows");
            Assert.AreEqual(null, context.SignIns.First().TimeOut, "time out is null");
            Assert.AreEqual(null, context.SignIns.First().EventId, "event id should be null when prompting");

            var uri = new Uri(url);

            result = Task.Run(() => context.DoApiCall(url, "1", true)).Result.ToXDocument();

            element = result.Root.FirstNode as XElement;
            Assert.AreEqual("Say", element.Name.LocalName, "expected say step 2");
            Assert.AreEqual(string.Format(Speeches.ChangeEventTemplate, "First Event"), element.Value, "change to event name");
            element = element.NextNode as XElement;
            Assert.AreEqual("Redirect", element.Name.LocalName, "action is a redirect");
            StringAssert.StartsWith("http://localhost/api/voice/menu?", element.Value.ToLower(), "redirects to menu");
            StringAssert.Contains("&e=5&", element.Value, "mission id is in url");
        }
Exemplo n.º 6
0
        public void AnswerUnknownCallerNoMissions()
        {
            var context = VoiceTestContext.GetDefault <VoiceTestContext>();

            context.Member = null;

            var expectedText = Speeches.WelcomeUnknownCaller
                               + string.Format(Speeches.PressOneTemplate, string.Format(Speeches.PromptSignInTemplate, string.Empty))
                               // no prompt to change missions because there are none
                               + string.Format(Speeches.PromptRecordMessageTemplate, 3)
                               + string.Format(Speeches.PromptChangeResponder, 8)
                               + string.Format(Speeches.PromptAdminMenu, 9);

            AnswerCallCheckResult(context, expectedText);
        }
Exemplo n.º 7
0
        public void RecordMessagePrompt()
        {
            var context = VoiceTestContext.GetDefault <VoiceTestContext>();

            var result = Task.Run(() => context.DoApiCall(VoiceTestContext.AnswerUrl)).Result;

            var nodes = Task.Run(() => context.DoApiCall("http://localhost/api/voice/DoMenu", digits: RecordMessageKey)).Result.ToXDocument()
                        .Root.Descendants().Cast <XElement>().ToArray();

            Assert.AreEqual(Speeches.StartRecording, nodes[0].Value, "record prompt");

            var recordNode = nodes[1];

            Assert.AreEqual("Record", recordNode.Name.LocalName, "tag name");
            Assert.AreEqual("http://localhost/api/voice/StopRecording", recordNode.Attribute("action").Value, "action value");
        }
Exemplo n.º 8
0
        public void UpdateSigninStatusOnAnswer()
        {
            var context = VoiceTestContext.GetDefault <VoiceTestContext>();

            context.SignIns.Add(new MemberSignIn {
                MemberId = context.Member.Id, TimeIn = DateTime.Now.AddMinutes(-5), Id = 5
            });

            var result = Task.Run(() => context.DoApiCall(VoiceTestContext.AnswerUrl)).Result;

            Assert.IsNotNull((from e in result.ToXDocument().Descendants("Gather")
                              from a in e.Attributes()
                              where a.Name == "action" && a.Value.Contains(BaseVoiceController.QueryFields.SignedInKey + "=1")
                              select a).SingleOrDefault(),
                             "action has 'signed in' query value");

            Assert.IsNotNull(result.ToXDocument().Descendants("Say").First().Value.Contains("sign out"), "contains text 'sign out'");
        }
Exemplo n.º 9
0
        public void FinishRecordMessage()
        {
            var context = VoiceTestContext.GetDefault <VoiceTestContext>();

            string recordingUrl      = "http://somelocation.tld/" + Guid.NewGuid().ToString();
            int    recordingDuration = 43;

            var request = context.CreateRequest(null);

            request.RecordingUrl      = recordingUrl;
            request.RecordingDuration = recordingDuration;

            var result = Task.Run(() => context.DoApiCall(VoiceTestContext.AnswerUrl)).Result;

            result = Task.Run(() => context.DoApiCall("http://localhost/api/voice/StopRecording", request)).Result;

            Assert.AreEqual(recordingDuration, context.Calls.Single().RecordingDuration, "duration");
            Assert.AreEqual(recordingUrl, context.Calls.Single().RecordingUrl, "url");
        }
Exemplo n.º 10
0
        public void QuickSignIn()
        {
            var context = VoiceTestContext.GetDefault <VoiceTestContext>();

            var result = Task.Run(() => context.DoApiCall(VoiceTestContext.AnswerUrl, (string)null)).Result;

            Assert.AreEqual(1, context.Calls.Count(), "rows in call table");
            Assert.AreEqual(context.From, context.Calls.Single().Number, "stored phone number");
            Assert.AreEqual(0, context.SignIns.Count(), "rows in signin table");

            var menuAction = (from e in result.ToXDocument().Descendants("Gather") select e.Attribute("action").Value).FirstOrDefault();

            Assert.IsTrue(menuAction.StartsWith("http://localhost/api/voice/DoMenu"), "action is DoMenu");

            result = Task.Run(() => context.DoApiCall(menuAction, "1")).Result;

            StringAssert.StartsWith("Signed in as Mr. Sandman", (from e in result.ToXDocument().Descendants("Say") select e.Value).FirstOrDefault(), "report signed in");
            Assert.AreEqual(1, context.SignIns.Count(), "sign in rows");
            Assert.AreEqual(null, context.SignIns.First().TimeOut, "time out is null");
            Assert.AreEqual(context.Member.Name, context.SignIns.First().Name, "name");
            Assert.AreEqual(context.Member.Id, context.SignIns.First().MemberId, "member id");
        }
Exemplo n.º 11
0
        public void AnswerKnownCallerOneMission()
        {
            var context  = VoiceTestContext.GetDefault <VoiceTestContext>();
            var theEvent = new SarEvent {
                Id = 3, Name = "Test Event", Opened = DateTime.Now.AddHours(-4), OutgoingUrl = "https://example.com/sample.mp3"
            };

            context.EventsServiceMock
            .Setup(f => f.ListActive()).Returns(() => Task.FromResult(new List <SarEvent> {
                theEvent
            }));

            var expectedText = string.Format(Speeches.CurrentEventTemplate, theEvent.Name)
                               + theEvent.OutgoingUrl
                               + GetKnownMemberSigninPrompt(context)
                               + string.Format(Speeches.PromptRecordMessageTemplate, 3)
                               + string.Format(Speeches.PromptChangeResponder, 8)
                               + string.Format(Speeches.PromptAdminMenu, 9);

            var response = AnswerCallCheckResult(context, expectedText);

            Assert.IsTrue(response.Descendants("Play").First().Value == theEvent.OutgoingUrl, "says outgoing message");
        }
Exemplo n.º 12
0
        public void Signout()
        {
            var context = VoiceTestContext.GetDefault <VoiceTestContext>();
            var signin  = new MemberSignIn
            {
                Id       = 24,
                isMember = true,
                MemberId = context.Member.Id,
                Name     = context.Member.Name,
                TimeIn   = DateTime.Now.AddHours(-7.5)
            };

            context.SignIns.Add(signin);

            string expectedAnswer = string.Format(Speeches.PressOneTemplate,
                                                  string.Format(Speeches.PromptSignOutTemplate, string.Format(Speeches.AsMemberTemplate, context.Member.Name)))
                                    + string.Format(Speeches.PromptRecordMessageTemplate, 3)
                                    + string.Format(Speeches.PromptChangeResponder, 8)
                                    + string.Format(Speeches.PromptAdminMenu, 9);


            var result  = AnswerCallCheckResult(context, expectedAnswer);
            var element = result.Root.FirstNode as XElement;

            Assert.AreEqual("Gather", element.Name.LocalName, "expected answer gather step");
            var url = element.Attribute("action").Value;


            DateTimeOffset markerA = TimeUtils.GetLocalDateTime(context.ConfigMock.Object);

            result = Task.Run(() => context.DoApiCall(url, digits: "1")).Result.ToXDocument();

            // Should mark the member signed out in the database
            Assert.IsTrue(signin.TimeOut.HasValue &&
                          signin.TimeOut.Value <= TimeUtils.GetLocalDateTime(context.ConfigMock.Object) &&
                          signin.TimeOut.Value >= markerA, "default time out in range");
            var defaultTimeout = signin.TimeOut.Value;

            element = result.Root.FirstNode as XElement;
            Assert.AreEqual("Gather", element.Name.LocalName, "expected gather step 1");
            url = element.Attribute("action").Value;

            // Should ask for more information
            Assert.AreEqual("SetTimeOut", context.GetActionMethod(url).Name, "next prompt is set time out");

            // The call should be tracking the caller as signed out
            Assert.False(url.Contains(VoiceController.QueryFields.SignedInKey + "=1"), "action does not have signed in query value");

            // Update the time out for an hour from now.
            result = Task.Run(() => context.DoApiCall(url, "60")).Result.ToXDocument();
            Assert.AreEqual(
                string.Format(Speeches.SignedOutTemplate, context.Member.Name, TimeUtils.GetMiltaryTimeVoiceText(signin.TimeOut.Value)),
                result.Descendants("Say").First().Value,
                "report updated time out");
            Assert.AreEqual(defaultTimeout.AddMinutes(60), signin.TimeOut.Value, "updated time out");

            element = result.Root.FirstNode as XElement;
            Assert.AreEqual("Gather", element.Name.LocalName, "expected gather step 2");
            url = element.Attribute("action").Value;

            Assert.AreEqual("SetMiles", context.GetActionMethod(url).Name, "next prompt is set miles");

            // The caller updates their miles
            result = Task.Run(() => context.DoApiCall(url, "120")).Result.ToXDocument();
            Assert.AreEqual(Speeches.MilesUpdated, result.Descendants("Say").First().Value, "report updated miles");
            Assert.AreEqual(120, signin.Miles.Value, "updated miles");
        }