Commit 5f30dd08 authored by Jason Williams's avatar Jason Williams
Browse files

Adds optional response bodies to PUT, PULL, and DELETE methods.

Tests them with the Xbox Settings API, which returns the updated setting object when calling PUT.
parent 6a0e8e28
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -66,8 +66,10 @@ namespace TestApp
                    setting.Name = desiredSetting;
                    setting.Value = desiredValue;

                    Task setSettingTask = portal.UpdateXboxSetting(setting);
                    Task<XboxSetting> setSettingTask = portal.UpdateXboxSetting(setting);
                    setSettingTask.Wait();

                    Console.WriteLine(setSettingTask.Result);
                }
            }
        }
+3 −0
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.XML" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="Windows.Foundation.UniversalApiContract">
      <HintPath>C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\2.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
    </Reference>
  </ItemGroup>
  <Choose>
    <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
+21 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
//----------------------------------------------------------------------------------------------

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Tools.WindowsDevicePortal.Tests;
@@ -21,8 +22,10 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// </summary>
        /// <param name="uri">The uri to which the delete request will be issued.</param>
        /// <returns>Task tracking HTTP completion</returns>
        private async Task Delete(Uri uri)
        private async Task<Stream> Delete(Uri uri)
        {
            MemoryStream dataStream = null;

            WebRequestHandler requestSettings = new WebRequestHandler();
            requestSettings.UseDefaultCredentials = false;
            requestSettings.Credentials = this.deviceConnection.Credentials;
@@ -42,8 +45,25 @@ namespace Microsoft.Tools.WindowsDevicePortal
                    {
                        throw new DevicePortalException(response);
                    }

                    if (response.Content != null)
                    {
                        using (HttpContent content = response.Content)
                        {
                            dataStream = new MemoryStream();

                            Task copyTask = content.CopyToAsync(dataStream);
                            await copyTask.ConfigureAwait(false);
                            copyTask.Wait();

                            // Ensure we return with the stream pointed at the origin.
                            dataStream.Position = 0;
                        }
                    }
                }
            }

            return dataStream;
        }
    }
}
+21 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
//----------------------------------------------------------------------------------------------

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Tools.WindowsDevicePortal.Tests;
@@ -21,8 +22,10 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// </summary>
        /// <param name="uri">The uri to which the post request will be issued.</param>
        /// <returns>Task tracking the completion of the POST request</returns>
        private async Task Post(Uri uri)
        private async Task<Stream> Post(Uri uri)
        {
            MemoryStream dataStream = null;

            WebRequestHandler requestSettings = new WebRequestHandler();
            requestSettings.UseDefaultCredentials = false;
            requestSettings.Credentials = this.deviceConnection.Credentials;
@@ -42,8 +45,25 @@ namespace Microsoft.Tools.WindowsDevicePortal
                    {
                        throw new DevicePortalException(response);
                    }

                    if (response.Content != null)
                    {
                        using (HttpContent content = response.Content)
                        {
                            dataStream = new MemoryStream();

                            Task copyTask = content.CopyToAsync(dataStream);
                            await copyTask.ConfigureAwait(false);
                            copyTask.Wait();

                            // Ensure we return with the stream pointed at the origin.
                            dataStream.Position = 0;
                        }
                    }
                }
            }

            return dataStream;
        }
    }
}
+21 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
//----------------------------------------------------------------------------------------------

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Tools.WindowsDevicePortal.Tests;
@@ -22,10 +23,12 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// <param name="uri">The uri to which the put request will be issued.</param>
        /// <param name="body">The HTTP content comprising the body of the request.</param>
        /// <returns>Task tracking the PUT completion.</returns>
        private async Task Put(
        private async Task<Stream> Put(
            Uri uri,
            HttpContent body = null)
        {
            MemoryStream dataStream = null;

            WebRequestHandler requestSettings = new WebRequestHandler();
            requestSettings.UseDefaultCredentials = false;
            requestSettings.Credentials = this.deviceConnection.Credentials;
@@ -46,8 +49,25 @@ namespace Microsoft.Tools.WindowsDevicePortal
                    {
                        throw new DevicePortalException(response);
                    }

                    if (response.Content != null)
                    {
                        using (HttpContent content = response.Content)
                        {
                            dataStream = new MemoryStream();

                            Task copyTask = content.CopyToAsync(dataStream);
                            await copyTask.ConfigureAwait(false);
                            copyTask.Wait();

                            // Ensure we return with the stream pointed at the origin.
                            dataStream.Position = 0;
                        }
                    }
                }
            }

            return dataStream;
        }
    }
}
Loading