public void ParseMobileEnvironmentTest_ValidMobileEnvironment_ReturnsExpectedMobileEnvironment()
        {
            MobileEnvironment mobileEnvironment = ParallelRunnerEnvironmentUtil.
                                                  ParseMobileEnvironment(MobileEnvironment);

            // function suceeded
            Assert.IsNotNull(mobileEnvironment);

            // propertes should be non-null
            Assert.IsNotNull(mobileEnvironment.device);
            Assert.IsNotNull(mobileEnvironment.lab);

            Device device = mobileEnvironment.device;

            // not present in the string
            Assert.IsNull(device.deviceID);

            // only the manufacturer should be filled
            Assert.IsNull(device.model);

            // must be present
            Assert.IsNotNull(device.manufacturer);
            Assert.IsNotNull(device.osType);
            Assert.IsNotNull(device.osVersion);

            Assert.AreEqual("android", device.osType);
            Assert.AreEqual("4.4.2", device.osVersion);
            Assert.AreEqual("\"samsung gt-i9515\"", device.manufacturer);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse the mobile environment provided in jenkins.
        /// </summary>
        /// <param name="environment"> the environment string</param>
        /// <returns>the MobileEnvironment for ParallelRunner </returns>
        public static MobileEnvironment ParseMobileEnvironment(string environment)
        {
            var dictionary = GetEnvironmentProperties(environment);

            // invalid environment string
            if (dictionary.Count == 0)
            {
                return(null);
            }

            var device = new Device();

            var mobileEnvironment = new MobileEnvironment
            {
                device = device,
                lab    = MobileCenterLab
            };

            if (dictionary.ContainsKey(DeviceIdKey.ToLower()))
            {
                if (!string.IsNullOrEmpty(dictionary[DeviceIdKey.ToLower()]))
                {
                    device.deviceID = dictionary[DeviceIdKey.ToLower()];
                }
            }

            if (dictionary.ContainsKey(ManufacturerAndModelKey.ToLower()))
            {
                if (!string.IsNullOrEmpty(dictionary[ManufacturerAndModelKey.ToLower()]))
                {
                    device.manufacturer = dictionary[ManufacturerAndModelKey.ToLower()];
                }
            }

            if (dictionary.ContainsKey(OsVersionKey.ToLower()))
            {
                if (!string.IsNullOrEmpty(dictionary[OsVersionKey.ToLower()]))
                {
                    device.osVersion = dictionary[OsVersionKey.ToLower()];
                }
            }

            if (dictionary.ContainsKey(OsTypeKey.ToLower()))
            {
                if (!string.IsNullOrEmpty(dictionary[OsTypeKey.ToLower()]))
                {
                    device.osType = dictionary[OsTypeKey.ToLower()];
                }
            }

            // the environment string should contain at least a valid property
            // in order for PrallelRunner to be able to query MC for the specific device
            if (device.deviceID == null && (device.osType == null && device.osVersion == null && device.manufacturer == null))
            {
                return(null);
            }

            return(mobileEnvironment);
        }
        public void ParseMobileEnvironmentTest_EmptyMobileEnvironment_ReturnsNull()
        {
            MobileEnvironment mobileEnvironment = ParallelRunnerEnvironmentUtil.
                                                  ParseMobileEnvironment("");

            // function suceeded
            Assert.IsNull(mobileEnvironment);
        }
        public void ParseMobileEnvironmentTest_InvalidKeyMobileEnvironment_ReturnsNull()
        {
            string invalidEnvironment = "invalid: android";

            MobileEnvironment mobileEnvironment = ParallelRunnerEnvironmentUtil.
                                                  ParseMobileEnvironment(invalidEnvironment);

            // function suceeded
            Assert.IsNull(mobileEnvironment);
        }