public async Task RetryHelpers_DefaultRetryHelper()
        {
            DateTime dateTime = DateTime.MinValue;
            int      count    = 0;
            TestDelegatingHandler testDelegatingHandler = new TestDelegatingHandler((request) =>
            {
                if (count < 3)
                {
                    dateTime = DateTime.Now;
                    count++;
                    var response     = new HttpResponseMessage((HttpStatusCode)429);
                    response.Content = new StringContent(JsonConvert.SerializeObject(new ResourceResponse("ID")));
                    return(Task.FromResult(response));
                }
                else
                {
                    if (!(DateTime.Now - dateTime > TimeSpan.FromSeconds(2) && (DateTime.Now - dateTime < TimeSpan.FromSeconds(20))))
                    {
                        Assert.Fail("Invalid backoff time detected for default retry strategy" + (DateTime.Now - dateTime));
                    }

                    var response     = new HttpResponseMessage((HttpStatusCode)200);
                    response.Content = new StringContent(JsonConvert.SerializeObject(new ResourceResponse("ID")));
                    return(Task.FromResult(response));
                }
            });

            Activity        sampleActivity = JsonConvert.DeserializeObject <Activity>(File.ReadAllText(@"Jsons\SampleActivityNoMentions.json"));
            ConnectorClient conClient      = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);
            await conClient.Conversations.SendToConversationWithRetriesAsync(sampleActivity);
        }
        public async Task RetryHelpers_SendActivityWithRetries()
        {
            int count = 0;
            TestDelegatingHandler testDelegatingHandler = new TestDelegatingHandler((request) =>
            {
                if (count < 3)
                {
                    count++;
                    var response     = new HttpResponseMessage((HttpStatusCode)429);
                    response.Content = new StringContent(JsonConvert.SerializeObject(new ResourceResponse("ID")));
                    return(Task.FromResult(response));
                }
                else
                {
                    var response     = new HttpResponseMessage((HttpStatusCode)200);
                    response.Content = new StringContent(JsonConvert.SerializeObject(new ResourceResponse("ID")));
                    return(Task.FromResult(response));
                }
            });

            Activity        sampleActivity = JsonConvert.DeserializeObject <Activity>(File.ReadAllText(@"Jsons\SampleActivityNoMentions.json"));
            ConnectorClient conClient      = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);

            sampleActivity.ReplyToId = "RandomId";
            await conClient.Conversations.ReplyToActivityWithRetriesAsync(sampleActivity);
        }
        public async Task TeamsAPI_FetchTeamDetailsAsyncTest()
        {
            Microsoft.Rest.ServiceClientTracing.IsEnabled = true;
            TeamDetails teamDetails = new TeamDetails("TeamId", "TeamName", "GroupId");

            TestDelegatingHandler testHandler = new TestDelegatingHandler((request) =>
            {
                StringContent stringContent = new StringContent(JsonConvert.SerializeObject(teamDetails));
                var response     = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = stringContent;
                return(Task.FromResult(response));
            });

            ConnectorClient connectorClient = new ConnectorClient(
                new Uri("https://smba.trafficmanager.net/amer-client-ss.msg/"),
                ConfigurationManager.AppSettings["MicrosoftAppId"],
                ConfigurationManager.AppSettings["MicrosoftAppPassword"],
                testHandler);

            TeamsConnectorClient teamsConnectorClient = connectorClient.GetTeamsConnectorClient();

            TeamDetails teamDetailsResult = await teamsConnectorClient.Teams.FetchTeamDetailsAsync("TestTeamId");

            Assert.IsNotNull(teamDetailsResult);
            Assert.IsNotNull(teamDetailsResult.Id);
            Assert.IsNotNull(teamDetailsResult.Name);
            Assert.IsNotNull(teamDetailsResult.AadGroupId);
            Assert.AreEqual(teamDetailsResult.Id, teamDetails.Id);
            Assert.AreEqual(teamDetailsResult.Name, teamDetails.Name);
            Assert.AreEqual(teamDetailsResult.AadGroupId, teamDetails.AadGroupId);
        }
        public async Task ConnectorExtensions_GetTeamsConversationMembersAsync()
        {
            TestDelegatingHandler testDelegatingHandler = new TestDelegatingHandler((request) =>
            {
                Assert.IsFalse(request.Headers.Contains("X-MsTeamsTenantId"));

                StringContent stringContent = new StringContent(File.ReadAllText(@"Jsons\SampleResponseGetTeamsConversationMembers.json"));
                var response     = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = stringContent;
                return(Task.FromResult(response));
            });

            ConnectorClient conClient = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);

