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)); }
public void performing_updates_has_information_about_failure_modules_operations_throws() { ModulesOperations.Setup(x => x.LoadModules(It.IsAny <IModuleDiscovery>())) .Throws(new Exception("Can not discovery moduels")); var moduleManifests = new List <ModuleManifest> { new ModuleManifest(), }; // 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); }
public void preparing_updates_calls_proper_subsystems_publishes_msg_at_the_end() { // return the same - might stop working if some of the code is gonna be put to verify download }; var modulePacakge = new ModulePackage { ModuleManifest = _moduleManifest }; ModulesRepository.Setup(x => x.GetModule(It.Is <string>(y => y == _moduleName))) .Returns(modulePacakge) .Verifiable("This package should be downloaded"); EventAggregator.Setup(x => x.Publish(It.IsAny <NomadUpdatesReadyMessage>())) .Callback <NomadUpdatesReadyMessage>(msg => { Assert.IsFalse(msg.Error); Assert.AreEqual(1, msg.ModuleManifests.Count); Assert.AreSame(modulePacakge.ModuleManifest, msg.ModuleManifests[0]); }) .Returns(null) .Verifiable("This message should be published upon exit"); NomadUpdater.PrepareUpdate(new List <ModuleManifest>() { _moduleManifest }); EventAggregator.Verify(); ModulesRepository.Verify(); Assert.AreEqual(UpdaterStatus.Prepared, NomadUpdater.Status); }
public void preparing_updates_invoked_with_null_raises_message() { EventAggregator.Setup(x => x.Publish(It.IsAny <NomadUpdatesReadyMessage>())) .Callback <NomadUpdatesReadyMessage>(msg => Assert.IsTrue(msg.Error)) .Returns(null) .Verifiable("The message should be published"); NomadUpdater.PrepareUpdate(null); EventAggregator.Verify(); Assert.AreEqual(UpdaterStatus.Invalid, NomadUpdater.Status); }
public void module_repository_throws_exception_while_preparing_updates_changed_to_message() { ModulesRepository.Setup(x => x.GetModule(It.IsAny <string>())) .Throws(new Exception("Module Cannot be selected")); EventAggregator.Setup(x => x.Publish(It.IsAny <NomadUpdatesReadyMessage>())) .Callback <NomadUpdatesReadyMessage>(msg => Assert.IsTrue(msg.Error)) .Returns(null) .Verifiable("The message should be published"); NomadUpdater.PrepareUpdate(new List <ModuleManifest>() { _moduleManifest }); EventAggregator.Verify(); Assert.AreEqual(UpdaterStatus.Invalid, NomadUpdater.Status); }
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); }
public void packages_gotten_from_repository_have_nulls() { EventAggregator.Setup(x => x.Publish(It.IsAny <NomadUpdatesReadyMessage>())) .Callback <NomadUpdatesReadyMessage>(msg => Assert.IsTrue(msg.Error)) .Returns(null) .Verifiable("The message should be published"); var modulePackages = new List <ModuleManifest> { new ModuleManifest() { ModuleName = "Test" }, }; // provide wrong packages in repository ModulesRepository.Setup(x => x.GetModule(It.IsAny <string>())).Returns( new ModulePackage()); NomadUpdater.PrepareUpdate(modulePackages); EventAggregator.Verify(); Assert.AreEqual(UpdaterStatus.Invalid, NomadUpdater.Status); }