public void TestPostUserApi() { const string API_URL = "/v1/user"; Dictionary <string, object> parameters = new Dictionary <string, object>() { { Partition, AuthenticationInfoProvider.Current.DefaultPartition }, { RequestType, 1 }, { Count, 10 }, }; var connection = new PublicAPIConnection(); connection.Authentication.Authenticate(); connection.URLParameters = parameters; connection.ServerURL = PublicAPIConfig.ServerURL; connection.RequestType = TestLibrary.Enums.SupportedHttpMethod.Post; connection.RelativeURL = API_URL; XmlHandler handler = connection.SendRequest() as XmlHandler; Assert.NotNull(handler); Assert.That(HttpStatusCode.OK, Is.EqualTo(handler.HttpCode)); Assert.NotNull(handler.XML); XElement xmlCode = handler.XML.Descendants("Code").First(); Assert.NotNull(xmlCode); connection.Authentication.RemoveAuthentication(); Assert.That(Enums.PublicAPIResultCode.ResourceNotExist.ToString(), Is.EqualTo(xmlCode.Value)); }
private void InitNoScopeAdapters() { var secondPartyAppInfo = GetDefaultApplication(ApplicationType.SecondParty); var secondPartyConnection = new PublicAPIConnection(secondPartyAppInfo.Key, secondPartyAppInfo.Secret); Dictionary <string, string> oauthParams = new Dictionary <string, string>(); oauthParams.Add("scope", string.Empty); oauthParams.Add("app_id", secondPartyAppInfo.Key); oauthParams.Add("response_type", "code_direct"); secondPartyConnection.Authentication.Authenticate(oauthParams); _secondPartyApplicationAdapter = PublicApiAdapter.CreateAdapter(secondPartyConnection, secondPartyAppInfo.Company.Partition); var thirdPartyAppInfo = GetDefaultApplication(ApplicationType.ThirdParty); var thirdPartyConnection = new PublicAPIConnection(thirdPartyAppInfo.Key, thirdPartyAppInfo.Secret); var subscriber = new ApplicationSubscriber(); Assume.That(subscriber.Subscribe(thirdPartyAppInfo.Key, thirdPartyAppInfo.Metadata["redirectUrl"].ToString(), "client_d", AuthenticationInfoProvider.Current.DefaultCompanyName, // client_d does not affect read/write operations. We use it as a workaround for empty scope AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword), Is.EqualTo(AuthResponseCode.Success), "Couldn't get oauth code for 3rd party application"); var tokenApi = new TokenAPI { AccessHelper = new PublicAPIConnection(thirdPartyAppInfo.Key, thirdPartyAppInfo.Secret) }; var tokenResponse = tokenApi.AccessTokenSuccess(thirdPartyAppInfo.Key, "oauth_code", thirdPartyAppInfo.Secret, subscriber.ResultOauthCode); Assume.That(tokenResponse.AccessToken, Is.Not.Null, "get token request for 3rd party application was not successful"); thirdPartyConnection.Authentication.Token = tokenResponse.AccessToken; _thirdPartyApplicationAdapter = PublicApiAdapter.CreateAdapter(thirdPartyConnection, thirdPartyAppInfo.Company.Partition); }
private void InitScopeAdapter(string scope, ApplicationType appType) { appInfo = GetDefaultApplication(appType); var connection = new PublicAPIConnection(appInfo.Key, appInfo.Secret); var subscriber = new ApplicationSubscriber(); Assume.That(subscriber.Subscribe(appInfo.Key, appInfo.Metadata["redirectUrl"].ToString(), scope, AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword), Is.EqualTo(AuthResponseCode.Success)); _testCleanupActions.Add(() => subscriber.Unsubscribe(appInfo.Key, appInfo.Metadata["redirectUrl"].ToString(), scope, AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword)); var tokenApi = new TokenAPI { AccessHelper = new PublicAPIConnection(appInfo.Key, appInfo.Secret) }; var tokenResponse = tokenApi.AccessTokenSuccess(appInfo.Key, "oauth_code", appInfo.Secret, subscriber.ResultOauthCode); Assume.That(tokenResponse.AccessToken, Is.Not.Null); connection.Authentication.Token = tokenResponse.AccessToken; adapter = PublicApiAdapter.CreateAdapter(connection, appInfo.Company.Partition); }
private PublicAPIConnection PreparePublicApiConnection(string contentTypeHeaderValue) { var connection = new PublicAPIConnection(); var code = new OAuthAPI().GetCodeSuccess(AuthenticationInfoProvider.Current.DefaultAppKey, "code_direct").Code; var token = new TokenAPI().AccessTokenSuccess(AuthenticationInfoProvider.Current.DefaultAppKey, "oauth_code", AuthenticationInfoProvider.Current.DefaultAppSecret, code).AccessToken; connection.Authentication.Token = token; connection.Headers["Content-Type"] = contentTypeHeaderValue; return(connection); }
public PublicApiAdapter(PublicAPIConnection connection, string partition) { _connection = connection; _partition = partition; if (string.IsNullOrEmpty(_connection.Authentication.Token)) { _connection.Authentication.Authenticate(); } }
private PublicApiAdapter CreateSecondPartyAppAdapter(bool isReadApp) { var secondPartyAppInfo = GetDefaultApplication(ApplicationType.SecondParty, isReadApp); var secondPartyConnection = new PublicAPIConnection(secondPartyAppInfo.Key, secondPartyAppInfo.Secret); Dictionary <string, string> oauthParams = new Dictionary <string, string>(); oauthParams.Add("scope", isReadApp ? ReadOnlyScope : WriteOnlyScope); oauthParams.Add("app_id", secondPartyAppInfo.Key); oauthParams.Add("response_type", "code_direct"); secondPartyConnection.Authentication.Authenticate(oauthParams); return(PublicApiAdapter.CreateAdapter(secondPartyConnection, secondPartyAppInfo.Company.Partition)); }
public void TestSearchCondition(string requestType) { Dictionary <string, object> urlParameters = new Dictionary <string, object>(); if (requestType != null) { urlParameters[PartitionApiFields.RequestType] = requestType; } PublicAPIConnection connection = new PublicAPIConnection(singleCompanyAppInfo.Key, singleCompanyAppInfo.Secret); ReadResponseData <Partition> result = PublicApiAdapter.CreateAdapter(connection, singleCompanyAppInfo.Company.Partition).ReadSuccess <Partition>(urlParameters); Assert.That(result, MustBe.ReadSuccess(1), string.Format(Enums.Message.READ_RESOURCE_FAILED, "Partition")); }
private PublicApiAdapter CreateThirdPartyAppAdapter(bool isReadApp) { var thirdPartyAppInfo = GetDefaultApplication(ApplicationType.ThirdParty, isReadApp); var thirdPartyConnection = new PublicAPIConnection(thirdPartyAppInfo.Key, thirdPartyAppInfo.Secret); var subscriber = new ApplicationSubscriber(); Assume.That(subscriber.Subscribe(thirdPartyAppInfo.Key, thirdPartyAppInfo.Metadata["redirectUrl"].ToString(), isReadApp ? ReadOnlyScope : WriteOnlyScope, AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword), Is.EqualTo(AuthResponseCode.Success), "Couldn't get oauth code for 3rd party application"); var tokenApi = new TokenAPI { AccessHelper = new PublicAPIConnection(thirdPartyAppInfo.Key, thirdPartyAppInfo.Secret) }; var tokenResponse = tokenApi.AccessTokenSuccess(thirdPartyAppInfo.Key, "oauth_code", thirdPartyAppInfo.Secret, subscriber.ResultOauthCode); Assume.That(tokenResponse.AccessToken, Is.Not.Null, "get token request for 3rd party application was not successful"); thirdPartyConnection.Authentication.Token = tokenResponse.AccessToken; return(PublicApiAdapter.CreateAdapter(thirdPartyConnection, thirdPartyAppInfo.Company.Partition)); }
/// <summary> /// This is used as Thread method /// </summary> /// <param name="connection"></param> public static void Connect(object connection) { Log.Info("Thread Start: " + Thread.CurrentThread.Name); PublicAPIConnection conn = connection as PublicAPIConnection; conn.ServerURL = PublicAPIConfig.ServerURL; conn.RequestType = TestLibrary.Enums.SupportedHttpMethod.Get; conn.RelativeURL = API_URL; // Authenticate using Connection conn.Authentication.Authenticate(); Handler handler = conn.SendRequest(); if (null == handler) { Log.Info("Unable to connect to the server"); //Thread.CurrentThread.Abort(); Thread.Sleep(50); } Log.Info("Connection Success"); Log.Info("Thread End"); }
public static PublicApiAdapter CreateAdapter(PublicAPIConnection connection, string partition) { return(new PublicApiAdapter(connection, partition)); }
private PublicApiAdapter() { _connection = PublicAPIConnection.Instance; _partition = AuthenticationInfoProvider.Current.DefaultPartition; }
public void TestMultipleConnections_Success() { // TestBase Connection PublicConnection.Authentication.Authenticate(); PublicConnection.URLParameters = new Dictionary <string, object>() { { "partition", AuthenticationInfoProvider.Current.DefaultPartition } }; PublicConnection.ServerURL = PublicAPIConfig.ServerURL; PublicConnection.RequestType = TestLibrary.Enums.SupportedHttpMethod.Get; PublicConnection.RelativeURL = API_URL; XmlHandler handler = PublicConnection.SendRequest() as XmlHandler; Assert.NotNull(handler); Assert.AreEqual(HttpStatusCode.OK, handler.HttpCode); Assert.NotNull(handler.XML); XElement xmlCode = handler.XML.Descendants("Code").First(); Assert.NotNull(xmlCode); Assert.AreEqual("0", xmlCode.Value); // Connection #1 : PublicAPIConnection Class PublicAPIConnection conn1 = new PublicAPIConnection(TestConfig.GetValueFromConfig("AppID1"), TestConfig.GetValueFromConfig("AppSecret1")); conn1.URLParameters = new Dictionary <string, object>() { { "partition", TestConfig.GetValueFromConfig("Partition1") } }; conn1.ServerURL = PublicAPIConfig.ServerURL; conn1.RequestType = TestLibrary.Enums.SupportedHttpMethod.Get; conn1.RelativeURL = API_URL; // Authenticate using Connection #1 conn1.Authentication.Authenticate(); handler = conn1.SendRequest() as XmlHandler; Assert.NotNull(handler); Assert.AreEqual(HttpStatusCode.OK, handler.HttpCode); Assert.NotNull(handler.XML); xmlCode = handler.XML.Descendants("Code").First(); Assert.NotNull(xmlCode); Assert.AreEqual("0", xmlCode.Value); // Connection #2 : PublicAPIConnection Class PublicAPIConnection conn2 = new PublicAPIConnection(); conn2.URLParameters = new Dictionary <string, object>() { { "partition", TestConfig.GetValueFromConfig("Partition2") } }; conn2.ServerURL = PublicAPIConfig.ServerURL; conn2.RequestType = TestLibrary.Enums.SupportedHttpMethod.Get; conn2.RelativeURL = API_URL; // Authenticate using Connection #2 conn2.Authentication.Authenticate(TestConfig.GetValueFromConfig("AppID2"), TestConfig.GetValueFromConfig("AppSecret2")); handler = conn2.SendRequest() as XmlHandler; Assert.NotNull(handler); Assert.AreEqual(HttpStatusCode.OK, handler.HttpCode); Assert.NotNull(handler.XML); xmlCode = handler.XML.Descendants("Code").First(); Assert.NotNull(xmlCode); Assert.AreEqual("0", xmlCode.Value); }
public void TestMultipleConnectionsMultipleThreads_Success() { PublicAPIConnection conn = new PublicAPIConnection(); conn.Authentication.Authenticate(TestConfig.GetValueFromConfig("AppID"), TestConfig.GetValueFromConfig("AppSecret")); conn.URLParameters = new Dictionary <string, object>() { { "partition", TestConfig.GetValueFromConfig("Partition") } }; PublicAPIConnection conn1 = new PublicAPIConnection(); conn1.Authentication.Authenticate(TestConfig.GetValueFromConfig("AppID1"), TestConfig.GetValueFromConfig("AppSecret1")); conn1.URLParameters = new Dictionary <string, object>() { { "partition", TestConfig.GetValueFromConfig("Partition1") } }; PublicAPIConnection conn2 = new PublicAPIConnection(); conn2.Authentication.Authenticate(TestConfig.GetValueFromConfig("AppID2"), TestConfig.GetValueFromConfig("AppSecret2")); conn2.URLParameters = new Dictionary <string, object>() { { "partition", TestConfig.GetValueFromConfig("Partition2") } }; ParameterizedThreadStart threadStart = new ParameterizedThreadStart(TestPublicAPIConnection.Connect); Log.Info("Starting Thread #1"); Thread thread1 = new Thread(threadStart); thread1.Name = "Thread1"; Log.Info("Starting Thread #2"); Thread thread2 = new Thread(threadStart); thread2.Name = "Thread2"; Log.Info("Starting Thread #3"); Thread thread3 = new Thread(threadStart); thread3.Name = "Thread3"; thread1.Start(conn); thread2.Start(conn1); thread3.Start(conn2); thread1.Join(); thread2.Join(); thread3.Join(); Assert.AreNotEqual(ThreadState.Aborted, thread1.ThreadState, "Error trying to establish connection to Private API using: " + thread1.Name); Assert.AreNotEqual(ThreadState.Aborted, thread2.ThreadState, "Error trying to establish connection to Private API using: " + thread2.Name); Assert.AreNotEqual(ThreadState.Aborted, thread3.ThreadState, "Error trying to establish connection to Private API using: " + thread3.Name); }