#pragma warning disable CS0618 // Type or member is obsolete
            var memberList = await conClient.Conversations.GetTeamsConversationMembersAsync("TestConversationId", Guid.Empty.ToString());

#pragma warning restore CS0618 // Type or member is obsolete

            Assert.IsTrue(memberList.Count() == 2);
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.ObjectId)));
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.UserPrincipalName)));
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.Id)));
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.Email)));
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.Name)));
        }
Exemple #5
0
        public async Task RetryHelpers_UpdateActivityWithCustomConvIdWithRetries()
        {
            int count = 0;
            TestDelegatingHandler testDelegatingHandler = GenerateTestHandler(count);

            Activity        sampleActivity = JsonConvert.DeserializeObject <Activity>(File.ReadAllText(@"Jsons\SampleActivityNoMentions.json"));
            ConnectorClient conClient      = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);
            await conClient.Conversations.UpdateActivityWithRetriesAsync(sampleActivity.Conversation.Id, sampleActivity.Id, sampleActivity);
        }
Exemple #6
0
        public async Task RetryHelpers_DefaultRetryHelper()
        {
            DateTime dateTime = DateTime.MinValue;
            int      count    = 0;
            TestDelegatingHandler testDelegatingHandler = GenerateTestHandler(count);

            Activity        sampleActivity = JsonConvert.DeserializeObject <Activity>(File.ReadAllText(@"Jsons\SampleActivityNoMentions.json"));
            ConnectorClient conClient      = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);
            await conClient.Conversations.SendToConversationWithRetriesAsync(sampleActivity);
        }
Exemple #7
0
        public async Task TeamsAPI_FetchChannelListAsyncWithHttpMessagesTest()
        {
            Microsoft.Rest.ServiceClientTracing.IsEnabled = true;
            ConversationList conversationList = new ConversationList
            {
                Conversations = new List <ChannelInfo>
                {
                    new ChannelInfo
                    {
                        Id   = "ChannelId",
                        Name = "ChannelName"
                    }
                }
            };

            TestDelegatingHandler testHandler = new TestDelegatingHandler((request) =>
            {
                StringContent stringContent = new StringContent(JsonConvert.SerializeObject(conversationList));
                var response     = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = stringContent;
                Assert.IsNotNull(request.Headers.GetValues("Authorization"));
                Assert.AreEqual(request.Headers.GetValues("Authorization").Count(), 1);
                Assert.AreEqual(request.Headers.GetValues("Authorization").ToList()[0], "CustomValue");
                return(Task.FromResult(response));
            });

            ConnectorClient connectorClient = new ConnectorClient(
                new Uri("https://smba.trafficmanager.net/amer-client-ss.msg/"),
                ConfigurationManager.AppSettings["MicrosoftAppId"],
                ConfigurationManager.AppSettings["MicrosoftAppPassword"],
                testHandler);

            TeamsConnectorClient teamsConnectorClient = connectorClient.GetTeamsConnectorClient();

            ConversationList conversationListResponse = (await teamsConnectorClient.Teams.FetchChannelListWithHttpMessagesAsync(
                                                             "TestTeamId",
                                                             new Dictionary <string, List <string> >()
            {
                { "Authorization", new List <string>()
                  {
                      "CustomValue"
                  } }
            })).Body;

            Assert.IsNotNull(conversationListResponse);
            Assert.IsNotNull(conversationListResponse.Conversations);
            Assert.AreEqual(conversationListResponse.Conversations.Count, 1);
            Assert.AreEqual(conversationListResponse.Conversations[0].Id, conversationList.Conversations[0].Id);
            Assert.AreEqual(conversationListResponse.Conversations[0].Name, conversationList.Conversations[0].Name);
        }
