Ejemplo n.º 1
0
        ICreatesWebDriver GetFactory(ICreatesWebDriver factory, object options)
        {
            if (options != null && (factory is ICreatesWebDriverFromOptions))
            {
                return(new OptionsCachingDriverFactoryProxy((ICreatesWebDriverFromOptions)factory, options));
            }

            return(factory);
        }
        public void GetProviderOptions_returns_null_for_unsupported_factory(ICreatesWebDriver factory,
                                                                            Dictionary <string, string> options,
                                                                            FactoryOptionsFactory sut)
        {
            // Act
            var result = sut.GetFactoryOptions(factory, options);

            // Assert
            Assert.That(result, Is.Null);
        }
        DummyBrowserFactory GetProxiedFactory(ICreatesWebDriver factory)
        {
            var fac = factory as OptionsCachingDriverFactoryProxy;

            if (ReferenceEquals(fac, null))
            {
                return(null);
            }

            return(fac.ProxiedFactory as DummyBrowserFactory);
        }
        public void CreateFactory_returns_result_from_instance_creator([Frozen] IInstanceCreator creator,
                                                                       WebDriverFactoryCreator sut,
                                                                       ICreatesWebDriver expectedResult)
        {
            // Arrange
            var typeName = typeof(FactoryType).AssemblyQualifiedName;

            Mock.Get(creator).Setup(x => x.CreateInstance(typeof(FactoryType))).Returns(expectedResult);

            // Act
            var result = sut.GetFactory(typeName);

            // Assert
            Assert.That(result, Is.SameAs(expectedResult));
        }
        /// <summary>
        /// Gets the factory options.
        /// </summary>
        /// <returns>The factory options.</returns>
        /// <param name="factory">A web driver factory.</param>
        /// <param name="optionsDictionary">A collection of key-value pairs which indicate the values to populate into the created options instance.</param>
        public object GetFactoryOptions(ICreatesWebDriver factory,
                                        IDictionary <string, string> optionsDictionary)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var factoryWithOptionsSupport = factory as ICreatesWebDriverFromOptions;

            if (factoryWithOptionsSupport == null)
            {
                return(null);
            }

            var optionsObject = factoryWithOptionsSupport.CreateEmptyOptions();

            PopulateOptions(optionsObject, optionsDictionary);

            return(optionsObject);
        }
        public void GetWebDriverProviderFactory_returns_factory_creator_result_when_factory_does_not_support_options(ICreatesWebDriverFactory factoryCreator,
                                                                                                                     ICreatesFactoryOptions optionsCreator,
                                                                                                                     IDescribesWebDriverFactory config,
                                                                                                                     ICreatesWebDriver factory,
                                                                                                                     string typeName,
                                                                                                                     Dictionary <string, string> optionsDictionary)
        {
            // Arrange
            var sut = new WebDriverFactorySource(factoryCreator, optionsCreator);

            Mock.Get(config)
            .Setup(x => x.GetFactoryAssemblyQualifiedTypeName())
            .Returns(typeName);
            Mock.Get(config)
            .Setup(x => x.GetOptionKeyValuePairs())
            .Returns(optionsDictionary);
            Mock.Get(factoryCreator)
            .Setup(x => x.GetFactory(It.IsAny <string>()))
            .Returns(factory);

            // Act
            var result = sut.CreateFactory(config);

            // Assert
            Assert.That(result, Is.SameAs(factory));
        }