Example #1
0
        public async Task SavesTurnStateUsingMockWithVirtualSaveChangesAsync()
        {
            // Note: this test requires that SaveChangesAsync is made virtual in order to be able to create a mock.
            var memoryStorage         = new MemoryStorage();
            var mockConversationState = new Mock <ConversationState>(memoryStorage)
            {
                CallBase = true,
            };

            var mockUserState = new Mock <UserState>(memoryStorage)
            {
                CallBase = true,
            };

            var mockRootDialog = SimpleMockFactory.CreateMockDialog <Dialog>(null, "mockRootDialog");
            var mockLogger     = new Mock <ILogger <DialogBot <Dialog> > >();

            // Act
            var sut         = new DialogBot <Dialog>(mockConversationState.Object, mockUserState.Object, mockRootDialog.Object, mockLogger.Object);
            var testAdapter = new TestAdapter();
            var testFlow    = new TestFlow(testAdapter, sut);
            await testFlow.Send("Hi").StartTestAsync();

            // Assert that SaveChangesAsync was called
            mockConversationState.Verify(x => x.SaveChangesAsync(It.IsAny <TurnContext>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once);
            mockUserState.Verify(x => x.SaveChangesAsync(It.IsAny <TurnContext>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once);
        }
Example #2
0
        public async Task LogsInformationToILogger()
        {
            // Arrange
            var memoryStorage     = new MemoryStorage();
            var conversationState = new ConversationState(memoryStorage);
            var userState         = new UserState(memoryStorage);

            var mockRootDialog = SimpleMockFactory.CreateMockDialog <Dialog>(null, "mockRootDialog");
            var mockLogger     = new Mock <ILogger <DialogBot <Dialog> > >();

            mockLogger.Setup(x =>
                             x.Log(It.IsAny <LogLevel>(), It.IsAny <EventId>(), It.IsAny <object>(), null, It.IsAny <Func <object, Exception, string> >()));

            // Run the bot
            var sut         = new DialogBot <Dialog>(conversationState, userState, mockRootDialog.Object, mockLogger.Object);
            var testAdapter = new TestAdapter();
            var testFlow    = new TestFlow(testAdapter, sut);
            await testFlow.Send("Hi").StartTestAsync();

            // Assert that log was changed with the expected parameters
            mockLogger.Verify(
                x => x.Log(
                    LogLevel.Information,
                    It.IsAny <EventId>(),
                    It.Is <object>(o => o.ToString() == "Running dialog with Message Activity."),
                    null,
                    It.IsAny <Func <object, Exception, string> >()),
                Times.Once);
        }
        public GetResultsController(IBotFrameworkHttpAdapter adapter, IConfiguration configuration, ConversationState conversationState,
                                    ILogger <MainDialog> logger,
                                    ConcurrentDictionary <string, ConversationReference> conversationReferences,
                                    ICredentialProvider credentialProvider, IBot bot)
        {
            this.bot = bot as DialogBot <MainDialog>;
            _adapter = adapter;
            _conversationReferences = conversationReferences;
            ConversationState       = conversationState;
            _appId       = configuration["MicrosoftAppId"];
            _appPassword = configuration["MicrosoftAppPassword"];
            _botId       = configuration["BotId"];
            _botName     = configuration["BotName"];

            _logger             = logger;
            _configuration      = configuration;
            _credentialProvider = credentialProvider;

            // If the channel is the Emulator, and authentication is not in use,
            // the AppId will be null.  We generate a random AppId for this case only.
            // This is not required for production, since the AppId will have a value.
            if (string.IsNullOrEmpty(_appId))
            {
                _appId = Guid.NewGuid().ToString(); //if no AppId, use a random Guid
            }
        }
        public async Task SavesTurnStateUsingMemoryStorage()
        {
            // TODO: Figure out how to implement this test.
            // Note: this doesn't require a virtual SaveChangesAsync and it manually inspects storage to ensure the save methods were called.
            var memoryStorage     = new MemoryStorage();
            var conversationState = new ConversationState(memoryStorage);
            var userState         = new UserState(memoryStorage);

            var mockRootDialog = new Mock <Dialog>("mockRootDialog");

            mockRootDialog.Setup(x => x.ContinueDialogAsync(It.IsAny <DialogContext>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new DialogTurnResult(DialogTurnStatus.Empty)));

            var mockLogger = new Mock <ILogger <DialogBot <Dialog> > >();

            // Run the bot
            var sut         = new DialogBot <Dialog>(conversationState, userState, mockRootDialog.Object, mockLogger.Object);
            var testAdapter = new TestAdapter();
            var testFlow    = new TestFlow(testAdapter, sut);
            await testFlow.Send("Hi").StartTestAsync();

            // Assert that SaveChangesAsyncWasCalled
            Assert.True(false, "TODO");
        }