예제 #1
0
        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));
        }
예제 #2
0
        /// <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");
        }
예제 #3
0
        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);
        }