Exemplo n.º 1
0
        public void TestExample3()
        {
            var myObject = new MyObject {
                Id = 1, Name = "Example"
            };

            IObjectToQueryConverter objectToQueryConverter = new ObjectToQueryConverter();
            string queryString = objectToQueryConverter.ToQuery(myObject);

            //Result: Id=1&Name=Example&Tags=a&Tags=b&NestedObject.Id=2
            string expectedQuery = "Id=1&Name=Example&Tags=a&Tags=b&NestedObject.Id=2";

            Assert.Equal(expectedQuery, queryString);
        }
Exemplo n.º 2
0
        public void TestDynamic()
        {
            IObjectToQueryConverter objectToQueryConverter = new ObjectToQueryConverter();

            string queryString   = objectToQueryConverter.ToQuery(new { Id = 1, Name = "Example" });
            string expectedQuery = "Id=1&Name=Example";

            Assert.Equal(expectedQuery, queryString);

            queryString = objectToQueryConverter.ToQuery(new { Id = 1, Name = "Example" });
            Assert.Equal(expectedQuery, queryString);

            string queryString2   = objectToQueryConverter.ToQuery(new { Id2 = 1, Name2 = "Example" });
            string expectedQuery2 = "Id2=1&Name2=Example";

            Assert.Equal(expectedQuery2, queryString2);

            string queryString3   = objectToQueryConverter.ToQuery(new { Id = 3, Name = "Example3" });
            string expectedQuery3 = "Id=3&Name=Example3";

            Assert.Equal(expectedQuery3, queryString3);
        }
Exemplo n.º 3
0
        public void TestConverter()
        {
            var testData = TestDataFactory.CreateTestObject();
            IObjectToQueryConverter converter = new ObjectToQueryConverter();
            var query = converter.ToQuery(testData);

            string expectedQuery =
                "Id=2" +
                //"&UserAge=" +
                "&UserHeight=80%2C5" +
                "&ShoeSize=10%2C4" +
                "&FirstName=Luigi" +
                "&LastName=" +
                //"&LuckyNumber=" +
                "&Tags=C&Tags=d" +
                "&Birth=2018-01-01T00%3A00%3A00.0000000%2B00%3A00" +
                "&Died=2030-01-01T00%3A00%3A00.0000000%2B00%3A00" +
                //"&Rebirth=" +
                "&DefaultInt=0" +
                "&LastAnniversary=2018-01-01T00%3A00%3A00.0000000Z" +
                "&NextAnniversary=2018-01-01T00%3A00%3A00.0000000Z" +
                "&Categories=a" +
                "&Categories=B" +
                "&Profile.Email=firstname.lastname%40company.com" +
                "&Profile.Alias=super%20man" +
                "&Profile.FavoritePage=https%3A%2F%2Fgithub.com%2F%3FTest%3D2" +
                "&Profile.Subs.Id=4" +
                "&Profile.Subs.Name=Test" +
                "&Profile.Subs.Id=5" +
                "&Profile.Subs.Name=Test" +
                "&Profile.Categories=a" +
                "&Profile.Categories=B" +
                "&Profile.Sub.Id=6" +
                "&Profile.Sub.Name=Test";

            Assert.Equal(expectedQuery, query);
        }
Exemplo n.º 4
0
        string AddQueryAndAutorize(MethodsType method, Dictionary <string, string> query = null, object objectBody = null)
        {
            if (autorization == Autorization.NONE)
            {
                client.AddQuery(query);
            }
            else if (autorization == Autorization.MARKET)
            {
                if (!session.IsMarketAutorized)
                {
                    throw new UnautorizedClientException("Client is unautorized, use SetAutorizationData() method for autorize client, " +
                                                         "method required public api key.");
                }

                client.AddQuery(query);
                client.AddOwnHeaderToRequest("X-MBX-APIKEY", session.PublicKey);
            }
            else if (autorization == Autorization.TRADING)
            {
                if (!session.IsTradingAutorized)
                {
                    throw new UnautorizedClientException("Client is unautorized, use SetAutorizationData() method for autorize client, " +
                                                         "method required public and private api key.");
                }

                client.AddOwnHeaderToRequest("X-MBX-APIKEY", session.PublicKey);

                string totalParmas = string.Empty;

                if (query != null)
                {
                    totalParmas += client.AddQuery(query);
                }

                string body = string.Empty;
                if (objectBody != null)
                {
                    body = ObjectToQueryConverter.Convert(objectBody);

                    if (method != MethodsType.POST)
                    {
                        totalParmas += client.AddStringToEndOfQuery("&" + body);
                    }
                    else
                    {
                        totalParmas += body;
                    }
                }
                else
                {
                    if (method == MethodsType.POST)
                    {
                        body         = "null";
                        totalParmas += body;
                    }
                }

                if (query != null)
                {
                    client.AddStringToEndOfQuery("&signature=" + HashManager.HashHMACHex(session.PrivateKey, totalParmas.Substring(1)));
                }
                else
                {
                    client.AddStringToEndOfQuery("?signature=" + HashManager.HashHMACHex(session.PrivateKey, totalParmas.Substring(1)));
                }

                if (method == MethodsType.POST)
                {
                    return(body);
                }
            }

            return("");
        }