public async Task GetActivityFromRingCentralRequestAsync_WhatsAppContentImportedMissingBodyText_ReturnsUnknownEventAndNullActivity(string jsonFile)
        {
            // Arrange
            var request            = new Mock <HttpRequest>();
            var response           = new Mock <HttpResponse>();
            var ringCentralRequest = GetEmbeddedTestData($"{GetType().Namespace}.TestData.{jsonFile}");

            using var ms = new MemoryStream();
            using var sw = new StreamWriter(ms);
            sw.Write(ringCentralRequest);
            sw.Flush();
            ms.Position = 0;
            request.Setup(x => x.Body).Returns(ms);
            request.Setup(x => x.Path).Returns(PathString.FromUriComponent("/contentimport"));
            response.Setup(x => x.Body).Returns(new MemoryStream());

            var mockOptions = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "abc", RingCentralEngageApiUrl = "http://localhost", BotId = "testbot", RingCentralEngageBotControlledThreadCategoryId = "botcontrolled"
            };
            var mockRingCentralClient = new Mock <DimeloClient>();

            var sut            = new RingCentralClientWrapper(OptionsHelper.GetOptionsMonitor(mockOptions), new StaticHandoffRequestRecognizer());
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;
            var adapter        = new RingCentralAdapter(sut, mockBotAdapter, new StaticHandoffRequestRecognizer());

            // Act
            var(ringCentralWebhook, activity) = await sut.GetActivityFromRingCentralRequestAsync(adapter, mockBotAdapter, request.Object, response.Object);

            // Assert
            Assert.Equal(RingCentralHandledEvent.Unknown, ringCentralWebhook);
            Assert.Null(activity);
            response.VerifySet(x => x.StatusCode = StatusCodes.Status204NoContent);
        }
        public async Task GetActivityFromRingCentralRequestAsync_ImplementationInfoRequest_ReturnsActionAndNullActivity(string jsonFile)
        {
            // Arrange
            var request  = new Mock <HttpRequest>();
            var response = new DefaultHttpContext().Response;

            response.Body = new MemoryStream();
            var ringCentralRequest = GetEmbeddedTestData($"{GetType().Namespace}.TestData.{jsonFile}");

            using var ms = new MemoryStream();
            using var sw = new StreamWriter(ms);
            sw.Write(ringCentralRequest);
            sw.Flush();
            ms.Position = 0;
            request.Setup(x => x.Body).Returns(ms);
            request.Setup(x => x.Path).Returns(PathString.FromUriComponent("/action"));

            var mockOptions = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "abc", RingCentralEngageApiUrl = "http://localhost", BotId = "testbot"
            };
            var sut            = new RingCentralClientWrapper(OptionsHelper.GetOptionsMonitor(mockOptions), new StaticHandoffRequestRecognizer());
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;
            var adapter        = new RingCentralAdapter(sut, mockBotAdapter, new StaticHandoffRequestRecognizer());

            // Act
            var(ringCentralWebhook, activity) = await sut.GetActivityFromRingCentralRequestAsync(adapter, mockBotAdapter, request.Object, response);

            // Assert
            Assert.Equal(RingCentralHandledEvent.Action, ringCentralWebhook);
            Assert.Null(activity);
            Assert.Equal(StatusCodes.Status200OK, response.StatusCode);
        }
        public async void DeleteActivityAsyncShouldThrowNotSupportedException()
        {
            // Arrange
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;
            var mockOptions    = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "1111",
                RingCentralEngageApiUrl         = "http://someurl.com",
                BotId = "testbot"
            };
            var rcw      = new RingCentralClientWrapper(OptionsHelper.GetOptionsMonitor(mockOptions), new StaticHandoffRequestRecognizer());
            var adapter  = new RingCentralAdapter(rcw, mockBotAdapter, new StaticHandoffRequestRecognizer());
            var activity = new Activity();
            var conversationReference = new ConversationReference();

            // Act
            using (var turnContext = new TurnContext(adapter, activity))
            {
                // Assert
                await Assert.ThrowsAsync <NotImplementedException>(async() =>
                {
                    await adapter.DeleteActivityAsync(turnContext, conversationReference, default);
                });
            }
        }
        public async Task GetActivityFromRingCentralRequestAsync_UnspecificSourceRequest_ReturnsContentImportedAndUnspecificChannelId(string jsonFile)
        {
            // Arrange
            var request  = new Mock <HttpRequest>();
            var response = new DefaultHttpContext().Response;

            response.Body = new MemoryStream();
            var ringCentralRequest = GetEmbeddedTestData($"{GetType().Namespace}.TestData.{jsonFile}");

            using var ms = new MemoryStream();
            using var sw = new StreamWriter(ms);
            sw.Write(ringCentralRequest);
            sw.Flush();
            ms.Position = 0;
            request.Setup(x => x.Body).Returns(ms);
            request.Setup(x => x.Path).Returns(PathString.FromUriComponent("/contentimport"));

            var mockOptions = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "abc", RingCentralEngageApiUrl = "http://localhost", BotId = "testbot", RingCentralEngageBotControlledThreadCategoryId = "botcontrolled"
            };
            var mockRingCentralClient = new Mock <DimeloClient>();

            var sut            = new RingCentralClientWrapper(OptionsHelper.GetOptionsMonitor(mockOptions), new StaticHandoffRequestRecognizer());
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;
            var adapter        = new RingCentralAdapter(sut, mockBotAdapter, new StaticHandoffRequestRecognizer());

            // Act
            var(ringCentralWebhook, activity) = await sut.GetActivityFromRingCentralRequestAsync(adapter, mockBotAdapter, request.Object, response);

            // Assert
            Assert.Equal(RingCentralHandledEvent.ContentImported, ringCentralWebhook);
            Assert.Equal(RingCentralChannels.Unspecific, activity.ChannelId);
        }
        public async void SendActivitiesAsyncShouldSucceedAndNoActivityReturnedWithActivityTypeNotMessage()
        {
            // Arrange
            var activity = new Mock <Activity>().SetupAllProperties();

            activity.Object.Type        = ActivityTypes.Trace;
            activity.Object.Attachments = new List <Attachment> {
                new Attachment(contentUrl: "http://example.com")
            };
            activity.Object.Conversation = new ConversationAccount(id: "MockId");
            activity.Object.Text         = "Trace content";

            const string resourceIdentifier = "ringCentralContentId";
            var          mockOptions        = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "1111",
                RingCentralEngageApiUrl         = "http://someurl.com",
                BotId = "testbot"
            };

            var rcw            = new Mock <RingCentralClientWrapper>(OptionsHelper.GetOptionsMonitor(mockOptions));
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;

            rcw.Setup(x => x.SendContentToRingCentralAsync(activity.Object, "9f4bba850e69dc636a707fd6")).Returns(Task.FromResult(resourceIdentifier));
            var adapter = new RingCentralAdapter(rcw.Object, mockBotAdapter, new StaticHandoffRequestRecognizer());

            // Act
            var resourceResponses = await adapter.SendActivitiesAsync(null, new Activity[] { activity.Object }, default).ConfigureAwait(false);

            // Assert
            Assert.True(resourceResponses.Length == 0);
        }
        public void ConstructorWithAdapterApiWrapperSucceeds()
        {
            // Arrange
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;
            var mockOptions    = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "1111",
                RingCentralEngageApiUrl         = "http://someurl.com",
                BotId = "testbot"
            };
            var rcw = new RingCentralClientWrapper(OptionsHelper.GetOptionsMonitor(mockOptions), new StaticHandoffRequestRecognizer());

            // Act
            var sut = new RingCentralAdapter(rcw, mockBotAdapter, new StaticHandoffRequestRecognizer());

            // Assert
            Assert.NotNull(sut);
        }
        public async void SendActivitiesAsyncShouldSucceed()
        {
            var activity = new Mock <Activity>().SetupAllProperties();

            activity.Object.Type        = "message";
            activity.Object.Attachments = new List <Attachment> {
                new Attachment(contentUrl: "http://example.com")
            };
            activity.Object.Conversation = new ConversationAccount(id: "MockId");
            activity.Object.Text         = "Hello, Bot!";

            var turnContext = new Mock <ITurnContext>();

            turnContext.SetupGet(tc => tc.Activity).Returns(() =>
                                                            new Activity()
            {
                ChannelData = new RingCentralChannelData()
                {
                    SourceId = "9f4bba850e69dc636a707fd6",
                    ThreadId = "a_thread_id"
                }
            });

            const string resourceIdentifier = "ringCentralContentId";
            var          mockOptions        = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "1111",
                RingCentralEngageApiUrl         = "http://someurl.com",
                BotId = "testbot"
            };

            var rcw            = new Mock <RingCentralClientWrapper>(OptionsHelper.GetOptionsMonitor(mockOptions));
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;

            rcw.Setup(x => x.SendContentToRingCentralAsync(activity.Object, "9f4bba850e69dc636a707fd6")).Returns(Task.FromResult(resourceIdentifier));
            var adapter = new RingCentralAdapter(rcw.Object, mockBotAdapter, new StaticHandoffRequestRecognizer());

            var resourceResponses = await adapter.SendActivitiesAsync(turnContext.Object, new Activity[] { activity.Object }, default).ConfigureAwait(false);

            Assert.True(resourceResponses[0].Id == resourceIdentifier);
        }
        public async void ProcessAsyncShouldFailWithNullBot()
        {
            // Arrange
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;
            var mockOptions    = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "1111",
                RingCentralEngageApiUrl         = "http://someurl.com",
                BotId = "testbot"
            };
            var rcw          = new RingCentralClientWrapper(OptionsHelper.GetOptionsMonitor(mockOptions), new StaticHandoffRequestRecognizer());
            var adapter      = new RingCentralAdapter(rcw, mockBotAdapter, new StaticHandoffRequestRecognizer());
            var httpRequest  = new Mock <HttpRequest>();
            var httpResponse = new Mock <HttpResponse>();

            // Act & Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await adapter.ProcessAsync(httpRequest.Object, httpResponse.Object, null, default);
            });
        }
        public async Task GetActivityFromRingCentralRequestAsync_ActionRequest_ReturnsActionAndActivityText(string jsonFile, string expectedMessage)
        {
            // Arrange
            var request  = new Mock <HttpRequest>();
            var response = new DefaultHttpContext().Response;

            response.Body = new MemoryStream();
            var ringCentralRequest = GetEmbeddedTestData($"{GetType().Namespace}.TestData.{jsonFile}");

            using var ms = new MemoryStream();
            using var sw = new StreamWriter(ms);
            sw.Write(ringCentralRequest);
            sw.Flush();
            ms.Position = 0;
            request.Setup(x => x.Body).Returns(ms);
            request.Setup(x => x.Path).Returns(PathString.FromUriComponent("/action"));

            var mockOptions = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = "abc", RingCentralEngageApiUrl = "http://localhost", BotId = "testbot", MicrosoftAppId = "appId"
            };
            var sut = new RingCentralClientWrapper(OptionsHelper.GetOptionsMonitor(mockOptions), new StaticHandoffRequestRecognizer());

            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>();

            mockBotAdapter.As <IAdapterIntegration>().Setup(x => x.ContinueConversationAsync(mockOptions.BotId, new ConversationReference(), null, default)).Returns(Task.CompletedTask);
            mockBotAdapter.Verify();
            var adapter = new RingCentralAdapter(sut, mockBotAdapter.Object, new StaticHandoffRequestRecognizer());

            // Act
            var(ringCentralWebhook, activity) = await sut.GetActivityFromRingCentralRequestAsync(adapter, mockBotAdapter.Object, request.Object, response);

            // Assert
            Assert.Equal(RingCentralHandledEvent.Action, ringCentralWebhook);
            Assert.Equal(expectedMessage, activity.Text);
            Assert.Equal(StatusCodes.Status200OK, response.StatusCode);
        }
        public async Task GetActivityFromRingCentralRequestAsync_WhatsAppRequest_ReturnsContentImported(string jsonFile, string expectedMessage)
        {
            // Arrange
            var request  = new Mock <HttpRequest>();
            var response = new DefaultHttpContext().Response;

            response.Body = new MemoryStream();
            var ringCentralRequest = GetEmbeddedTestData($"{GetType().Namespace}.TestData.{jsonFile}");

            using var ms = new MemoryStream();
            using var sw = new StreamWriter(ms);
            sw.Write(ringCentralRequest);
            sw.Flush();
            ms.Position = 0;
            request.Setup(x => x.Body).Returns(ms);
            request.Setup(x => x.Path).Returns(PathString.FromUriComponent("/contentimport"));

            var mockOptions = new RingCentralOptions()
            {
                RingCentralEngageApiAccessToken = PROPERAPIACCESSKEYFORMANUALTESTS,
                RingCentralEngageApiUrl         = PROPERENGAGEURLFORMANUALTEST,
                BotId = "testbot",
                RingCentralEngageBotControlledThreadCategoryId = "botcontrolled"
            };
            var sut            = new RingCentralClientWrapper(OptionsHelper.GetOptionsMonitor(mockOptions), new StaticHandoffRequestRecognizer());
            var mockBotAdapter = new Mock <IBotFrameworkHttpAdapter>().Object;
            var adapter        = new RingCentralAdapter(sut, mockBotAdapter, new StaticHandoffRequestRecognizer());

            // Act
            var(ringCentralWebhook, activity) = await sut.GetActivityFromRingCentralRequestAsync(adapter, mockBotAdapter, request.Object, response);

            // Assert
            Assert.Equal(RingCentralHandledEvent.ContentImported, ringCentralWebhook);
            Assert.Equal(expectedMessage, activity.Text);
            Assert.Equal(StatusCodes.Status200OK, response.StatusCode);
        }
Beispiel #11
0
 public RingCentralController(IConfiguration configuration, RingCentralAdapter adapter, IBot bot)
 {
     _configuration = configuration;
     _bot           = bot;
     _adapter       = adapter;
 }