public async Task TeamsAPI_FetchChannelListTestInvalidHttpCodeWithoutResponseContentAsync()
        {
            Microsoft.Rest.ServiceClientTracing.IsEnabled = true;
            TestDelegatingHandler testHandler = new TestDelegatingHandler((request) =>
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound);
                return(Task.FromResult(response));
            });

            TeamsConnectorClient teamsConnectorClient = new TeamsConnectorClient(
                new Uri("https://smba.trafficmanager.net/amer-client-ss.msg/"),
                new MicrosoftAppCredentials("Test", "Test"),
                testHandler);
            ConversationList conversationListResponse = await teamsConnectorClient.Teams.FetchChannelListAsync("TestTeamId").ConfigureAwait(false);
        }
        public async Task TeamsAPI_FetchChannelListAsyncWithHttpMessagesTestAsync()
        {
            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));
            });

            TeamsConnectorClient teamsConnectorClient = new TeamsConnectorClient(
                new Uri("https://smba.trafficmanager.net/amer-client-ss.msg/"),
                new MicrosoftAppCredentials("Test", "Test"),
                testHandler);

            ConversationList conversationListResponse = (await teamsConnectorClient.Teams.FetchChannelListWithHttpMessagesAsync(
                                                             "TestTeamId",
                                                             new Dictionary <string, List <string> >()
            {
                { "Authorization", new List <string>()
                  {
                      "CustomValue"
                  } }
            }).ConfigureAwait(false)).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);
        }
        public async Task TeamsAPI_FetchTeamDetailsTestInvalidTeamIdAsync()
        {
            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));
            });

            TeamsConnectorClient teamsConnectorClient = new TeamsConnectorClient(
                new Uri("https://smba.trafficmanager.net/amer-client-ss.msg/"),
                new MicrosoftAppCredentials("Test", "Test"),
                testHandler);
            await teamsConnectorClient.Teams.FetchTeamDetailsAsync(null).ConfigureAwait(false);
        }
        /// <summary>
        /// Tests card attachment before and after sending match.
        /// </summary>
        /// <param name="attachment">Attachment to verify.</param>
        /// <returns>Task tracking operation.</returns>
        internal static async Task TestAttachmentAsync(Attachment attachment)
        {
            JsonSerializerSettings serializerSettings = new JsonSerializerSettings();

            serializerSettings.NullValueHandling = NullValueHandling.Ignore;
            Activity activity = JsonConvert.DeserializeObject <Activity>(File.ReadAllText(@"Jsons\SampleSkeletonActivity.json"));

            activity.Attachments = new List <Attachment>()
            {
                attachment
            };

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

                Assert.AreEqual(receivedActivity.Attachments.Count, activity.Attachments.Count);
                Assert.IsTrue(JObject.DeepEquals(
                                  JObject.FromObject(activity.Attachments[0].Content, JsonSerializer.Create(serializerSettings)),
                                  JObject.FromObject(receivedActivity.Attachments[0].Content)));

                ResourceResponse resourceResponse = new ResourceResponse("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"),
                new MicrosoftAppCredentials("Test", "Test"),
                testDelegatingHandler);

            ResourceResponse callResponse = await conClient.Conversations.SendToConversationAsync(activity).ConfigureAwait(false);

            Assert.IsTrue(conClient.Conversations.SendToConversation(activity).Id == "TestId");
        }