public void CancelPassesToConfigurationCallback()
        {
            using (var source = new CancellationTokenSource())
            {
                // the cancellation token here is the one we passed in below
                using (dynamic client = new DynamicRestClient("https://www.googleapis.com/oauth2/v1/userinfo", null,
                    async (request, cancelToken) =>
                    {
                        Assert.AreEqual(source.Token, cancelToken);

                        var oauth = new GoogleOAuth2("email profile");
                        var authToken = await oauth.Authenticate("", cancelToken);
                        request.Headers.Authorization = new AuthenticationHeaderValue("OAuth", authToken);
                    }))
                {
                    // run request on a different thread and do not await thread
                    Task t = client.oauth2.v1.userinfo.get(source.Token);

                    // cancel on unit test thread
                    source.Cancel();

                    try
                    {
                        // this will throw
                        Task.WaitAll(t);
                        Assert.Fail("Task was not cancelled");
                    }
                    catch (AggregateException e)
                    {
                        Assert.IsTrue(e.InnerExceptions.OfType<TaskCanceledException>().Any());
                    }
                }
            }
        }
        private static async Task EnumerateObjects(string project)
        {
            var auth = new GoogleOAuth2("https://www.googleapis.com/auth/devstorage.read_write");
            var token = await auth.Authenticate("");

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = "OAuth",
                AuthToken = token
            };

            dynamic google = new DynamicRestClient("https://www.googleapis.com/", defaults);
            dynamic bucketEndPoint = google.storage.v1.b;
            dynamic buckets = await bucketEndPoint.get(project: project);

            foreach (var bucket in buckets.items)
            {
                Console.WriteLine("bucket {0}: {1}", bucket.id, bucket.name);

                dynamic contents = await bucketEndPoint(bucket.id).o.get();

                foreach (var item in contents.items)
                {
                    Console.WriteLine("\tid: {0}", item.id);
                    Console.WriteLine("\tname: {0}", item.name);
                    Console.WriteLine("\tcontent type: {0}", item.contentType);
                    Console.WriteLine("\t-----");
                }
            }
        }
        //  [Ignore] // - this test requires user interaction
        public async Task GetCalendarList()
        {
            var auth = new GoogleOAuth2("email profile https://www.googleapis.com/auth/calendar");
            _token = await auth.Authenticate(_token);
            Assert.IsNotNull(_token, "auth failed");

            using (var client = new HttpClient(MockInitialization.Handler, false))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com/calendar/v3/");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", _token);

                using (dynamic proxy = new DynamicRestClient(client))
                {
                    var list = await proxy.users.me.calendarList.get();

                    Assert.IsNotNull(list);
                    Assert.AreEqual("calendar#calendarList", list.kind);
                }
            }
        }
        //  [Ignore] // - this test requires user interaction
        public async Task GetUserProfile()
        {
            var auth = new GoogleOAuth2("email profile");
            _token = await auth.Authenticate(_token);
            Assert.IsNotNull(_token, "auth failed");

            using (var client = new HttpClient(MockInitialization.Handler, false))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", _token);

                using (dynamic proxy = new DynamicRestClient(client))
                {
                    var profile = await proxy.oauth2.v1.userinfo.get();

                    Assert.IsNotNull(profile);
                    Assert.AreEqual("Kackman", profile.family_name);
                }
            }
        }
        // [Ignore] // - this test requires user interaction
        public async Task CreateCalendar()
        {
            var auth = new GoogleOAuth2("email profile https://www.googleapis.com/auth/calendar");
            _token = await auth.Authenticate(_token);
            Assert.IsNotNull(_token, "auth failed");

            using (var client = new HttpClient(MockInitialization.Handler, false))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com/calendar/v3/");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", _token);

                using (dynamic proxy = new DynamicRestClient(client))
                {
                    dynamic calendar = new ExpandoObject();
                    calendar.summary = "unit_testing";

                    var list = await proxy.calendars.post(calendar);

                    Assert.IsNotNull(list);
                    Assert.AreEqual("unit_testing", list.summary);
                }
            }
        }
        //  [Ignore] // - this test requires user interaction
        public async Task DeleteCalendar()
        {
            var auth = new GoogleOAuth2("email profile https://www.googleapis.com/auth/calendar");
            _token = await auth.Authenticate(_token);
            Assert.IsNotNull(_token, "auth failed");

            using (var client = new HttpClient(MockInitialization.Handler, false))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com/calendar/v3/");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", _token);

                using (dynamic proxy = new DynamicRestClient(client))
                {
                    var list = await proxy.users.me.calendarList.get();
                    Assert.IsNotNull(list);

                    string id = ((IEnumerable<dynamic>)(list.items)).Where(cal => cal.summary == "unit_testing").Select(cal => cal.id).FirstOrDefault();
                    Assert.IsFalse(string.IsNullOrEmpty(id), "calendar does not exist so we can't delete it");

                    var result = await proxy.calendars(id).delete();
                    Assert.IsNull(result);

                    //var list2 = await proxy.users.me.calendarList.get();
                    //Assert.IsNotNull(list2);
                    //var id2 = ((IEnumerable<dynamic>)(list2.items)).Where(cal => cal.summary == "unit_testing").Select(cal => (string)cal.id).FirstOrDefault();

                    //Assert.IsTrue(string.IsNullOrEmpty(id2), "calendar seems to have not been deleted");
                }
            }
        }
        //  [Ignore] // - this test requires user interaction
        public async Task UpdateCalendar()
        {
            var auth = new GoogleOAuth2("email profile https://www.googleapis.com/auth/calendar");
            _token = await auth.Authenticate(_token);
            Assert.IsNotNull(_token, "auth failed");

            using (var client = new HttpClient(MockInitialization.Handler, false))
            {
                client.BaseAddress = new Uri("https://www.googleapis.com/calendar/v3/");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", _token);

                using (dynamic proxy = new DynamicRestClient(client))
                {
                    var list = await proxy.users.me.calendarList.get();
                    Assert.IsNotNull(list);

                    string id = ((IEnumerable<dynamic>)(list.items)).Where(cal => cal.summary == "unit_testing").Select(cal => cal.id).FirstOrDefault();
                    Assert.IsFalse(string.IsNullOrEmpty(id));

                    var guid = Guid.NewGuid().ToString();
                    dynamic calendar = new ExpandoObject();
                    calendar.summary = "unit_testing";
                    calendar.description = guid;

                    var result = await proxy.calendars(id).put(calendar);
                    Assert.IsNotNull(result);

                    list = await proxy.users.me.calendarList.get();
                    Assert.IsNotNull(list);
                    string description = ((IEnumerable<dynamic>)(list.items)).Where(cal => cal.summary == "unit_testing").Select(cal => cal.description).FirstOrDefault();

                    Assert.AreEqual(guid, description);
                }
            }
        }