public void TestCommandWithEnumerableProp()
        {
            SubObject[] objects =
            {
                new SubObject()
                {
                    Prop = "value1"
                },
                new SubObject()
                {
                    Prop = "value2"
                },
                new SubObject()
                {
                    Prop = "value3"
                }
            };

            TestCommandEnumerable command = new()
            {
                Props = objects
            };

            Uri requestUri = ApiRequestBuilder.BuildRequest(api, command);

            var queryCollection = QueryHelpers.ParseQuery(requestUri.Query);

            Assert.True(queryCollection.ContainsKey("Prop1"));
            Assert.AreEqual(queryCollection["Prop1"], "value1");
            Assert.True(queryCollection.ContainsKey("Prop2"));
            Assert.AreEqual(queryCollection["Prop2"], "value2");
            Assert.True(queryCollection.ContainsKey("Prop3"));
            Assert.AreEqual(queryCollection["Prop3"], "value3");
        }
 public void TestCommandNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         Uri requestUri = ApiRequestBuilder.BuildRequest <object>(api, null);
     });
 }
        public void TestApiNull()
        {
            TestCommandBasic command = new();

            Assert.Throws <ArgumentNullException>(() =>
            {
                Uri requestUri = ApiRequestBuilder.BuildRequest(null, command);
            });
        }
        public void TestClassWithNoCommandAttr()
        {
            TestClassWithNoAttr badCommand = new();

            Assert.Throws <ArgumentException>(() =>
            {
                Uri requestUri = ApiRequestBuilder.BuildRequest(api, badCommand);
            });
        }
        public void TestNoParams()
        {
            TestCommandBasic command = new();

            Uri requestUri = ApiRequestBuilder.BuildRequest(api, command);

            var queryCollection = QueryHelpers.ParseQuery(requestUri.Query);

            AssertCommonQueryParams(queryCollection);
            Assert.False(queryCollection.ContainsKey("Prop"));
            Assert.False(queryCollection.ContainsKey("Prop1"));
        }
        public void TestEncodedParam()
        {
            TestCommandBasic command = new()
            {
                Prop  = "Encode This",
                Prop1 = "Also&This"
            };

            Uri requestUri = ApiRequestBuilder.BuildRequest(api, command);

            var queryCollection = QueryHelpers.ParseQuery(requestUri.Query);

            AssertCommonQueryParams(queryCollection);
            AssertQueryParam(queryCollection, "Prop", "Encode This");
            AssertQueryParam(queryCollection, "Prop1", "Also&This");
        }
        public void TestBasicCommand()
        {
            TestCommandBasic command = new()
            {
                Prop  = "Test",
                Prop1 = "Test2"
            };

            Uri requestUri = ApiRequestBuilder.BuildRequest(api, command);

            var queryCollection = QueryHelpers.ParseQuery(requestUri.Query);

            AssertCommonQueryParams(queryCollection);
            AssertQueryParam(queryCollection, "Prop", "Test");
            AssertQueryParam(queryCollection, "Prop1", "Test2");
        }
        internal async Task <ApiResponse <TResponse>?> ExecuteCommand <TCommand, TResponse>(TCommand command) where TResponse : CommandResponse
        {
            Uri requestUri = ApiRequestBuilder.BuildRequest(Api, command);

            XmlSerializer xmlSerializer = new(typeof(ApiResponse <TResponse>));

            using Stream responseStream = await Api.HttpClient.GetStreamAsync(requestUri);

            /*
             * using StreamReader sr = new(responseStream);
             *
             * string responseString = sr.ReadToEnd();
             *
             * Debugger.Break();
             */

            return(xmlSerializer.Deserialize(responseStream) as ApiResponse <TResponse>);
        }