/// <summary>
        /// Adds a response for this endpoint, loading from the file matching the deviceType and OsVersion
        /// </summary>
        /// <param name="endpoint">Endpoint we are mocking.</param>
        /// <param name="platform">Device platform we are testing.</param>
        /// <param name="friendlyOperatingSystemVersion">The friendly name of the OS Version we are testing, used to find the mock file.</param>
        /// <param name="httpMethod">HTTP method we are mocking.</param>
        public void AddMockResponse(string endpoint, DevicePortalPlatforms platform, string friendlyOperatingSystemVersion, HttpMethods httpMethod)
        {
            // If no OS is provided, use the default.
            if (friendlyOperatingSystemVersion == null)
            {
                this.AddMockResponse(endpoint, httpMethod);
                return;
            }

            if (httpMethod != HttpMethods.Get)
            {
                endpoint = httpMethod.ToString() + "_" + endpoint;
            }

            Utilities.ModifyEndpointForFilename(ref endpoint);

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            if (platform == DevicePortalPlatforms.IoTDragonboard410c || platform == DevicePortalPlatforms.IoTMinnowboardMax || platform == DevicePortalPlatforms.IoTRaspberryPi2 || platform == DevicePortalPlatforms.IoTRaspberryPi3)
            {
                string filepath = Path.Combine("MockData", "IoT", friendlyOperatingSystemVersion, endpoint + "_" + platform.ToString() + "_" + friendlyOperatingSystemVersion + ".dat");
                response.Content = this.LoadContentFromFile(filepath);
            }
            else
            {
                string filepath = Path.Combine("MockData", platform.ToString(), friendlyOperatingSystemVersion, endpoint + "_" + platform.ToString() + "_" + friendlyOperatingSystemVersion + ".dat");
                response.Content = this.LoadContentFromFile(filepath);
            }

            this.mockResponses.Add(endpoint.ToLowerInvariant(), response);
        }
示例#2
0
        /// <summary>
        /// Helper for establishing a mock connection to a DevicePortal object.
        /// </summary>
        /// <param name="platform">The platform we are pretending to connect to.</param>
        /// <param name="operatingSystemVersion">The OS we are pretending it is running.</param>
        public static void EstablishMockConnection(DevicePortalPlatforms platform, string operatingSystemVersion)
        {
            TestHelpers.MockHttpResponder = new MockHttpResponder();
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.DeviceFamilyApi, platform, operatingSystemVersion, HttpMethods.Get);
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.OsInfoApi, platform, operatingSystemVersion, HttpMethods.Get);
            if (platform == DevicePortalPlatforms.HoloLens)
            {
                TestHelpers.MockHttpResponder.AddMockResponse(
                    DevicePortal.HolographicWebManagementHttpSettingsApi,
                    platform,
                    operatingSystemVersion,
                    HttpMethods.Get);
            }

            TestHelpers.Portal = new DevicePortal(
                connection: new MockDevicePortalConnection(),
                createHttpClient: (_, __) => TestHelpers.MockHttpResponder,
                webSocketFactory: new MockWebSocketFactory());

            Task connectTask = TestHelpers.Portal.ConnectAsync(updateConnection: false);

            connectTask.Wait();

            Assert.AreEqual(HttpStatusCode.OK, TestHelpers.Portal.ConnectionHttpStatusCode);
        }
        /// <summary>
        /// Checks if this device is a hololens.
        /// </summary>
        /// <param name="platform">The platform.</param>
        /// <param name="deviceFamily">The device family.</param>
        /// <returns>Whether this is a hololens.</returns>
        public static bool IsHoloLens(
            DevicePortalPlatforms platform,
            string deviceFamily)
        {
            bool isHoloLens = false;

            if ((platform == DevicePortalPlatforms.HoloLens) ||
                ((platform == DevicePortalPlatforms.VirtualMachine) && (deviceFamily == "Windows.Holographic")))
            {
                isHoloLens = true;
            }

            return(isHoloLens);
        }