Exemple #8
0
        public void ConnectorExtensions_Create1on1()
        {
            JsonSerializerSettings serializerSettings = new JsonSerializerSettings();

            serializerSettings.NullValueHandling = NullValueHandling.Ignore;

            var botAccount = new ChannelAccount
            {
                Id   = "BotId",
                Name = "BotName"
            };

            var userAccount = new ChannelAccount
            {
                Id   = "UserId",
                Name = "UserName"
            };

            TestDelegatingHandler testDelegatingHandler = new TestDelegatingHandler((request) =>
            {
                string data = (request.Content as StringContent).ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
                ConversationParameters receivedRequest = JsonConvert.DeserializeObject <ConversationParameters>(data, serializerSettings);

                Assert.AreEqual(receivedRequest.Bot.Id, botAccount.Id);
                Assert.IsNotNull(receivedRequest.Members);
                Assert.IsTrue(receivedRequest.Members.Count == 1);
                Assert.AreEqual(receivedRequest.Members[0].Id, userAccount.Id);

                TeamsChannelData channelData = JsonConvert.DeserializeObject <TeamsChannelData>(receivedRequest.ChannelData.ToString());

                Assert.IsNotNull(channelData);
                Assert.IsNotNull(channelData.Tenant);
                Assert.IsNotNull(channelData.Tenant.Id);
                Assert.AreEqual(channelData.Tenant.Id, "TestTenantId");

                ConversationResourceResponse resourceResponse = new ConversationResourceResponse()
                {
                    Id = "TestId"
                };
                StringContent responseContent = new StringContent(JsonConvert.SerializeObject(resourceResponse));
                var response     = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = responseContent;
                return(Task.FromResult(response));
            });

            ConnectorClient conClient = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);

            Assert.IsTrue(conClient.Conversations.CreateOrGetDirectConversation(botAccount, userAccount, "TestTenantId").Id == "TestId");
        }
Exemple #9
0
        public void TeamsAPI_FetchChannelListTestInvalidHttpCodeWithoutResponseContent()
        {
            Microsoft.Rest.ServiceClientTracing.IsEnabled = true;
            TestDelegatingHandler testHandler = new TestDelegatingHandler((request) =>
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound);
                return(Task.FromResult(response));
            });

            ConnectorClient connectorClient = new ConnectorClient(
                new Uri("https://smba.trafficmanager.net/amer-client-ss.msg/"),
                ConfigurationManager.AppSettings["MicrosoftAppId"],
                ConfigurationManager.AppSettings["MicrosoftAppPassword"],
                testHandler);

            TeamsConnectorClient teamsConnectorClient     = connectorClient.GetTeamsConnectorClient();
            ConversationList     conversationListResponse = teamsConnectorClient.Teams.FetchChannelList("TestTeamId");
        }
Exemple #10
0
        public async Task RetryHelpers_CustomRetryHelper()
        {
            DateTime dateTime = DateTime.MinValue;
            int      count    = 0;
            TestDelegatingHandler testDelegatingHandler = GenerateTestHandler(count);

            Activity        sampleActivity = JsonConvert.DeserializeObject <Activity>(File.ReadAllText(@"Jsons\SampleActivityNoMentions.json"));
            ConnectorClient conClient      = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);

            conClient.SetRetryPolicy(RetryHelpers.DefaultPolicyBuilder.WaitAndRetryAsync(new[]
            {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(6),
                TimeSpan.FromSeconds(10),
                TimeSpan.FromSeconds(20)
            }));
            await conClient.Conversations.SendToConversationWithRetriesAsync(sampleActivity);
        }
        public void TeamsAPI_FetchTeamDetailsTestInvalidTeamId()
        {
            Microsoft.Rest.ServiceClientTracing.IsEnabled = true;
            TestDelegatingHandler testHandler = new TestDelegatingHandler((request) =>
            {
                StringContent stringContent = new StringContent("RandomRandomRandom");
                var response     = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = stringContent;
                return(Task.FromResult(response));
            });

            ConnectorClient connectorClient = new ConnectorClient(
                new Uri("https://smba.trafficmanager.net/amer-client-ss.msg/"),
                ConfigurationManager.AppSettings["MicrosoftAppId"],
                ConfigurationManager.AppSettings["MicrosoftAppPassword"],
                testHandler);

            TeamsConnectorClient teamsConnectorClient = connectorClient.GetTeamsConnectorClient();

            teamsConnectorClient.Teams.FetchTeamDetails(null);
        }
