Esempio n. 1
0
        /// <summary>
        /// Utility method to get the settings
        /// </summary>
        /// <param name="lookUp">IDynamoLookUp instance</param>
        /// <param name="updateManager"></param>
        /// <returns></returns>
        public static UpdateManagerConfiguration GetSettings(IDynamoLookUp lookUp, IUpdateManager updateManager = null)
        {
            string filePath;
            var    exists = TryGetConfigFilePath(out filePath);

#if DEBUG
            //This code is just to create the default config file to
            //save the default settings, which later on can be modified
            //to re-direct it to other download target for testing.
            if (!exists)
            {
                var umConfig = new UpdateManagerConfiguration();
                umConfig.Save(filePath, updateManager);
            }
#endif
            if (!exists)
            {
                return new UpdateManagerConfiguration()
                       {
                           DynamoLookUp = lookUp
                       }
            }
            ;

            var config = Load(filePath, updateManager);
            if (null != config)
            {
                config.DynamoLookUp = lookUp;
            }

            return(config);
        }
Esempio n. 2
0
            private readonly FieldInfo fieldInfo; //internal configuration field.

            /// <summary>
            /// Creates ConfigInjection instance.
            /// </summary>
            /// <param name="updateManager">UpdateManager instance to which configuration is to be injected.</param>
            /// <param name="configuration">The configuration for injection.</param>
            public ConfigInjection(DynUpdateManager updateManager, UpdateManagerConfiguration configuration)
            {
                this.updateManager = updateManager;
                fieldInfo = updateManager.GetType()
                    .GetField("configuration", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.IsNotNull(fieldInfo);

                this.configuration = fieldInfo.GetValue(updateManager);
                fieldInfo.SetValue(updateManager, configuration);
            }
Esempio n. 3
0
        /// <summary>
        /// Utility method to get the settings
        /// </summary>
        /// <param name="updateManager"></param>
        /// <returns></returns>
        public static UpdateManagerConfiguration GetSettings(IUpdateManager updateManager = null)
        {
            string filePath;
            var    exists = TryGetConfigFilePath(out filePath);

#if DEBUG
            //This code is just to create the default config file to
            //save the default settings, which later on can be modified
            //to re-direct it to other download target for testing.
            if (!exists)
            {
                var config = new UpdateManagerConfiguration();
                config.Save(filePath, updateManager);
            }
#endif
            return(exists ? Load(filePath, updateManager) : new UpdateManagerConfiguration());
        }
Esempio n. 4
0
        private static Mock<IUpdateManager> MockUpdateManager(string availableVersion, string productVersion)
        {
            var um_mock = new Mock<IUpdateManager>();
            um_mock.Setup(um => um.AvailableVersion).Returns(BinaryVersion.FromString(availableVersion));
            um_mock.Setup(um => um.ProductVersion).Returns(BinaryVersion.FromString(productVersion));

            var config = new UpdateManagerConfiguration()
            {
                DownloadSourcePath = DOWNLOAD_SOURCE_PATH_S,
                SignatureSourcePath = SIGNATURE_SOURCE_PATH_S
            };
            um_mock.Setup(um => um.Configuration).Returns(config);

            var fieldInfo = typeof(UpdateManager).GetField("instance", BindingFlags.Static | BindingFlags.NonPublic);
            Assert.NotNull(fieldInfo);
            fieldInfo.SetValue(UpdateManager.Instance, um_mock.Object);
            return um_mock;
        }
Esempio n. 5
0
        /// <summary>
        /// Utility method to get the settings
        /// </summary>
        /// <param name="updateManager"></param>
        /// <returns></returns>
        public static UpdateManagerConfiguration GetSettings(IUpdateManager updateManager = null)
        {
            string location = Assembly.GetExecutingAssembly().Location;
            string filePath = Path.Combine(
                Path.GetDirectoryName(location),
                DEFAULT_CONFIG_FILE_S);

#if DEBUG
            //This code is just to create the default config file to
            //save the default settings, which later on can be modified
            //to re-direct it to other download target for testing.
            if (!File.Exists(filePath))
            {
                var config = new UpdateManagerConfiguration();
                config.Save(filePath, updateManager);
            }
#endif
            return(File.Exists(filePath) ? Load(filePath, updateManager) : new UpdateManagerConfiguration());
        }
Esempio n. 6
0
        /// <summary>
        /// Utility method to get the settings
        /// </summary>
        /// <param name="lookUp">IDynamoLookUp instance</param>
        /// <param name="updateManager"></param>
        /// <returns></returns>
        public static UpdateManagerConfiguration GetSettings(IDynamoLookUp lookUp, IUpdateManager updateManager = null)
        {
            string filePath;
            var exists = TryGetConfigFilePath(out filePath);
#if DEBUG
            //This code is just to create the default config file to
            //save the default settings, which later on can be modified
            //to re-direct it to other download target for testing.
            if (!exists)
            {
                var umConfig = new UpdateManagerConfiguration();
                umConfig.Save(filePath, updateManager);
            }
#endif
            if (!exists) 
                return new UpdateManagerConfiguration() { DynamoLookUp = lookUp };

            var config = Load(filePath, updateManager);
            if (null != config)
                config.DynamoLookUp = lookUp;

            return config;
        }
Esempio n. 7
0
        /// <summary>
        /// Utility method to get the settings
        /// </summary>
        /// <param name="updateManager"></param>
        /// <returns></returns>
        public static UpdateManagerConfiguration GetSettings(IUpdateManager updateManager = null)
        {
            string location = Assembly.GetExecutingAssembly().Location;
            string filePath = Path.Combine(
                Path.GetDirectoryName(location),
                DEFAULT_CONFIG_FILE_S);
#if DEBUG
            //This code is just to create the default config file to
            //save the default settings, which later on can be modified
            //to re-direct it to other download target for testing.
            if (!File.Exists(filePath))
            {
                var config = new UpdateManagerConfiguration();
                config.Save(filePath, updateManager);
            }
#endif
            return File.Exists(filePath) ? Load(filePath, updateManager) : new UpdateManagerConfiguration();
        }
Esempio n. 8
0
        public void ConfigurationRedirection()
        {
            //Inject test config to UpdateManager instance, using reflection.
            var config = new UpdateManagerConfiguration()
            {
                DownloadSourcePath = DOWNLOAD_SOURCE_PATH_S,
                SignatureSourcePath = SIGNATURE_SOURCE_PATH_S
            };

            var um = new DynUpdateManager(config);
            Assert.IsNotNull(um);
        
            var updateRequest = new Mock<IAsynchronousRequest>();
            updateRequest.Setup(ur => ur.Data)
                .Returns(UpdateManagerTestHelpers.updateAvailableData);
            um.UpdateDataAvailable(updateRequest.Object);

            // Spoof a download completion by setting the downloaded update info to the update info
            um.DownloadedUpdateInfo = um.UpdateInfo;
            Assert.NotNull(um.UpdateInfo);
            Assert.AreEqual("9.9.9.0", um.AvailableVersion.ToString());
            Assert.AreEqual(DOWNLOAD_SOURCE_PATH_S, um.UpdateInfo.VersionInfoURL);
            Assert.AreEqual(
                SIGNATURE_SOURCE_PATH_S + @"DynamoInstall9.9.9.sig",
                um.UpdateInfo.SignatureURL);
        }
Esempio n. 9
0
 public void ConfigurationSerialization()
 {
     var config = new UpdateManagerConfiguration()
     {
         DownloadSourcePath = DOWNLOAD_SOURCE_PATH_S,
         SignatureSourcePath = SIGNATURE_SOURCE_PATH_S
     };
     
     //save to a temp file.
     var tempFile = Path.GetTempFileName();
     Assert.DoesNotThrow(() => config.Save(tempFile, null));
     
     //read from a temp file.
     UpdateManagerConfiguration savedConfig = null;
     Assert.DoesNotThrow(() => savedConfig = UpdateManagerConfiguration.Load(tempFile, null));
     
     //Compare parameters.
     Assert.IsNotNull(savedConfig);
     Assert.AreEqual(config.CheckNewerDailyBuild, savedConfig.CheckNewerDailyBuild);
     Assert.AreEqual(config.SignatureSourcePath, savedConfig.SignatureSourcePath);
     Assert.AreEqual(config.DownloadSourcePath, savedConfig.DownloadSourcePath);
     Assert.AreEqual(config.ForceUpdate, savedConfig.ForceUpdate);
 }