Skip to content

Commit 14b6554

Browse files
Zerrythsgellock
andauthored
Dates in samples are now dynamically populated instead of hard-coded (microsoft#2364)
* C# sample 13.core-bot now gives date to be 1 week later * Updated sample C# sample 21.corebot-app-insights date * Updated C# dates to take week-later date rather than hardcoded date * Removed hardcoded date from JS samples using momentjs Co-authored-by: Scott Gellock <[email protected]>
1 parent e677375 commit 14b6554

File tree

10 files changed

+38
-18
lines changed

10 files changed

+38
-18
lines changed

samples/csharp_dotnetcore/13.core-bot.tests/Dialogs/MainDialogTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public async Task ShowsPromptIfLuisIsConfigured()
8383

8484
// Act/Assert
8585
var reply = await testClient.SendActivityAsync<IMessageActivity>("hi");
86-
Assert.Equal("What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on March 22, 2020\"", reply.Text);
86+
var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy");
87+
Assert.Equal($"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"", reply.Text);
8788
}
8889

8990
[Theory]
@@ -110,7 +111,8 @@ public async Task TaskSelector(string utterance, string intent, string invokedDi
110111
// Execute the test case
111112
Output.WriteLine($"Test Case: {intent}");
112113
var reply = await testClient.SendActivityAsync<IMessageActivity>("hi");
113-
Assert.Equal("What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on March 22, 2020\"", reply.Text);
114+
var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy");
115+
Assert.Equal($"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"", reply.Text);
114116

115117
reply = await testClient.SendActivityAsync<IMessageActivity>(utterance);
116118
Assert.Equal(invokedDialogResponse, reply.Text);
@@ -148,7 +150,8 @@ public async Task ShowsUnsupportedCitiesWarning(string jsonFile, string expected
148150
// Execute the test case
149151
Output.WriteLine($"Test Case: {mockLuisResult.Text}");
150152
var reply = await testClient.SendActivityAsync<IMessageActivity>("hi");
151-
Assert.Equal("What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on March 22, 2020\"", reply.Text);
153+
var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy");
154+
Assert.Equal($"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"", reply.Text);
152155

153156
reply = await testClient.SendActivityAsync<IMessageActivity>(mockLuisResult.Text);
154157
Assert.Equal(expectedMessage, reply.Text);

samples/csharp_dotnetcore/13.core-bot/Dialogs/MainDialog.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ await stepContext.Context.SendActivityAsync(
5050
}
5151

5252
// Use the text provided in FinalStepAsync or the default if it is the first time.
53-
var messageText = stepContext.Options?.ToString() ?? "What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on March 22, 2020\"";
53+
var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy");
54+
var messageText = stepContext.Options?.ToString() ?? $"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"";
5455
var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
5556
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
5657
}

samples/csharp_dotnetcore/21.corebot-app-insights/Dialogs/MainDialog.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ await stepContext.Context.SendActivityAsync(
5050
}
5151

5252
// Use the text provided in FinalStepAsync or the default if it is the first time.
53-
var messageText = stepContext.Options?.ToString() ?? "What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on March 22, 2020\"";
53+
var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy");
54+
var messageText = stepContext.Options?.ToString() ?? $"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"";
5455
var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
5556
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
5657
}

samples/csharp_webapi/13.core-bot/Dialogs/MainDialog.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ await stepContext.Context.SendActivityAsync(
5050
}
5151

5252
// Use the text provided in FinalStepAsync or the default if it is the first time.
53-
var messageText = stepContext.Options?.ToString() ?? "What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on March 22, 2020\"";
53+
var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy");
54+
var messageText = stepContext.Options?.ToString() ?? $"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"";
5455
var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
5556
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
5657
}

samples/javascript_nodejs/13.core-bot/dialogs/mainDialog.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { TimexProperty } = require('@microsoft/recognizers-text-data-types-timex-
55
const { MessageFactory, InputHints } = require('botbuilder');
66
const { LuisRecognizer } = require('botbuilder-ai');
77
const { ComponentDialog, DialogSet, DialogTurnStatus, TextPrompt, WaterfallDialog } = require('botbuilder-dialogs');
8+
const moment = require('moment-timezone');
89

910
const MAIN_WATERFALL_DIALOG = 'mainWaterfallDialog';
1011

@@ -59,7 +60,8 @@ class MainDialog extends ComponentDialog {
5960
return await stepContext.next();
6061
}
6162

62-
const messageText = stepContext.options.restartMsg ? stepContext.options.restartMsg : 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"';
63+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
64+
const messageText = stepContext.options.restartMsg ? stepContext.options.restartMsg : `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`;
6365
const promptMessage = MessageFactory.text(messageText, messageText, InputHints.ExpectingInput);
6466
return await stepContext.prompt('TextPrompt', { prompt: promptMessage });
6567
}

samples/javascript_nodejs/13.core-bot/tests/dialogs/mainDialog.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { FlightBookingRecognizer } = require('../../dialogs/flightBookingRecogniz
1010
const { MainDialog } = require('../../dialogs/mainDialog');
1111
const { BookingDialog } = require('../../dialogs/bookingDialog');
1212
const assert = require('assert');
13+
const moment = require('moment-timezone');
1314

1415
/**
1516
* A mock FlightBookingRecognizer for our main dialog tests that takes
@@ -84,7 +85,8 @@ describe('MainDialog', () => {
8485
const client = new DialogTestClient('test', sut, null, [new DialogTestLogger()]);
8586

8687
const reply = await client.sendActivity('hi');
87-
assert.strictEqual(reply.text, 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"', 'Did not show prompt');
88+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
89+
assert.strictEqual(reply.text, `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`, 'Did not show prompt');
8890
});
8991

9092
describe('Invokes tasks based on LUIS intent', () => {
@@ -107,7 +109,8 @@ describe('MainDialog', () => {
107109
// Execute the test case
108110
console.log(`Test Case: ${ testData.intent }`);
109111
let reply = await client.sendActivity('Hi');
110-
assert.strictEqual(reply.text, 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"');
112+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
113+
assert.strictEqual(reply.text, `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`);
111114

112115
reply = await client.sendActivity(testData.utterance);
113116
assert.strictEqual(reply.text, testData.invokedDialogResponse);
@@ -146,7 +149,8 @@ describe('MainDialog', () => {
146149
// Execute the test case
147150
console.log(`Test Case: ${ mockLuisResult.text }`);
148151
let reply = await client.sendActivity('Hi');
149-
assert.strictEqual(reply.text, 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"');
152+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
153+
assert.strictEqual(reply.text, `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`);
150154

151155
reply = await client.sendActivity(mockLuisResult.text);
152156
assert.strictEqual(reply.text, testData.expectedMessage);

samples/javascript_nodejs/21.corebot-app-insights/dialogs/mainDialog.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { TimexProperty } = require('@microsoft/recognizers-text-data-types-timex-
55
const { MessageFactory, InputHints } = require('botbuilder');
66
const { LuisRecognizer } = require('botbuilder-ai');
77
const { ComponentDialog, DialogSet, DialogTurnStatus, TextPrompt, WaterfallDialog } = require('botbuilder-dialogs');
8+
const moment = require('moment-timezone');
89

910
const MAIN_WATERFALL_DIALOG = 'mainWaterfallDialog';
1011

@@ -58,8 +59,8 @@ class MainDialog extends ComponentDialog {
5859
await stepContext.context.sendActivity(messageText, null, InputHints.IgnoringInput);
5960
return await stepContext.next();
6061
}
61-
62-
const messageText = stepContext.options.restartMsg ? stepContext.options.restartMsg : 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"';
62+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
63+
const messageText = stepContext.options.restartMsg ? stepContext.options.restartMsg : `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`;
6364
const promptMessage = MessageFactory.text(messageText, messageText, InputHints.ExpectingInput);
6465
return await stepContext.prompt('TextPrompt', { prompt: promptMessage });
6566
}

samples/javascript_nodejs/21.corebot-app-insights/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"eslint-plugin-node": "^11.1.0",
3333
"eslint-plugin-promise": "^4.2.1",
3434
"eslint-plugin-standard": "^4.0.1",
35+
"moment-timezone": "^0.5.28",
3536
"nodemon": "~2.0.4"
37+
"path": "^0.12.7",
38+
"restify": "^8.4.0"
3639
}
3740
}

samples/typescript_nodejs/13.core-bot/src/dialogs/mainDialog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
43
import { TimexProperty } from '@microsoft/recognizers-text-data-types-timex-expression';
54
import { BookingDetails } from './bookingDetails';
65

@@ -19,6 +18,7 @@ import {
1918
} from 'botbuilder-dialogs';
2019
import { BookingDialog } from './bookingDialog';
2120
import { FlightBookingRecognizer } from './flightBookingRecognizer';
21+
const moment = require('moment');
2222

2323
const MAIN_WATERFALL_DIALOG = 'mainWaterfallDialog';
2424

@@ -73,8 +73,8 @@ export class MainDialog extends ComponentDialog {
7373
await stepContext.context.sendActivity(luisConfigMsg, null, InputHints.IgnoringInput);
7474
return await stepContext.next();
7575
}
76-
77-
const messageText = (stepContext.options as any).restartMsg ? (stepContext.options as any).restartMsg : 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"';
76+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
77+
const messageText = (stepContext.options as any).restartMsg ? (stepContext.options as any).restartMsg : `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`;
7878
const promptMessage = MessageFactory.text(messageText, messageText, InputHints.ExpectingInput);
7979
return await stepContext.prompt('TextPrompt', { prompt: promptMessage });
8080
}

samples/typescript_nodejs/13.core-bot/src/tests/dialogs/mainDialog.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { BookingDialog } from '../../dialogs/bookingDialog';
88
import { FlightBookingRecognizer } from '../../dialogs/flightBookingRecognizer';
99
import { MainDialog } from '../../dialogs/mainDialog';
1010
const assert = require('assert');
11+
const moment = require('moment-timezone');
1112

1213
// tslint:disable max-classes-per-file
1314
/**
@@ -84,7 +85,8 @@ describe('MainDialog', () => {
8485
const client = new DialogTestClient('test', sut, null, [new DialogTestLogger()]);
8586

8687
const reply = await client.sendActivity('hi');
87-
assert.strictEqual(reply.text, 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"', 'Did not show prompt');
88+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
89+
assert.strictEqual(reply.text, `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`, 'Did not show prompt');
8890
});
8991

9092
describe('Invokes tasks based on LUIS intent', () => {
@@ -107,7 +109,8 @@ describe('MainDialog', () => {
107109
// Execute the test case
108110
console.log(`Test Case: ${ testData.intent }`);
109111
let reply = await client.sendActivity('Hi');
110-
assert.strictEqual(reply.text, 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"');
112+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
113+
assert.strictEqual(reply.text, `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`);
111114

112115
reply = await client.sendActivity(testData.utterance);
113116
assert.strictEqual(reply.text, testData.invokedDialogResponse);
@@ -146,7 +149,8 @@ describe('MainDialog', () => {
146149
// Execute the test case
147150
console.log(`Test Case: ${ mockLuisResult.text }`);
148151
let reply = await client.sendActivity('Hi');
149-
assert.strictEqual(reply.text, 'What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on March 22, 2020"');
152+
const weekLaterDate = moment().add(7, 'days').format('MMMM D, YYYY');
153+
assert.strictEqual(reply.text, `What can I help you with today?\nSay something like "Book a flight from Paris to Berlin on ${weekLaterDate}"`);
150154

151155
reply = await client.sendActivity(mockLuisResult.text);
152156
assert.strictEqual(reply.text, testData.expectedMessage);

0 commit comments

Comments
 (0)