Exemple #1
0
        void VerifyAllArguments(string screenshotsPath)
        {
            if (osVersion == null)
            {
                throw new ArgumentNullException(nameof(osVersion));
            }

            var regex = new Regex("([a-z][A-Z]*)+[-]([0-9]*)[-][0-9]");

            if (!regex.IsMatch(osVersion))
            {
                const string Message = "osVersion must be OS name followed by OS version, seperated by \"-\". ";
                var          example = "Example: \"iOS-9-2\". osVersion was: \"" + osVersion + "\".";
                throw new ArgumentException(Message + example, nameof(osVersion));
            }

            if (screenshotsPath == null)
            {
                throw new ArgumentNullException(nameof(screenshotsPath));
            }

            if (!Directory.Exists(screenshotsPath))
            {
                Directory.CreateDirectory(screenshotsPath);
            }

            if (appBundlePath == null)
            {
                throw new ArgumentNullException(nameof(appBundlePath));
            }

            if (!Directory.Exists(appBundlePath))
            {
                throw new ArgumentException($"Could not find App bundle at: \"{appBundlePath}\".",
                                            nameof(appBundlePath));
            }

            const string SimulatorNameErrorMessage = "Specify the names of the devices you wish to screenshot. Available device names are:{0}{0}{1}{0}";
            var          availableSimulatorNames   = DeviceSetParser.GetAvailableSimulatorNames(osVersion);

            if (deviceNames == null)
            {
                throw new ArgumentNullException(string.Format(SimulatorNameErrorMessage, Environment.NewLine, string.Join(Environment.NewLine, availableSimulatorNames)), nameof(deviceNames));
            }

            if (deviceNames.Length == 0 || deviceNames.Any(d => !availableSimulatorNames.Contains(d)))
            {
                throw new ArgumentException(string.Format(SimulatorNameErrorMessage, Environment.NewLine, string.Join(Environment.NewLine, availableSimulatorNames)), nameof(deviceNames));
            }
        }