/// <summary>
        /// Called by the 'BuildEngine' method to handle
        /// creation of the engine instance.
        /// </summary>
        /// <param name="properties"></param>
        /// <returns>
        /// An <see cref="IAspectEngine"/>.
        /// </returns>
        protected override DeviceDetectionHashEngine NewEngine(
            List <string> properties)
        {
            if (DataFiles.Count != 1)
            {
                throw new PipelineConfigurationException(
                          "This builder requires one and only one configured file " +
                          $"but it has {DataFileConfigs.Count}");
            }
            var dataFile = DataFiles.First();

            // We remove the data file configuration from the list.
            // This is because the on-premise engine builder base class
            // adds all the data file configs after engine creation.
            // However, the device detection data files are supplied
            // directly to the constructor.
            // Consequently, we remove it here to stop it from being added
            // again by the base class.
            DataFiles.Remove(dataFile);

            // Update the swig configuration object.
            SwigConfig.setUseUpperPrefixHeaders(false);
            if (dataFile.Configuration.CreateTempCopy && String.IsNullOrEmpty(TempDir) == false)
            {
                using (var tempDirs = new VectorStringSwig())
                {
                    tempDirs.Add(TempDir);
                    SwigConfig.setTempDirectories(tempDirs);
                }
                SwigConfig.setUseTempFile(true);
            }

            // Create swig property configuration object.
            IRequiredPropertiesConfigSwigWrapper propertyConfig = null;

            using (var vProperties = new VectorStringSwig(properties)) {
                propertyConfig = SwigFactory.CreateRequiredProperties(vProperties);
            }

            return(new DeviceDetectionHashEngine(
                       _loggerFactory,
                       dataFile,
                       SwigConfig,
                       propertyConfig,
                       CreateAspectData,
                       TempDir,
                       SwigFactory));
        }
        public void Init()
        {
            _builder = new DeviceDetectionPatternEngineBuilder(new LoggerFactory());

            // Setup values returned by IMetaDataSwigWrapper
            var properties = new Mock <IPropertyCollectionSwigWrapper>();

            properties.Setup(c => c.GetEnumerator()).Returns(new List <IFiftyOneAspectPropertyMetaData>().GetEnumerator());
            var components = new Mock <IComponentCollectionSwigWrapper>();

            components.Setup(c => c.GetEnumerator()).Returns(new List <IComponentMetaData>().GetEnumerator());

            // Setup values returned by IEngineSwigWrapper
            var swigMetaData = new Mock <IMetaDataSwigWrapper>();

            swigMetaData.Setup(d => d.getProperties(It.IsAny <DeviceDetectionPatternEngine>())).Returns(properties.Object);
            swigMetaData.Setup(d => d.getComponents(It.IsAny <DeviceDetectionPatternEngine>())).Returns(components.Object);
            var date = new Mock <IDateSwigWrapper>();

            date.Setup(d => d.getYear()).Returns(2019);
            date.Setup(d => d.getMonth()).Returns(12);
            date.Setup(d => d.getDay()).Returns(10);

            // Setup swig engine wrapper
            var swigEngine = new Mock <IEngineSwigWrapper>();

            swigEngine.Setup(e => e.getKeys()).Returns(new VectorStringSwig());
            swigEngine.Setup(e => e.getMetaData()).Returns(swigMetaData.Object);
            swigEngine.Setup(e => e.getPublishedTime()).Returns(date.Object);
            swigEngine.Setup(e => e.getUpdateAvailableTime()).Returns(date.Object);

            // Setup factory to create our mock engine rather than a real one
            var factory = new SwigFactory();

            factory.EngineFromData = (a, b, c, d) => { return(swigEngine.Object); };

            // Assign the factory to the builder
            _builder.SwigFactory = factory;
            _builder.SetAutoUpdate(false)
            .SetDataFileSystemWatcher(false);
        }