Esempio n. 1
0
        public async void ProcessAsyncWithEvenTypeCreatedShouldSucceed()
        {
            var message = JsonConvert.DeserializeObject <Message>(File.ReadAllText(PathUtils.NormalizePath(Directory.GetCurrentDirectory() + @"\Files\Message.json")));
            var payload = File.ReadAllText(PathUtils.NormalizePath(Directory.GetCurrentDirectory() + @"/Files/Payload.json"));
            var stream  = new MemoryStream(Encoding.UTF8.GetBytes(payload.ToString()));
            var call    = false;

            var webexApi = new Mock <WebexClientWrapper>(_testOptions);

            webexApi.SetupAllProperties();
            webexApi.Setup(x => x.GetMeAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(_identity));
            webexApi.Setup(x => x.ValidateSignature(It.IsAny <HttpRequest>(), It.IsAny <string>())).Returns(true);
            webexApi.Setup(x => x.GetMessageAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(message));

            var webexAdapter = new WebexAdapter(webexApi.Object, _adapterOptions);

            var httpRequest = new Mock <HttpRequest>();

            httpRequest.SetupGet(req => req.Body).Returns(stream);

            var httpResponse = new Mock <HttpResponse>();
            var bot          = new Mock <IBot>();

            bot.Setup(x => x.OnTurnAsync(It.IsAny <TurnContext>(), It.IsAny <CancellationToken>())).Callback(() =>
            {
                call = true;
            });

            await webexAdapter.ProcessAsync(httpRequest.Object, httpResponse.Object, bot.Object, default);

            Assert.True(call);
        }
Esempio n. 2
0
        public async void ContinueConversationAsyncShouldFailWithNullLogic()
        {
            var webexAdapter          = new WebexAdapter(new Mock <WebexClientWrapper>(_testOptions).Object, _adapterOptions);
            var conversationReference = new ConversationReference();

            await Assert.ThrowsAsync <ArgumentNullException>(async() => { await webexAdapter.ContinueConversationAsync(conversationReference, null, default); });
        }
Esempio n. 3
0
        public async void ProcessAsyncShouldFailWithNullHttpResponse()
        {
            var webexAdapter = new WebexAdapter(new Mock <WebexClientWrapper>(_testOptions).Object, _adapterOptions);
            var httpRequest  = new Mock <HttpRequest>();
            var bot          = new Mock <IBot>();

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await webexAdapter.ProcessAsync(httpRequest.Object, null, default, default);
Esempio n. 4
0
        public async void ContinueConversationAsyncShouldFailWithNullConversationReference()
        {
            var webexAdapter = new WebexAdapter(new Mock <WebexClientWrapper>(_testOptions).Object, _adapterOptions);

            Task BotsLogic(ITurnContext turnContext, CancellationToken cancellationToken)
            {
                return(Task.CompletedTask);
            }

            await Assert.ThrowsAsync <ArgumentNullException>(async() => { await webexAdapter.ContinueConversationAsync(null, BotsLogic, default); });
        }
Esempio n. 5
0
        public async void ContinueConversationAsyncShouldSucceed()
        {
            var callbackInvoked = false;

            var webexAdapter          = new WebexAdapter(new Mock <WebexClientWrapper>(_testOptions).Object, _adapterOptions);
            var conversationReference = new ConversationReference();

            Task BotsLogic(ITurnContext turnContext, CancellationToken cancellationToken)
            {
                callbackInvoked = true;
                return(Task.CompletedTask);
            }

            await webexAdapter.ContinueConversationAsync(conversationReference, BotsLogic, default);

            Assert.True(callbackInvoked);
        }
Esempio n. 6
0
 public WebexController(WebexAdapter adapter, IBot bot)
 {
     _adapter = adapter;
     _bot     = bot;
 }