private static LoginResult GetToken() { const string tokenMethod = "token"; var executingUrlForToken = Helpers.UriHelper.GetMethodPath(AppSettings.AzureAD.LoginUrl, AppSettings.AzureAD.Domain, AppSettings.AzureAD.Protocol, tokenMethod, null, AppSettings.AzureAD.ApiVersion10); JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; var requestTokenHeaders = new ListDictionary { { "ContentLength", "180" }, { "Expect", "100-continue" }, { "Connection", "Keep-Alive" } }; var requestTokenContent = string.Concat( "grant_type=" + AppSettings.AzureAD.GrantType, "&resource=" + AppSettings.AzureAD.BaseUrl, "&client_id=" + AppSettings.AzureAD.ClientId, "&client_secret=" + AppSettings.AzureAD.ClientSecret ); var stringTokenContent = new StringContent(requestTokenContent, Encoding.UTF8, AppSettings.AzureAD.MediaType); // Act var httpPostResult = FetchData.HttpPost(executingUrlForToken, requestTokenHeaders, stringTokenContent).Result; LoginResult deserializedTokenObject = JsonConvert.DeserializeObject <LoginResult>(httpPostResult, jsonSerializerSettings); return(deserializedTokenObject); }
public void Get_applications_should_not_return_null() { //Arrange Uri executingUrl = Helpers.UriHelper.GetMethodPath(AppSettings.NewRelic.BaseUrl, AppSettings.NewRelic.Version, AppSettings.NewRelic.ApplicationPath); ListDictionary requestHeaders = new ListDictionary { { "X-Api-Key", AppSettings.NewRelic.ApiKey } }; //Act string httpGetResult = FetchData.HttpGet(executingUrl, requestHeaders).Result; ApplicationResponse deserializedObject = JsonConvert.DeserializeObject <ApplicationResponse>(httpGetResult); // Assert Assert.IsNotNull(deserializedObject.Applications); }
public void Get_site_by_id_health_status_should_be_gray_when_application_is_down() { var method = "applications"; var expectedValueWhenApplicationHasError = "gray"; //Arrange Uri executingUrl = Helpers.UriHelper.GetMethodPath(AppSettings.NewRelic.BaseUrl, AppSettings.NewRelic.Version, method, AppSettings.NewRelic.DummyApplication); ListDictionary requestHeaders = new ListDictionary { { "X-Api-Key", AppSettings.NewRelic.ApiKey } }; //Act string httpGetResult = FetchData.HttpGet(executingUrl, requestHeaders).Result; ApplicationResponse deserializedObject = JsonConvert.DeserializeObject <ApplicationResponse>(httpGetResult); // Assert Assert.AreEqual(expectedValueWhenApplicationHasError, deserializedObject.Application.HealthStatus); }
public void Get_users_should_not_return_null() { const string userMethod = "users"; // Arrange LoginResult deserializedTokenObject = GetToken(); Uri executingUrl = Helpers.UriHelper.GetMethodPath(AppSettings.AzureAD.BaseUrl, AppSettings.AzureAD.Domain, null, userMethod, null, AppSettings.AzureAD.ApiVersion16); ListDictionary requestHeaders = new ListDictionary { { "Authorization", "Bearer " + deserializedTokenObject.AccessToken }, { "Content-Type", AppSettings.AzureAD.ContentType }, }; // Act string httpGetResult = FetchData.HttpGet(executingUrl, requestHeaders).Result; UserResult deserializedObject = JsonConvert.DeserializeObject <UserResult>(httpGetResult); // Assert Assert.IsNotNull(deserializedObject.Users); }