Commit 1a01c7af authored by Jason Williams's avatar Jason Williams
Browse files

Adds some Xbox specific test mocks to establish the pattern for other device types and OS versions.

parent 58b60bb8
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
//----------------------------------------------------------------------------------------------

using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;

namespace Microsoft.Tools.WindowsDevicePortal.Tests
{
@@ -22,7 +23,29 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests
        /// </summary>
        public BaseTests()
        {
            TestHelpers.EstablishMockConnection();
            TestHelpers.EstablishMockConnection(this.PlatformType, this.OperatingSystemVersion);
        }

        /// <summary>
        /// Gets the overridable Platform type.
        /// </summary>
        protected virtual DevicePortalPlatforms PlatformType
        {
            get
            {
                return DevicePortalPlatforms.Unknown;
            }
        }

        /// <summary>
        /// Gets the overridable OS Version.
        /// </summary>
        protected virtual string OperatingSystemVersion
        {
            get
            {
                return null;
            }
        }

        /// <summary>
+38 −0
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="XboxHelpers.cs" company="Microsoft Corporation">
//     Licensed under the MIT License. See LICENSE.TXT in the project root license information.
// </copyright>
//----------------------------------------------------------------------------------------------

using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;

namespace Microsoft.Tools.WindowsDevicePortal.Tests
{
    /// <summary>
    /// Helpers for Xbox tests.
    /// </summary>
    public class XboxHelpers
    {
        /// <summary>
        /// Helper method for verifying OS info based on a given version.
        /// </summary>
        /// <param name="operatingSystemVersion">The version of the OS we are targeting.</param>
        public static void VerifyOsInformation(string operatingSystemVersion)
        {
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.MachineNameApi, DevicePortalPlatforms.XboxOne, operatingSystemVersion);

            Task<string> getNameTask = TestHelpers.Portal.GetDeviceName();
            getNameTask.Wait();

            string formattedOsVersion = TestHelpers.Portal.OperatingSystemVersion;
            formattedOsVersion = formattedOsVersion.Replace('.', '_');
            formattedOsVersion = formattedOsVersion.Replace('-', '_');

            Assert.AreEqual(operatingSystemVersion, formattedOsVersion);
            Assert.AreEqual(DevicePortalPlatforms.XboxOne, TestHelpers.Portal.Platform);
            Assert.AreEqual("XboxOneName", getNameTask.Result);
        }
    }
}
+79 −0
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="XboxOne_14385_1002_amd64fre_rs1_xbox_rel_1608_160709_1700.cs" company="Microsoft Corporation">
//     Licensed under the MIT License. See LICENSE.TXT in the project root license information.
// </copyright>
//----------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;

namespace Microsoft.Tools.WindowsDevicePortal.Tests
{
    /// <summary>
    /// Test class for XboxOne_14385_1002_amd64fre_rs1_xbox_rel_1608_160709_1700 version
    /// </summary>
    [TestClass]
    public class XboxOne_14385_1002_amd64fre_rs1_xbox_rel_1608_160709_1700 : BaseTests
    {
        /// <summary>
        /// Gets the Platform type these tests are targeting.
        /// </summary>
        protected override DevicePortalPlatforms PlatformType
        {
            get
            {
                return DevicePortalPlatforms.XboxOne;
            }
        }

        /// <summary>
        /// Gets the OS Version these tests are targeting.
        /// </summary>
        protected override string OperatingSystemVersion
        {
            get
            {
                return "14385_1002_amd64fre_rs1_xbox_rel_1608_160709_1700";
            }
        }

        /// <summary>
        /// Gets a mock list of users and verifies it comes back as 
        /// expected from the raw response content using a mock generated
        /// on an Xbox One running the 1608 OS recovery.
        /// </summary>
        [TestMethod]
        public void GetXboxLiveUserListTest_XboxOne_1608()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.XboxLiveUserApi, this.PlatformType, this.OperatingSystemVersion);

            Task<UserList> getUserTask = TestHelpers.Portal.GetXboxLiveUsers();
            getUserTask.Wait();

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

            List<UserInfo> users = getUserTask.Result.Users;

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

            Assert.AreEqual("TestUser@XboxTestDomain.com", users[0].EmailAddress);
            Assert.AreEqual("TestGamertag", users[0].Gamertag);
            Assert.AreEqual(20u, users[0].UserId);
            Assert.AreEqual("1234567890123456", users[0].XboxUserId);
            Assert.AreEqual(false, users[0].SignedIn);
            Assert.AreEqual(false, users[0].AutoSignIn);
        }

        /// <summary>
        /// Basic test of 
        /// </summary>
        [TestMethod]
        public void GetOsInfo_XboxOne_1608()
        {
            XboxHelpers.VerifyOsInformation(this.OperatingSystemVersion);
        }
    }
}
+1 −1
Original line number Diff line number Diff line
{"ComputerName" : "XboxOne", "Language" : "en-US", "OsEdition" : "SystemOS", "OsEditionId" : 2882382797, "OsVersion" : "14381.1003.amd64fre.rs1_xbox_rel_1610.160704-1900", "Platform" : "Xbox One"}
 No newline at end of file
{"ComputerName" : "MyComputerName", "Language" : "en-US", "OsEdition" : "SystemOS", "OsEditionId" : 2882382797, "OsVersion" : "12345.1111.amd64fre.rs1.2123456-1111", "Platform" : "SomePlatform"}
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
Defaults contains mocks that are device and release agnostic to allow some 'general' testing of APIs.

Each device type can have its own folder as well for device specific responses, and subfolders 
under the device folder for release specific responses. This enables back-compat testing to ensure
new changes to the wrappers still operate as expected with responses from old devices.
 No newline at end of file
Loading