Exemple #12
0
        public void TeamsAPI_FetchChannelListTest()
        {
            Microsoft.Rest.ServiceClientTracing.IsEnabled = true;
            ConversationList conversationList = new ConversationList
            {
                Conversations = new List <ChannelInfo>
                {
                    new ChannelInfo
                    {
                        Id   = "ChannelId",
                        Name = "ChannelName"
                    }
                }
            };

            TestDelegatingHandler testHandler = new TestDelegatingHandler((request) =>
            {
                StringContent stringContent = new StringContent(JsonConvert.SerializeObject(conversationList));
                var response     = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = stringContent;
                return(Task.FromResult(response));
            });

            ConnectorClient connectorClient = new ConnectorClient(
                new Uri("https://smba.trafficmanager.net/amer-client-ss.msg/"),
                ConfigurationManager.AppSettings["MicrosoftAppId"],
                ConfigurationManager.AppSettings["MicrosoftAppPassword"],
                testHandler);

            TeamsConnectorClient teamsConnectorClient = connectorClient.GetTeamsConnectorClient();

            ConversationList conversationListResponse = teamsConnectorClient.Teams.FetchChannelList("TestTeamId");

            Assert.IsNotNull(conversationListResponse);
            Assert.IsNotNull(conversationListResponse.Conversations);
            Assert.AreEqual(conversationListResponse.Conversations.Count, 1);
            Assert.AreEqual(conversationListResponse.Conversations[0].Id, conversationList.Conversations[0].Id);
            Assert.AreEqual(conversationListResponse.Conversations[0].Name, conversationList.Conversations[0].Name);
        }
Exemple #13
0
        public void ConnectorExtensions_ResolveAsTeamsChannelAccount()
        {
            TestDelegatingHandler testDelegatingHandler = new TestDelegatingHandler((request) =>
            {
                Assert.IsFalse(request.Headers.Contains("X-MsTeamsTenantId"));

                StringContent stringContent = new StringContent(File.ReadAllText(@"Jsons\SampleResponseGetTeamsConversationMembers.json"));
                var response     = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = stringContent;
                return(Task.FromResult(response));
            });

            ConnectorClient conClient = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);

            var memberList = conClient.Conversations.GetConversationMembers("TestConversationId").AsTeamsChannelAccounts();

            Assert.IsTrue(memberList.Count() == 2);
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.ObjectId)));
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.Name)));
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.UserPrincipalName)));
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.Id)));
            Assert.IsFalse(memberList.Any(member => string.IsNullOrEmpty(member.Email)));
        }
Exemple #14
0
        public async Task ConnectorExtensions_GetTeamsSingleConversationMemberTest()
        {
            TestDelegatingHandler testDelegatingHandler = new TestDelegatingHandler((request) =>
            {
                Assert.IsFalse(request.Headers.Contains("X-MsTeamsTenantId"));

                StringContent stringContent = new StringContent(File.ReadAllText(@"Jsons\SampleResponseTeamsGetConversationMember.json"));
                var response = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = stringContent
                };
                return(Task.FromResult(response));
            });

            ConnectorClient conClient = new ConnectorClient(new Uri("https://testservice.com"), "Test", "Test", testDelegatingHandler);

            var member = await conClient.Conversations.GetTeamsConversationMemberAsync(conClient, userId : "test2", conversationId : "TestConversationId");


            Assert.IsFalse(string.IsNullOrEmpty(member.ObjectId));
            Assert.IsFalse(string.IsNullOrEmpty(member.Id));
            Assert.IsFalse(string.IsNullOrEmpty(member.Name));
        }