示例#1
0
        public void GetUserApiCall_ResultNotNull()
        {
            //Given
            var appConfig = new ConfigurationBuilder()
                            .AddUserSecrets <GraphManagerTests>()
                            .Build();

            AuthProvider.Initialize(appConfig);
            AuthProvider.Instance.Scopes = new[] { Permissions.User.Read };
            var url     = $"{Urls.BaseUrl}me/";
            var request = new HttpRequestMessage(HttpMethod.Get, url);

            AuthProvider.Instance.AuthenticateRequestAsync(request).Wait();
            //When
            TimeSpan            timeout = TimeSpan.FromSeconds(5);
            HttpResponseMessage response;

            using (var client = new HttpClient()) {
                client.Timeout = timeout;
                response       = client.SendAsync(request).Result;
            }
            var responseBody = response.Content.ReadAsStringAsync().Result;

            Console.WriteLine(responseBody);
            var jObject = JObject.Parse(responseBody);
            var jString = jObject.ToString();

            Console.WriteLine(jString);
            var user = JsonConvert.DeserializeObject <User>(responseBody);

            //Then
            Assert.NotNull(responseBody);
        }
 public AuthProviderTests()
 {
     appConfig = new ConfigurationBuilder()
                 .AddUserSecrets <GraphManagerTests>()
                 .Build();
     AuthProvider.Initialize(appConfig);
     authProvider = AuthProvider.Instance;
 }