Beispiel #1
0
        public void Parse_ShouldThrowUnsupportedBrowserConfigurationExceptionWhenBrowserStackServiceIsSupportedReturnsFalse()
        {
            // Arrange

            BrowserConfiguration browserConfiguration = null;

            _browserStackService.IsNotSupported(Arg.Do <BrowserConfiguration>(x => browserConfiguration = x)).Returns(true);

            Action attemptToParseUnSupportedBrowserConfiguration = () => _sut.Parse("unknown,some device");

            //Assert
            var exception = attemptToParseUnSupportedBrowserConfiguration
                            .ShouldThrow <UnsupportedBrowserException>()
                            .WithMessage("some device is not supported").Which;

            exception.Browser.Should().BeSameAs(browserConfiguration);
        }
Beispiel #2
0
        public BrowserConfiguration Parse(string value)
        {
            bool isMobileDevice;
            var  parameters = ValidateAndExtractBrowserConfiguration(value, out isMobileDevice);
            BrowserConfiguration result;

            if (isMobileDevice)
            {
                result = new BrowserConfiguration(parameters[0], parameters[1].Replace(ItemSpaceSeparator, " "));
            }
            else if (parameters.Length == 1)
            {
                if (!IsNotDesktopResolution(parameters[0]))
                {
                    throw new InvalidBrowserConfigurationException("First and only parameter cannot be a desktop resolution");
                }
                result = new BrowserConfiguration(parameters[0]);
            }
            else if (parameters.Length >= 4)
            {
                result = new BrowserConfiguration(parameters[0], parameters[1],
                                                  parameters[2].Replace(ItemSpaceSeparator, " "),
                                                  parameters[3], ParseDesktopResolution(parameters));
            }
            else
            {
                result = new BrowserConfiguration(parameters[0], resolution: parameters[1]);
            }

            if (_browserStackService.IsNotSupported(result))
            {
                throw new UnsupportedBrowserException(result);
            }

            return(result);
        }