2017-05-01 28 views
1

私は現在、ボットのユニットテストを作成しようとしていますが、レスポンスを取得しようとすると、テストは必ず失敗します。 DialogTestBaseを継承した模擬テストを作成しました。Microsoft Bot Framework - ユニットテストの失敗

[TestClass] 
public class Tests : DialogTestBase 
{ 
    [TestMethod] 
    public async Task TestDialogTest() 
    { 
     await TestDialogFlow(new TestDialog()); 
    } 

    private async Task TestDialogFlow(IDialog<object> echoDialog) 
    { 
     // arrange 
     var toBot = DialogTestBase.MakeTestMessage(); 
     toBot.From.Id = Guid.NewGuid().ToString(); 
     toBot.Text = "Hi"; 

     Func<IDialog<object>> MakeRoot =() => echoDialog; 

     using (new FiberTestBase.ResolveMoqAssembly(echoDialog)) 
     using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, echoDialog)) 
     { 
      IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot); 

      Assert.IsTrue(toUser.Text.StartsWith("Hello")); 
     } 
    } 

    private async Task<IMessageActivity> GetResponse(IContainer container, Func<IDialog<object>> makeRoot, IMessageActivity toBot) 
    { 
     using (var scope = DialogModule.BeginLifetimeScope(container, toBot)) 
     { 
      DialogModule_MakeRoot.Register(scope, makeRoot); 

      // act: sending the message 
      await Conversation.SendAsync(toBot, makeRoot); 
      return scope.Resolve<Queue<IMessageActivity>>().Dequeue(); 
     } 
    } 
} 

私はテストだダイアログは次のとおりです。

[Serializable] 
public class TestDialog : IDialog 
{ 
    public async Task StartAsync(IDialogContext context) 
    { 
     context.Wait(ProcessMessage); 
    } 

    public async Task ProcessMessage(IDialogContext context, IAwaitable<IMessageActivity> argument) 
    { 
     await context.PostAsync("Hello. I'm a bot"); 
     await context.PostAsync("How can I help?"); 

     context.Wait(ProcessRequest); 
    } 

    public async Task ProcessRequest(IDialogContext context, IAwaitable<IMessageActivity> argument) 
    { 
     var request = await argument; 

     await context.PostAsync($"You asked the following question: {request}"); 

     context.Done(true); 
    } 
} 

私は、私は次のエラーを取得するテストを実行する場合:

Autofac.Core.DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> Invalid URI: The format of the URI could not be determined. (See inner exception for details.) --->System.UriFormatException: Invalid URI: The format of the URI could not be determined.

を我々が送信するときに問題がのGetResponseメソッドで発生リクエスト。どんな助けでも大歓迎です。

答えて

1

GetResponse方法は、実際のパラメータとしてscopetoBotを使用してSendAsyncを呼び出す必要があります。

await Conversation.SendAsync(toBot, makeRoot); 

私はあなたが共有していると、この変更を行った後、テストにパスコードを試してみました。

関連する問題