Commit 9aa0a422 authored by Jason Williams's avatar Jason Williams
Browse files

Add Xbox Settings API along with tests for it.

parent 1a01c7af
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ namespace MockDataGenerator
            DevicePortal.MachineNameApi,
            DevicePortal.OsInfoApi,
            DevicePortal.XboxLiveUserApi,
            DevicePortal.XboxSettingsApi,
        };

        /// <summary>
@@ -108,10 +109,24 @@ namespace MockDataGenerator
            else
            {
                foreach (string endpoint in Endpoints)
                {
                    try
                    {
                        Task saveResponseTask = portal.SaveEndpointResponseToFile(endpoint, directory);
                        saveResponseTask.Wait();
                    }
                    catch (Exception e)
                    {
                        // Print an error message if possible but continue on.
                        // Not all APIs are available on all device types.
                        if (e.InnerException is DevicePortalException)
                        {
                            DevicePortalException exception = e.InnerException as DevicePortalException;

                            Console.WriteLine(string.Format("Failed to generate .dat for {0} with status {1} ({2}).", endpoint, exception.HResult, exception.Reason));
                        }
                    }
                }
            }

            Console.WriteLine("Data generated in directory {0}. Please make sure to remove any personally identifiable information from the response(s) before adding them as mock responses.", directory);
+75 −0
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="SettingOperation.cs" company="Microsoft Corporation">
//     Licensed under the MIT License. See LICENSE.TXT in the project root license information.
// </copyright>
//----------------------------------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using Microsoft.Tools.WindowsDevicePortal;
using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;

namespace TestApp
{
    /// <summary>
    /// Helper for Setting related operations
    /// </summary>
    internal class SettingOperation
    {
        /// <summary>
        /// Usage message for this operation
        /// </summary>
        private const string XblSettingUsageMessage = "Usage:\n" +
            "  [/setting:<setting name> [/value:<setting value>]]\n" +
            "        Gets current settings and their values. If\n" +
            "        /setting is specified, only returns that value.\n" +
            "        If /value is also specified, sets the settting to\n" +
            "        that value instead of returning the current\n" +
            "        value.\n";

        /// <summary>
        /// Main entry point for handling a Setting operation
        /// </summary>
        /// <param name="portal">DevicePortal reference for communicating with the device.</param>
        /// <param name="parameters">Parsed command line parameters.</param>
        public static void HandleOperation(DevicePortal portal, ParameterHelper parameters)
        {
            if (parameters.HasFlag(ParameterHelper.HelpFlag))
            {
                Console.WriteLine(XblSettingUsageMessage);
                return;
            }

            string desiredSetting = parameters.GetParameterValue("setting");
            string desiredValue = parameters.GetParameterValue("value");

            // Determine if this is for all settings or a single setting.
            if (string.IsNullOrWhiteSpace(desiredSetting))
            {
                Task<XboxSettingList> getSettingsTask = portal.GetXboxSettings();
                getSettingsTask.Wait();

                Console.WriteLine(getSettingsTask.Result);
            }
            else
            {
                if (string.IsNullOrWhiteSpace(desiredValue))
                {
                    Task<XboxSetting> getSettingTask = portal.GetXboxSetting(desiredSetting);
                    getSettingTask.Wait();

                    Console.WriteLine(getSettingTask.Result);
                }
                else
                {
                    XboxSetting setting = new XboxSetting();
                    setting.Name = desiredSetting;
                    setting.Value = desiredValue;

                    Task setSettingTask = portal.UpdateXboxSetting(setting);
                    setSettingTask.Wait();
                }
            }
        }
    }
}
 No newline at end of file
+15 −1
Original line number Diff line number Diff line
@@ -76,6 +76,11 @@ namespace TestApp
            /// Get the system performance operation
            /// </summary>
            GetSystemPerfOperation,

            /// <summary>
            /// Get or set Xbox Settings
            /// </summary>
            XboxSettings,
        }

        /// <summary>
@@ -240,6 +245,10 @@ namespace TestApp
                Console.WriteLine("Total Installed Kb: " + systemPerformanceInformation.TotalInstalledKb);
                Console.WriteLine("Total Pages: " + systemPerformanceInformation.TotalPages);
            }
            else if (operation == OperationType.XboxSettings)
            {
                SettingOperation.HandleOperation(portal, parameters);
            }
        }

        /// <summary>
@@ -273,6 +282,10 @@ namespace TestApp
            {
                return OperationType.GetSystemPerfOperation;
            }
            else if (operation.Equals("config", StringComparison.OrdinalIgnoreCase))
            {
                return OperationType.XboxSettings;
            }

            throw new Exception("Unknown Operation Type. Supported operations are the following:\n" +
                "info\n" +
@@ -280,7 +293,8 @@ namespace TestApp
                "install\n" +
                "reboot\n" +
                "processes\n" +
                "systemPerf\n");
                "systemPerf\n" +
                "config\n");
        }

        /// <summary>
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
  <ItemGroup>
    <Compile Include="DevicePortalConnection.cs" />
    <Compile Include="NetworkShare.cs" />
    <Compile Include="Operations\SettingOperation.cs" />
    <Compile Include="Operations\InstallOperation.cs" />
    <Compile Include="ParameterHelper.cs" />
    <Compile Include="Program.cs" />
+37 −1
Original line number Diff line number Diff line
@@ -68,12 +68,48 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests
        }

        /// <summary>
        /// Basic test of 
        /// Basic test of GET for operating system info for 1508 OS.
        /// </summary>
        [TestMethod]
        public void GetOsInfo_XboxOne_1608()
        {
            XboxHelpers.VerifyOsInformation(this.OperatingSystemVersion);
        }

        /// <summary>
        /// Basic test of the GET method. Gets a mock list of settings
        /// and verifies it comes back as expected from the raw response
        /// content for this 1508 OS.
        /// </summary>
        [TestMethod]
        public void GetXboxSettingsTest_XboxOne_1608()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.XboxSettingsApi, this.PlatformType, this.OperatingSystemVersion);

            Task<XboxSettingList> getSettingsTask = TestHelpers.Portal.GetXboxSettings();
            getSettingsTask.Wait();

            Assert.AreEqual(TaskStatus.RanToCompletion, getSettingsTask.Status);

            List<XboxSetting> settings = getSettingsTask.Result.Settings;

            // Check some known things about this response.
            Assert.AreEqual(8, settings.Count);

            Assert.AreEqual("AudioBitstreamFormat", settings[0].Name);
            Assert.AreEqual("DTS", settings[0].Value);
            Assert.AreEqual("Audio", settings[0].Category);
            Assert.AreEqual("No", settings[0].RequiresReboot);

            Assert.AreEqual("ColorDepth", settings[1].Name);
            Assert.AreEqual("24 bit", settings[1].Value);
            Assert.AreEqual("Video", settings[1].Category);
            Assert.AreEqual("Yes", settings[1].RequiresReboot);

            Assert.AreEqual("TVResolution", settings[7].Name);
            Assert.AreEqual("720p", settings[7].Value);
            Assert.AreEqual("Video", settings[7].Category);
            Assert.AreEqual("No", settings[7].RequiresReboot);
        }
    }
}
Loading