Exemple #1
0
        public void performing_updates_uses_packager_on_n_packages_exactly_n_times(int times)
        {
            int n = times;
            IList <ModuleManifest> modulePackages = new List <ModuleManifest>();

            for (int i = 0; i < n; i++)
            {
                modulePackages.Add(new ModuleManifest()
                {
                    ModuleName = "Test" + i
                });
            }

            // provide the proper packages per modules
            ModulesRepository.Setup(x => x.GetModule(It.IsAny <string>()))
            .Returns <string>(name => new ModulePackage()
            {
                ModuleManifest = modulePackages
                                 .Where(x => x.ModuleName.Equals(name))
                                 .Select(x => x).Single()
            });

            NomadUpdater.PrepareUpdate(modulePackages);

            NomadUpdater.PerformUpdates(new CompositeModuleDiscovery());

            NomadUpdater.UpdateFinished.WaitOne();
            ModulePackager.Verify(x => x.PerformUpdates(PluginsDir, It.IsAny <ModulePackage>()),
                                  Times.Exactly(n),
                                  string.Format("One package should be invoked {0} times.", n));
        }
Exemple #2
0
        public void zip_packager_unzips_the_file_properly()
        {
            string zipFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"res\test.zip");

            var modulePackage = new ModulePackage
            {
                ModuleManifest =
                    new ModuleManifest(),
                ModuleZip =
                    File.ReadAllBytes(zipFile)
            };


            // get the zip packager
            IModulePackager packager = new ModulePackager();

            // set up directory
            string targetDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Updater\Zip\");

            if (Directory.Exists(targetDirectory))
            {
                Directory.Delete(targetDirectory, true);
            }

            Directory.CreateDirectory(targetDirectory);

            // perform test
            packager.PerformUpdates(targetDirectory, modulePackage);

            // assert test
            Assert.IsTrue(File.Exists(Path.Combine(targetDirectory, "readme")));
        }
Exemple #3
0
        public void zip_packager_unzips_the_file_properly()
        {
            string zipFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"res\test.zip");

            var modulePackage = new ModulePackage
                {
                    ModuleManifest =
                        new ModuleManifest(),
                    ModuleZip =
                        File.ReadAllBytes(zipFile)
                };

            // get the zip packager
            IModulePackager packager = new ModulePackager();

            // set up directory
            string targetDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,@"Updater\Zip\");
            if(Directory.Exists(targetDirectory))
                Directory.Delete(targetDirectory,true);

            Directory.CreateDirectory(targetDirectory);

            // perform test
            packager.PerformUpdates(targetDirectory,modulePackage);

            // assert test
            Assert.IsTrue(File.Exists(Path.Combine(targetDirectory, "readme")));
        }
Exemple #4
0
        public void performing_updates_has_information_about_failure_packager_throws()
        {
            ModulePackager.Setup(
                x => x.PerformUpdates(It.IsAny <String>(), It.IsAny <ModulePackage>()))
            .Throws(new Exception("Can not pacakge this"));

            var manifest = new ModuleManifest()
            {
                ModuleName = "AlaMaKota"
            };
            var moduleManifests = new List <ModuleManifest>
            {
                manifest,
            };

            ModulesRepository.Setup(x => x.GetModule(It.IsAny <string>()))
            .Returns(new ModulePackage()
            {
                ModuleManifest = manifest
            });

            // preapre stub module manifest
            NomadUpdater.PrepareUpdate(moduleManifests);

            ModulesRepository.Setup(x => x.GetModule(It.IsAny <string>()))
            .Returns(new ModulePackage()
            {
                ModuleManifest = moduleManifests[0]
            });

            NomadUpdater.PerformUpdates(new CompositeModuleDiscovery());

            // wait till end to get the information about failure
            NomadUpdater.UpdateFinished.WaitOne();
            Assert.AreEqual(UpdaterStatus.Invalid, NomadUpdater.Status);
        }