Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
fix find contact issue (#2286)
Browse files Browse the repository at this point in the history
  • Loading branch information
KayMKM committed Sep 6, 2019
1 parent 2d2967f commit 000881e
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ protected async Task<string> GetReadyToSendNameListStringAsync(WaterfallStepCont
foreach (var person in personList)
{
var mailAddress = person.Emails[0] ?? person.UserPrincipalName;
if (mailAddress == null)
if (mailAddress == null || !IsEmail(mailAddress))
{
continue;
}
Expand All @@ -1377,7 +1377,7 @@ protected async Task<string> GetReadyToSendNameListStringAsync(WaterfallStepCont
foreach (var user in userList)
{
var mailAddress = user.Emails[0] ?? user.UserPrincipalName;
if (mailAddress == null)
if (mailAddress == null || !IsEmail(mailAddress))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
 using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
Expand Down Expand Up @@ -410,15 +410,18 @@ public FindContactDialog(
}
else
{
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(
FindContactResponses.UserNotFoundAgain,
new StringDictionary()
return await sc.PromptAsync(
Actions.Prompt,
new PromptOptions
{
{ "source", state.EventSource == Models.EventSource.Microsoft ? "Outlook" : "Gmail" },
{ "UserName", currentRecipientName }
}));
state.MeetingInfor.ContactInfor.CurrentContactName = string.Empty;
return await sc.EndDialogAsync();
Prompt = ResponseManager.GetResponse(
FindContactResponses.UserNotFoundAgain,
new StringDictionary()
{
{ "source", state.EventSource == Models.EventSource.Microsoft ? "Outlook" : "Gmail" },
{ "UserName", currentRecipientName }
})
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,49 @@ await GetTestFlow()
.StartTestAsync();
}

[TestMethod]
public async Task Test_CalendarCreateWithWrongContactName()
{
var peopleCount = 3;
ServiceManager = MockServiceManager.SetPeopleToMultiple(peopleCount);
var testRecipient = string.Format(Strings.Strings.UserName, 0);
var testEmailAddress = string.Format(Strings.Strings.UserEmailAddress, 0);
var recipientDict = new StringDictionary() { { "UserName", testRecipient }, { "EmailAddress", testEmailAddress } };

await GetTestFlow()
.Send(CreateMeetingTestUtterances.BaseCreateMeeting)
.AssertReply(ShowAuth())
.Send(GetAuthResponse())
.AssertReplyOneOf(AskForParticpantsPrompt())
.Send("wrong name")
.AssertReplyOneOf(UserNotFoundPrompt("wrong name"))
.Send("wrong name")
.AssertReplyOneOf(UserNotFoundAgainPrompt("wrong name"))
.Send(string.Format(Strings.Strings.UserName, 0))
.AssertReplyOneOf(ConfirmOneNameOneAddress(recipientDict))
.Send(Strings.Strings.ConfirmYes)
.AssertReplyOneOf(AddMoreUserPrompt(testRecipient, testEmailAddress))
.Send(Strings.Strings.ConfirmNo)
.AssertReplyOneOf(AskForSubjectWithContactNamePrompt(testRecipient, testEmailAddress))
.Send(Strings.Strings.DefaultEventName)
.AssertReplyOneOf(AskForContentPrompt())
.Send(Strings.Strings.DefaultContent)
.AssertReplyOneOf(AskForDatePrompt())
.Send(Strings.Strings.DefaultStartDate)
.AssertReplyOneOf(AskForStartTimePrompt())
.Send(Strings.Strings.DefaultStartTime)
.AssertReplyOneOf(AskForDurationPrompt())
.Send(Strings.Strings.DefaultDuration)
.AssertReplyOneOf(AskForLocationPrompt())
.Send(Strings.Strings.DefaultLocation)
.AssertReply(ShowCalendarList())
.AssertReplyOneOf(ConfirmPrompt())
.Send(Strings.Strings.ConfirmYes)
.AssertReply(ShowCalendarList())
.AssertReply(ActionEndMessage())
.StartTestAsync();
}

[TestMethod]
public async Task Test_CalendarCreateWithOneContactMultipleEmails()
{
Expand Down Expand Up @@ -1006,5 +1049,21 @@ private string RestParticipantsResponse(int count)

return resultString;
}

private string[] UserNotFoundPrompt(string userName)
{
return ParseReplies(FindContactResponses.UserNotFound, new StringDictionary() { { "UserName", userName } });
}

private string[] UserNotFoundAgainPrompt(string userName)
{
return ParseReplies(
FindContactResponses.UserNotFoundAgain,
new StringDictionary()
{
{ "source", "Outlook" },
{ "UserName", userName }
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public static IServiceManager SetPeopleToMultiple(int count)
return Task.FromResult(result);
});
mockUserService.Setup(service => service.GetUserAsync(It.IsAny<string>())).Returns((string name) =>
{
return Task.FromResult(new List<PersonModel>());
});
return mockServiceManager.Object;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using CalendarSkill.Prompts;
using CalendarSkill.Prompts.Options;
using CalendarSkillTest.Flow.Fakes;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Microsoft.Recognizers.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.Bot.Builder.Dialogs.Tests
namespace CalendarSkillTest.Prompt
{
[TestClass]
public class GetEventPromptTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,22 +411,24 @@ public FindContactDialog(
FindContactResponses.UserNotFound,
new StringDictionary()
{
{ "UserName", currentRecipientName }
{ "UserName", currentRecipientName }
})
});
}
else
{
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(
FindContactResponses.UserNotFoundAgain,
new StringDictionary()
return await sc.PromptAsync(
FindContactAction.Prompt,
new PromptOptions
{
{ "source", state.MailSourceType == MailSource.Microsoft ? "Outlook" : "Gmail" },
{ "UserName", currentRecipientName }
}));
state.FindContactInfor.FirstRetryInFindContact = true;
state.FindContactInfor.CurrentContactName = string.Empty;
return await sc.EndDialogAsync();
Prompt = ResponseManager.GetResponse(
FindContactResponses.UserNotFoundAgain,
new StringDictionary()
{
{ "source", state.MailSourceType == MailSource.Microsoft ? "Outlook" : "Gmail" },
{ "UserName", currentRecipientName }
})
});
}
}

Expand Down Expand Up @@ -786,6 +788,10 @@ await sc.Context.SendActivityAsync(ResponseManager.GetResponse(
foreach (var person in personList)
{
var mailAddress = person.Emails[0] ?? person.UserPrincipalName;
if (mailAddress == null || !Util.IsEmail(mailAddress))
{
continue;
}

var isDup = false;
foreach (var formattedPerson in formattedPersonList)
Expand All @@ -808,6 +814,10 @@ await sc.Context.SendActivityAsync(ResponseManager.GetResponse(
foreach (var user in userList)
{
var mailAddress = user.Emails[0] ?? user.UserPrincipalName;
if (mailAddress == null || !Util.IsEmail(mailAddress))
{
continue;
}

var isDup = false;
foreach (var formattedPerson in formattedPersonList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,43 @@ await this.GetTestFlow()
.StartTestAsync();
}

[TestMethod]
public async Task Test_SendEmailToWrongUser()
{
string testRecipient = ContextStrings.TestRecipient;
string testEmailAddress = ContextStrings.TestEmailAdress;

StringDictionary recipientDict = new StringDictionary() { { "UserName", testRecipient }, { "EmailAddress", testEmailAddress } };
StringDictionary recipientList = new StringDictionary() { { "NameList", testRecipient + ": " + testEmailAddress } };

await this.GetTestFlow()
.Send(SendEmailUtterances.SendEmails)
.AssertReply(this.ShowAuth())
.Send(this.GetAuthResponse())
.AssertReplyOneOf(this.CollectRecipientsMessage())
.Send("wrong name")
.AssertReplyOneOf(this.UserNotFoundPrompt("wrong name"))
.Send("wrong name")
.AssertReplyOneOf(this.UserNotFoundAgainPrompt("wrong name"))
.Send(ContextStrings.TestRecipient)
.AssertReplyOneOf(this.ConfirmOneNameOneAddress(recipientDict))
.Send(GeneralTestUtterances.Yes)
.AssertReplyOneOf(this.AddMoreContacts(recipientList))
.Send(GeneralTestUtterances.No)
.AssertReply(this.CollectSubjectMessage(recipientDict))
.Send(ContextStrings.TestSubject)
.AssertReplyOneOf(this.CollectEmailContentMessage())
.Send(ContextStrings.TestContent)
.AssertReply(this.AssertContentPlayback())
.AssertReply(this.AssertCheckContent())
.Send(GeneralTestUtterances.Yes)
.AssertReply(this.AssertComfirmBeforeSendingPrompt())
.Send(GeneralTestUtterances.Yes)
.AssertReply(this.AfterSendingMessage(ContextStrings.TestSubject))
.AssertReply(this.ActionEndMessage())
.StartTestAsync();
}

private Action<IActivity> AfterSendingMessage(string subject)
{
return activity =>
Expand Down Expand Up @@ -414,6 +451,22 @@ private string[] CollectRecipientsMessage()
return this.ParseReplies(EmailSharedResponses.NoRecipients, new StringDictionary());
}

private string[] UserNotFoundPrompt(string userName)
{
return ParseReplies(FindContactResponses.UserNotFound, new StringDictionary() { { "UserName", userName } });
}

private string[] UserNotFoundAgainPrompt(string userName)
{
return ParseReplies(
FindContactResponses.UserNotFoundAgain,
new StringDictionary()
{
{ "source", "Outlook" },
{ "UserName", userName }
});
}

private Action<IActivity> CollectRecipients()
{
return activity =>
Expand Down

0 comments on commit 000881e

Please sign in to comment.