public void GenerateFileContents_prerelease_tag() { // arrange var repository = Mock.Create <LibGit2Sharp.IRepository>(); Mock.Arrange(() => repository.Head.Commits).Returns(MockCommitLog(new[] { "third", "second", "first", "zero" })); Mock.Arrange(() => repository.Tags).Returns(MockTags(new Dictionary <String, String> { { "zero", "v1.2" }, { "second", "v1.3-RC" } })); var configuration = new VersionConfiguration(true, true, true, true, true, true); var expectedContents = @"// This is a generated file. Do not commit it to version control and do not modify it. using System.Reflection; [assembly: AssemblyVersion(""1.2.3.0"")] [assembly: AssemblyFileVersion(""1.2.3.0"")] [assembly: AssemblyInformationalVersion(""1.3.0.0-RC-001"")] ".Replace("\r\n", "\n") .Replace("\n", Environment.NewLine); // act var actualContents = GitVersion.GenerateFileContents(configuration, repository); // assert Assert.Equal(expectedContents, actualContents); }
public VersionConfigurationApplicator(Versions versions, VersionConfiguration configuration) { Contract.Requires(versions != null); Contract.Requires(configuration != null); _versions = versions; _configuration = configuration; }
public void Equals_DifferInLabel_ReturnsTrue(VersionConfiguration sut, VersionConfiguration other) { // Arrange / Act var result = sut.Equals(other); // Assert result.Should().BeFalse(); }
public LocationsModel(VersionConfiguration versionConfig) { this.IsRelevant = !versionConfig.ExistingVersionInstalled; this.Header = "Locations"; this.Refresh(); this._refreshing = true; //when configurelocations is checked and place paths in samefolder is not set, set configureall locations to true var prop = this.WhenAny( vm => vm.ConfigureLocations, vm => vm.PlaceWritableLocationsInSamePath, vm => vm.InstallDir, (configureLocations, samePath, i) => configureLocations.GetValue() && !samePath.GetValue() ) .ToProperty(this, vm => vm.ConfigureAllLocations, out configureAllLocations); this.WhenAny( vm => vm.LogsDirectory, (c) => { var v = c.GetValue(); if (Path.IsPathRooted(v)) { return(Path.Combine(c.GetValue(), "kibana.log")); } return(null); }) .ToProperty(this, vm => vm.KibanaLog, out kibanaLog); this.ThrownExceptions.Subscribe(e => { }); //If install, config, logs or data dir are set force ConfigureLocations to true this.WhenAny( vm => vm.InstallDir, vm => vm.LogsDirectory, (i, l) => !this._refreshing ) .Subscribe(x => { if (x) { this.ConfigureLocations = true; } }); this.WhenAny( vm => vm.ConfigureLocations, (c) => !this._refreshing && !c.Value ) .Subscribe(x => { if (x) { this.Refresh(); } }); this._refreshing = false; }
public NoticeModel( VersionConfiguration versionConfig, IServiceStateProvider serviceStateProvider, LocationsModel locationsModel, ServiceModel serviceModel ) { this.IsRelevant = versionConfig.ExistingVersionInstalled; this.LocationsModel = locationsModel; this.ServiceModel = serviceModel; this.Header = "Notice"; this.ExistingVersion = versionConfig.UpgradeFromVersion; this.CurrentVersion = versionConfig.CurrentVersion; this.ReadMoreOnUpgrades = ReactiveCommand.Create(); this.ReadMoreOnXPackOpening = ReactiveCommand.Create(); this._serviceStateProvider = serviceStateProvider; this.Refresh(); if (!string.IsNullOrWhiteSpace(this.CurrentVersion?.Prerelease)) { if (versionConfig.ExistingVersionInstalled) { this.UpgradeTextHeader = TextResources.NoticeModel_ToPrerelease_Header; this.UpgradeText = TextResources.NoticeModel_ToPrerelease; } else { this.UpgradeTextHeader = TextResources.NoticeModel_Prerelease_Header; this.UpgradeText = TextResources.NoticeModel_Prerelease; } this.IsRelevant = true; //show prerelease notice always } else if (!string.IsNullOrWhiteSpace(this.ExistingVersion?.Prerelease)) { this.UpgradeTextHeader = TextResources.NoticeModel_FromPrerelease_Header; this.UpgradeText = TextResources.NoticeModel_FromPrerelease; this.IsRelevant = true; //show prerelease notice always } else { var v = Enum.GetName(typeof(VersionChange), versionConfig.VersionChange); var d = Enum.GetName(typeof(InstallationDirection), versionConfig.InstallationDirection); var prefix = nameof(NoticeModel) + "_" + v + d; this.UpgradeTextHeader = TextResources.ResourceManager.GetString(prefix + "_Header"); this.UpgradeText = TextResources.ResourceManager.GetString(prefix); } if (!string.IsNullOrWhiteSpace(this.UpgradeTextHeader)) { this.UpgradeTextHeader = string.Format(this.UpgradeTextHeader, versionConfig.UpgradeFromVersion, versionConfig.CurrentVersion); } this.ShowOpeningXPackBanner = this.ExistingVersion < XPackModel.XPackInstalledByDefaultVersion; this.ShowUpgradeDocumentationLink = versionConfig.VersionChange == VersionChange.Major || versionConfig.VersionChange == VersionChange.Minor; this.ExistingVersionInstalled = versionConfig.ExistingVersionInstalled; }
public LocationsModel( ElasticsearchEnvironmentConfiguration elasticsearchEnvironmentConfiguration, ElasticsearchYamlConfiguration yamlConfiguration, VersionConfiguration versionConfig, IFileSystem fileSystem) { this.IsRelevant = !versionConfig.ExistingVersionInstalled; this.Header = "Locations"; this._elasticsearchEnvironmentConfiguration = elasticsearchEnvironmentConfiguration; this._yamlConfiguration = yamlConfiguration; this.CurrentVersion = versionConfig.CurrentVersion.ToString(); this.ExistingVersion = versionConfig.UpgradeFromVersion?.ToString(); this.FileSystem = fileSystem; this.Refresh(); this._refreshing = true; this.WhenAny( vm => vm.LogsDirectory, (c) => { var v = c.GetValue(); return(this.FileSystem.Path.IsPathRooted(v) ? this.FileSystem.Path.Combine(v, "elasticsearch.log") : null); }) .ToProperty(this, vm => vm.ElasticsearchLog, out elasticsearchLog); this.ThrownExceptions.Subscribe(e => { }); //If install, config, logs or data dir are set force ConfigureLocations to true this.WhenAny( vm => vm.InstallDir, vm => vm.ConfigDirectory, vm => vm.LogsDirectory, vm => vm.DataDirectory, (i, c, l, d) => !this._refreshing ) .Subscribe(x => { if (x) { this.ConfigureLocations = true; } }); this.WhenAny( vm => vm.ConfigureLocations, (c) => !this._refreshing && !c.Value ) .Subscribe(x => { if (x) { this.Refresh(); } }); this._refreshing = false; }
/// <summary> /// Initializes a new instance of the <see cref="VersionContext"/> class. /// </summary> /// <param name="environment">The <see cref="IVersionEnvironment"/> for the invocation.</param> /// <param name="configuration">The <see cref="VersionConfiguration"/> for the current branch.</param> /// <param name="result">The <see cref="VersionResult"/> to collect final version details.</param> public VersionContext( IVersionEnvironment environment, VersionConfiguration configuration, VersionResult result) { Environment = environment ?? throw new ArgumentNullException(nameof(environment)); Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); Result = result ?? throw new ArgumentNullException(nameof(result)); }
public void Equals_GivenNull_ReturnsFalse() { // Arrange var sut = new VersionConfiguration(); // Act var result = sut.Equals(null); // Assert result.Should().BeFalse(); }
public NoticeModel( VersionConfiguration versionConfig, IServiceStateProvider serviceStateProvider, LocationsModel locationsModel, ServiceModel serviceModel ) { this.IsRelevant = versionConfig.ExistingVersionInstalled; this.LocationsModel = locationsModel; this.ServiceModel = serviceModel; this.Header = "Notice"; this.ExistingVersion = versionConfig.ExistingVersion; this.CurrentVersion = versionConfig.CurrentVersion; this.ReadMoreOnUpgrades = ReactiveCommand.Create(); var e = versionConfig.ExistingVersion; var c = versionConfig.CurrentVersion; if (!string.IsNullOrWhiteSpace(c?.Prerelease)) { this.UpgradeTextHeader = TextResources.NoticeModel_ToPrerelease_Header; this.UpgradeText = TextResources.NoticeModel_ToPrerelease; this.IsRelevant = true; //show prerelease notice always } else if (!string.IsNullOrWhiteSpace(e?.Prerelease)) { this.UpgradeTextHeader = TextResources.NoticeModel_FromPrerelease_Header; this.UpgradeText = TextResources.NoticeModel_FromPrerelease; this.IsRelevant = true; //show prerelease notice always } else { var v = Enum.GetName(typeof(VersionChange), versionConfig.VersionChange); var d = Enum.GetName(typeof(InstallationDirection), versionConfig.InstallationDirection); var prefix = nameof(NoticeModel) + "_" + v + d; this.UpgradeTextHeader = TextResources.ResourceManager.GetString(prefix + "_Header"); this.UpgradeText = TextResources.ResourceManager.GetString(prefix); } // TODO: We should show the upgrade notice, even for a patch upgrade. if (this.IsRelevant && versionConfig.VersionChange == VersionChange.Patch && versionConfig.InstallationDirection == InstallationDirection.Up) { this.IsRelevant = false; } this.ExistingVersionInstalled = versionConfig.ExistingVersionInstalled; this.InstalledAsService = serviceStateProvider.SeesService; this.Refresh(); }
public void Ctor_SetsDefaults() { // Arrange / Act var sut = new VersionConfiguration(); // Assert AssertUtils.AssertGetSetProperty(sut, nameof(sut.Version), x => x.Should().BeEmpty(), "test"); AssertUtils.AssertGetSetProperty(sut, nameof(sut.OffSet), x => x.Should().Be(0), 50); AssertUtils.AssertGetSetProperty(sut, nameof(sut.Label), x => x.Should().BeEmpty(), new List <string> { "test" }); AssertUtils.AssertGetSetProperty(sut, nameof(sut.Metadata), x => x.Should().BeEmpty(), new List <string> { "test" }); }
public override Boolean Execute() { Contract.Assume(Log != null); var repositorySearchPathStart = Path.GetDirectoryName(OutputFilePath); var repositoryPath = LibGit2Sharp.Repository.Discover(repositorySearchPathStart); var repository = (repositoryPath != null) ? new LibGit2Sharp.Repository(repositoryPath) : null; using (repository) { var configuration = new VersionConfiguration(IncludeAssemblyVersion, IncludeAssemblyFileVersion, IncludeAssemblyInformationalVersion, !OnlyMajorAndMinorInAssemblyVersion, !OnlyMajorAndMinorInAssemblyFileVersion, !OnlyMajorAndMinorInAssemblyInformationalVersion); var fileContents = GitVersion.GenerateFileContents(configuration, repository); File.WriteAllText(OutputFilePath, fileContents); } return true; }
public void GenerateFileContents_when_default_mock() { // arrange var repository = Mock.Create <LibGit2Sharp.IRepository>(); var configuration = new VersionConfiguration(true, true, true, true, true, true); var expectedContents = @"// This is a generated file. Do not commit it to version control and do not modify it. using System.Reflection; [assembly: AssemblyVersion(""0.0.0.0"")] [assembly: AssemblyFileVersion(""0.0.0.0"")] [assembly: AssemblyInformationalVersion(""0.0.0.0"")] ".Replace("\r\n", "\n") .Replace("\n", Environment.NewLine); // act var actualContents = GitVersion.GenerateFileContents(configuration, repository); // assert Assert.Equal(expectedContents, actualContents); }
public void info_patch() { // arrange var version = new Version(1, 2, 3, 4, "alpha"); var fileVersion = new Version(3, 4, 5, 6, "beta"); var infoVersion = new Version(5, 6, 7, 8, "delta"); var versions = new Versions(version, fileVersion, infoVersion); var configuration = new VersionConfiguration(true, true, true, false, false, true); var versionConfigurationApplicator = new VersionConfigurationApplicator(versions, configuration); // act var cleanedVersion = versionConfigurationApplicator.Version; var cleanedFileVersion = versionConfigurationApplicator.FileVersion; var cleanedInfoVersion = versionConfigurationApplicator.InfoVersion; // assert Assert.Equal("1.2.0.0-alpha", cleanedVersion); Assert.Equal("3.4.0.0-beta", cleanedFileVersion); Assert.Equal("5.6.7.8-delta", cleanedInfoVersion); }
public void file_patch() { // arrange var version = new Version(1, 2, 3, 4, "alpha"); var fileVersion = new Version(3, 4, 5, 6, "beta"); var infoVersion = new Version(5, 6, 7, 8, "delta"); var versions = new Versions(version, fileVersion, infoVersion); var configuration = new VersionConfiguration(true, true, true, false, true, false); var versionConfigurationApplicator = new VersionConfigurationApplicator(versions, configuration); // act var cleanedVersion = versionConfigurationApplicator.Version; var cleanedFileVersion = versionConfigurationApplicator.FileVersion; var cleanedInfoVersion = versionConfigurationApplicator.InfoVersion; // assert Assert.Equal("1.2.0.0-alpha", cleanedVersion); Assert.Equal("3.4.5.6-beta", cleanedFileVersion); Assert.Equal("5.6.0.0-delta", cleanedInfoVersion); }
public XPackModel( VersionConfiguration versionConfig, IObservable <bool> xPackEnabled, IObservable <bool> canAutomaticallySetupUsers) { xPackEnabled.Subscribe(t => { this.IsRelevant = t; }); canAutomaticallySetupUsers.Subscribe(b => { this.CanAutomaticallySetupUsers = b; this.SkipSettingPasswords = !b; }); this.Header = "X-Pack"; this.CurrentVersion = versionConfig.CurrentVersion; this.OpenLicensesAndSubscriptions = ReactiveCommand.Create(); this.RegisterBasicLicense = ReactiveCommand.Create(); this.OpenManualUserConfiguration = ReactiveCommand.Create(); this.Refresh(); }
public ServiceModel(IServiceStateProvider serviceStateProvider, VersionConfiguration versionConfig) { this._existingVersionInstalled = versionConfig.ExistingVersionInstalled; this.PreviouslyInstalledAsAService = serviceStateProvider.SeesService; this.IsRelevant = !this._existingVersionInstalled || (this._existingVersionInstalled && !this.PreviouslyInstalledAsAService); this.Header = "Service"; this.Refresh(); this.WhenAny(vm => vm.User, vm => vm.Password, (u, p) => string.IsNullOrEmpty(u.Value) && string.IsNullOrEmpty(p.Value)) .Subscribe(b => { if (b) { return; } this.UseExistingUser = true; this.UseLocalSystem = false; this.UseNetworkService = false; }); this.WhenAny(vm => vm.InstallAsService, i => i.Value) .Subscribe(b => { if (!b) { _internalRefresh = true; this.Refresh(); } }); this.ValidateCredentials = ReactiveCommand.CreateAsyncTask(async _ => { this.ValidatingCredentials = true; var valid = await Task.Run(() => this.Validator.ValidateCredentials(this.User, this.Password)); this.ManualValidationPassed = valid; this.ValidatingCredentials = false; }); }
public XPackModel(VersionConfiguration versionConfig, IObservable <bool> canAutomaticallySetupUsers, IObservable <bool> upgradeFromXPackPlugin) { upgradeFromXPackPlugin.Subscribe(b => { //show x-pack tab when we're upgrading from a version lower than `6.3.0` and the x-pack plugin was not installed. //otherwise assume x-pack is installed and only show the tab on new installs this.IsRelevant = (versionConfig.InstallationDirection == Up && versionConfig.UpgradeFromVersion < XPackInstalledByDefaultVersion && !b) || versionConfig.InstallationDirection == None; }); canAutomaticallySetupUsers.Subscribe(b => { this.CanAutomaticallySetupUsers = b; this.SkipSettingPasswords = !b; }); this.Header = "X-Pack"; this.CurrentVersion = versionConfig.CurrentVersion; this.OpenLicensesAndSubscriptions = ReactiveCommand.Create(); this.OpenManualUserConfiguration = ReactiveCommand.Create(); this.Refresh(); }
public KibanaInstallationModel( IWixStateProvider wixStateProvider, IServiceStateProvider serviceStateProvider, IPluginStateProvider pluginStateProvider, IKibanaEnvironmentStateProvider environmentStateProvider, ISession session, string[] args ) : base(wixStateProvider, session, args) { var versionConfig = new VersionConfiguration(wixStateProvider, this.Session.IsInstalled); this.KibanaEnvironmentState = environmentStateProvider; this.LocationsModel = new LocationsModel(versionConfig); this.NoticeModel = new NoticeModel(versionConfig, serviceStateProvider, this.LocationsModel); this.ServiceModel = new ServiceModel(serviceStateProvider, versionConfig); this.ConfigurationModel = new ConfigurationModel(); this.ConnectingModel = new ConnectingModel(); var pluginDependencies = this.WhenAnyValue( vm => vm.NoticeModel.AlreadyInstalled, vm => vm.LocationsModel.InstallDir, vm => vm.LocationsModel.ConfigDirectory ); this.PluginsModel = new PluginsModel(pluginStateProvider, pluginDependencies); var isUpgrade = versionConfig.InstallationDirection == InstallationDirection.Up; var observeHost = this.WhenAnyValue(x => x.ConfigurationModel.HostName, x => x.ConfigurationModel.HttpPort, (h, p) => $"http://{(string.IsNullOrWhiteSpace(h) ? "localhost" : h)}:{p}"); var observeInstallationLog = this.WhenAnyValue(vm => vm.MsiLogFileLocation); var observeKibanaLog = this.WhenAnyValue(vm => vm.LocationsModel.KibanaLog); var observeInstallXPack = this.PluginsModel.AvailablePlugins.ItemChanged .Where(x => x.PropertyName == nameof(Plugin.Selected) && x.Sender.PluginType == PluginType.XPack) .Select(x => x.Sender.Selected); this.ClosingModel = new ClosingModel(wixStateProvider.CurrentVersion, isUpgrade, observeHost, observeInstallationLog, observeKibanaLog, observeInstallXPack, serviceStateProvider); this.AllSteps.AddRange(new List <IStep> { this.NoticeModel, this.LocationsModel, this.ServiceModel, this.ConfigurationModel, this.ConnectingModel, this.PluginsModel, this.ClosingModel }); var observeValidationChanges = this.WhenAny( vm => vm.NoticeModel.ValidationFailures, vm => vm.LocationsModel.ValidationFailures, vm => vm.PluginsModel.ValidationFailures, vm => vm.ServiceModel.ValidationFailures, vm => vm.ConfigurationModel.ValidationFailures, vm => vm.ConnectingModel.ValidationFailures, vm => vm.ClosingModel.ValidationFailures, vm => vm.TabSelectedIndex, (notice, locations, plugins, service, config, connecting, closing, index) => { var firstInvalidScreen = this.Steps.FirstOrDefault(s => !s.IsValid) ?? this.ClosingModel; return(firstInvalidScreen); }); observeValidationChanges .Subscribe(selected => { var step = this.Steps[this.TabSelectedIndex]; var failures = step.ValidationFailures; this.FirstInvalidStepValidationFailures = selected.ValidationFailures; }); this.WhenAny( vm => vm.NoticeModel.IsValid, vm => vm.LocationsModel.IsValid, vm => vm.PluginsModel.IsValid, vm => vm.ServiceModel.IsValid, vm => vm.ConfigurationModel.IsValid, vm => vm.ConnectingModel.IsValid, vm => vm.ClosingModel.IsValid, (notice, locations, plugins, service, config, connecting, closing) => { var firstInvalidScreen = this.Steps.Select((s, i) => new { s, i }).FirstOrDefault(s => !s.s.IsValid); return(firstInvalidScreen?.i ?? (this.Steps.Count - 1)); }) .Subscribe(selected => { this.TabSelectionMax = selected; //if one of the steps prior to the current selection is invalid jump back if (this.TabSelectedIndex > this.TabSelectionMax) { this.TabSelectedIndex = this.TabSelectionMax; } this.FirstInvalidStepValidationFailures = this.ActiveStep.ValidationFailures; }); this.Install = ReactiveCommand.CreateAsyncTask(observeValidationChanges.Select(s => s.IsValid), _ => { this.TabSelectedIndex += 1; return(this.InstallUITask()); }); this.Install.Subscribe(installationObservable => { installationObservable.Subscribe(installed => { this.ClosingModel.Installed = installed; }); }); this.Refresh(); //validate the first stab explicitly on constructing this //main viewmodel. WPF triggers a validation already this.ParsedArguments = new KibanaArgumentParser( this.AllSteps.Cast <IValidatableReactiveObject>().Concat(new[] { this }).ToList(), args); this.ActiveStep.Validate(); }
public ElasticsearchInstallationModel( IWixStateProvider wixStateProvider, JavaConfiguration javaConfiguration, ElasticsearchEnvironmentConfiguration elasticsearchEnvironmentConfiguration, IServiceStateProvider serviceStateProvider, IPluginStateProvider pluginStateProvider, ElasticsearchYamlConfiguration yamlConfiguration, LocalJvmOptionsConfiguration localJvmOptions, ISession session, string[] args ) : base(wixStateProvider, session, args) { this.JavaConfiguration = javaConfiguration ?? throw new ArgumentNullException(nameof(javaConfiguration)); this.ElasticsearchEnvironmentConfiguration = elasticsearchEnvironmentConfiguration; this._yamlConfiguration = yamlConfiguration; var versionConfig = new VersionConfiguration(wixStateProvider); this.SameVersionAlreadyInstalled = versionConfig.SameVersionAlreadyInstalled; this.HigherVersionAlreadyInstalled = versionConfig.HigherVersionAlreadyInstalled; this.LocationsModel = new LocationsModel(elasticsearchEnvironmentConfiguration, yamlConfiguration, versionConfig); this.NoticeModel = new NoticeModel(versionConfig, serviceStateProvider, this.LocationsModel); this.ServiceModel = new ServiceModel(serviceStateProvider, versionConfig); this.ConfigurationModel = new ConfigurationModel(yamlConfiguration, localJvmOptions); var pluginDependencies = this.WhenAnyValue( vm => vm.ConfigurationModel.IngestNode, vm => vm.NoticeModel.AlreadyInstalled, vm => vm.LocationsModel.InstallDir, vm => vm.LocationsModel.ConfigDirectory ); this.PluginsModel = new PluginsModel(pluginStateProvider, pluginDependencies); var isUpgrade = versionConfig.InstallationDirection == InstallationDirection.Up; var observeHost = this.WhenAnyValue(vm => vm.ConfigurationModel.NetworkHost, vm => vm.ConfigurationModel.HttpPort, (h, p) => $"http://{(string.IsNullOrWhiteSpace(h) ? "localhost" : h)}:{p}"); var observeInstallationLog = this.WhenAnyValue(vm => vm.MsiLogFileLocation); var observeElasticsearchLog = this.WhenAnyValue(vm => vm.LocationsModel.ElasticsearchLog); var observeInstallXPack = this.PluginsModel.AvailablePlugins.ItemChanged .Where(x => x.PropertyName == nameof(Plugin.Selected) && x.Sender.PluginType == PluginType.XPack) .Select(x => x.Sender.Selected); this.ClosingModel = new ClosingModel(wixStateProvider.CurrentVersion, isUpgrade, observeHost, observeInstallationLog, observeElasticsearchLog, observeInstallXPack, serviceStateProvider); this.AllSteps = new ReactiveList <IStep> { this.NoticeModel, this.LocationsModel, this.ServiceModel, this.ConfigurationModel, this.PluginsModel, this.ClosingModel }; this.Steps = this.AllSteps.CreateDerivedCollection(x => x, x => x.IsRelevant); var observeValidationChanges = this.WhenAny( vm => vm.NoticeModel.ValidationFailures, vm => vm.LocationsModel.ValidationFailures, vm => vm.ConfigurationModel.ValidationFailures, vm => vm.PluginsModel.ValidationFailures, vm => vm.ServiceModel.ValidationFailures, vm => vm.ClosingModel.ValidationFailures, vm => vm.TabSelectedIndex, (welcome, locations, configuration, plugins, service, install, index) => { var firstInvalidScreen = this.Steps.FirstOrDefault(s => !s.IsValid) ?? this.ClosingModel; return(firstInvalidScreen); }); observeValidationChanges .Subscribe(selected => { var step = this.Steps[this.TabSelectedIndex]; var failures = step.ValidationFailures; this.CurrentStepValidationFailures = selected.ValidationFailures; }); this.WhenAny( vm => vm.NoticeModel.IsValid, vm => vm.LocationsModel.IsValid, vm => vm.ConfigurationModel.IsValid, vm => vm.PluginsModel.IsValid, vm => vm.ServiceModel.IsValid, vm => vm.ClosingModel.IsValid, (welcome, locations, configuration, plugins, service, install) => { var firstInvalidScreen = this.Steps.Select((s, i) => new { s, i }).FirstOrDefault(s => !s.s.IsValid); return(firstInvalidScreen?.i ?? (this.Steps.Count - 1)); }) .Subscribe(selected => { this.TabSelectionMax = selected; //if one of the steps prior to the current selection is invalid jump back if (this.TabSelectedIndex > this.TabSelectionMax) { this.TabSelectedIndex = this.TabSelectionMax; } this.CurrentStepValidationFailures = this.ActiveStep.ValidationFailures; }); this.Install = ReactiveCommand.CreateAsyncTask(observeValidationChanges.Select(s => s.IsValid), _ => { this.TabSelectedIndex += 1; return(this.InstallUITask()); }); this.Install.Subscribe(installationObservable => { installationObservable.Subscribe(installed => this.ClosingModel.Installed = installed); }); this.Refresh(); //validate the first stab explicitly on constructing this //main viewmodel. WPF triggers a validation already this.ParsedArguments = new ElasticsearchArgumentParser( this.AllSteps.Cast <IValidatableReactiveObject>().Concat(new[] { this }).ToList(), args); this.ActiveStep.Validate(); }
public VersionContextFixture() { _environment = Substitute.For <IVersionEnvironment>(); _config = new VersionConfiguration(); _result = new VersionResult(); }
public InstallationModel( IWixStateProvider wixStateProvider, JavaConfiguration javaConfiguration, IElasticsearchEnvironmentStateProvider environmentStateProvider, IServiceStateProvider serviceStateProvider, IPluginStateProvider pluginStateProvider, ElasticsearchYamlConfiguration yamlConfiguration, LocalJvmOptionsConfiguration localJvmOptions, ISession session, string[] args ) { this.Session = session; if (wixStateProvider == null) { throw new ArgumentNullException(nameof(wixStateProvider)); } if (javaConfiguration == null) { throw new ArgumentNullException(nameof(javaConfiguration)); } this._wixStateProvider = wixStateProvider; this.JavaConfiguration = javaConfiguration; this.ElasticsearchEnvironmentState = environmentStateProvider; this._yamlConfiguration = yamlConfiguration; var versionConfig = new VersionConfiguration(wixStateProvider); this.SameVersionAlreadyInstalled = versionConfig.SameVersionAlreadyInstalled; this.HigherVersionAlreadyInstalled = versionConfig.HigherVersionAlreadyInstalled; this.LocationsModel = new LocationsModel(environmentStateProvider, yamlConfiguration, versionConfig); this.NoticeModel = new NoticeModel(versionConfig, serviceStateProvider, this.LocationsModel); this.ServiceModel = new ServiceModel(serviceStateProvider, versionConfig); this.ConfigurationModel = new ConfigurationModel(yamlConfiguration, localJvmOptions); var pluginDependencies = this.WhenAnyValue( vm => vm.ConfigurationModel.IngestNode, vm => vm.NoticeModel.AlreadyInstalled, vm => vm.LocationsModel.InstallDir, vm => vm.LocationsModel.ConfigDirectory ); this.PluginsModel = new PluginsModel(pluginStateProvider, pluginDependencies); var observeHost = this.WhenAnyValue(vm => vm.ConfigurationModel.NetworkHost, vm => vm.ConfigurationModel.HttpPort, (h, p) => $"http://{(string.IsNullOrWhiteSpace(h) ? "localhost" : h)}:{p}"); var observeLog = this.WhenAnyValue(vm => vm.MsiLogFileLocation); var observeElasticsearchLog = this.WhenAnyValue(vm => vm.LocationsModel.ElasticsearchLog); var isUpgrade = versionConfig.InstallationDirection == InstallationDirection.Up; this.ClosingModel = new ClosingModel(wixStateProvider.CurrentVersion, isUpgrade, observeHost, observeLog, observeElasticsearchLog, serviceStateProvider); this.AllSteps = new ReactiveList <IStep> { this.NoticeModel, this.LocationsModel, this.ServiceModel, this.ConfigurationModel, this.PluginsModel, this.ClosingModel }; this.Steps = this.AllSteps.CreateDerivedCollection(x => x, x => x.IsRelevant); this.NextButtonText = TextResources.SetupView_NextText; var canMoveForwards = this.WhenAny(vm => vm.TabSelectedIndex, vm => vm.TabSelectionMax, (i, max) => i.GetValue() < max.GetValue()); this.Next = ReactiveCommand.Create(canMoveForwards); this.Next.Subscribe(i => { this.TabSelectedIndex = Math.Min(this.Steps.Count - 1, this.TabSelectedIndex + 1); }); var canMoveBackwards = this.WhenAny(vm => vm.TabSelectedIndex, (i) => i.GetValue() > 0); this.Back = ReactiveCommand.Create(canMoveBackwards); this.Back.Subscribe(i => { this.TabSelectedIndex = Math.Max(0, this.TabSelectedIndex - 1); }); this.Help = ReactiveCommand.Create(); this.ShowLicenseBlurb = ReactiveCommand.Create(); this.ShowCurrentStepErrors = ReactiveCommand.Create(); this.RefreshCurrentStep = ReactiveCommand.Create(); this.RefreshCurrentStep.Subscribe(x => { this.Steps[this.TabSelectedIndex].Refresh(); }); this.Exit = ReactiveCommand.Create(); var observeValidationChanges = this.WhenAny( vm => vm.NoticeModel.ValidationFailures, vm => vm.LocationsModel.ValidationFailures, vm => vm.ConfigurationModel.ValidationFailures, vm => vm.PluginsModel.ValidationFailures, vm => vm.ServiceModel.ValidationFailures, vm => vm.ClosingModel.ValidationFailures, vm => vm.TabSelectedIndex, (welcome, locations, configuration, plugins, service, install, index) => { var firstInvalidScreen = this.Steps.FirstOrDefault(s => !s.IsValid) ?? this.ClosingModel; return(firstInvalidScreen); }); var canInstall = observeValidationChanges.Select(s => s.IsValid); this.Install = ReactiveCommand.CreateAsyncTask(canInstall, _ => { this.TabSelectedIndex += 1; return(this.InstallUITask()); }); this.Install.Subscribe(installationObservable => { installationObservable.Subscribe(installed => { this.ClosingModel.Installed = installed; }); }); this.WhenAny(vm => vm.TabSelectedIndex, v => v.GetValue()) .Subscribe(i => { var c = this.Steps.Count; if (i == (c - 1)) { this.NextButtonText = TextResources.SetupView_ExitText; } else if (i == (c - 2)) { this.NextButtonText = TextResources.SetupView_InstallText; } else { this.NextButtonText = TextResources.SetupView_NextText; } }); observeValidationChanges .Subscribe(selected => { var step = this.Steps[this.TabSelectedIndex]; var failures = step.ValidationFailures; this.CurrentStepValidationFailures = selected.ValidationFailures; }); this.WhenAny( vm => vm.NoticeModel.IsValid, vm => vm.LocationsModel.IsValid, vm => vm.ConfigurationModel.IsValid, vm => vm.PluginsModel.IsValid, vm => vm.ServiceModel.IsValid, vm => vm.ClosingModel.IsValid, (welcome, locations, configuration, plugins, service, install) => { var firstInvalidScreen = this.Steps.Select((s, i) => new { s, i }).FirstOrDefault(s => !s.s.IsValid); return(firstInvalidScreen?.i ?? (this.Steps.Count - 1)); }) .Subscribe(selected => { this.TabSelectionMax = selected; //if one of the steps prior to the current selection is invalid jump back if (this.TabSelectedIndex > this.TabSelectionMax) { this.TabSelectedIndex = this.TabSelectionMax; } this.CurrentStepValidationFailures = this.ActiveStep.ValidationFailures; }); this.WhenAnyValue(view => view.ValidationFailures) .Subscribe(failures => { this.PrequisiteFailures = (failures ?? Enumerable.Empty <ValidationFailure>()) .Where(v => _prerequisiteProperties.Contains(v.PropertyName)) .ToList(); }); this.Refresh(); //validate the first stab explicitly on constructing this //main viewmodel. WPF triggers a validation already this.ParsedArguments = new InstallationModelArgumentParser(this.AllSteps.Cast <IValidatableReactiveObject>().Concat(new[] { this }).ToList(), args); this.ActiveStep.Validate(); }
public void GenerateFileContents_prerelease_tag() { // arrange var repository = Mock.Create<LibGit2Sharp.IRepository>(); Mock.Arrange(() => repository.Head.Commits).Returns(MockCommitLog(new[] { "third", "second", "first", "zero" })); Mock.Arrange(() => repository.Tags).Returns(MockTags(new Dictionary<String, String> { { "zero", "v1.2" }, { "second", "v1.3-RC" } })); var configuration = new VersionConfiguration(true, true, true, true, true, true); var expectedContents = @"// This is a generated file. Do not commit it to version control and do not modify it. using System.Reflection; [assembly: AssemblyVersion(""1.2.3.0"")] [assembly: AssemblyFileVersion(""1.2.3.0"")] [assembly: AssemblyInformationalVersion(""1.3.0.0-RC-001"")] ".Replace("\r\n", "\n") .Replace("\n", Environment.NewLine); // act var actualContents = GitVersion.GenerateFileContents(configuration, repository); // assert Assert.Equal(expectedContents, actualContents); }
public void GenerateFileContents_when_default_mock() { // arrange var repository = Mock.Create<LibGit2Sharp.IRepository>(); var configuration = new VersionConfiguration(true, true, true, true, true, true); var expectedContents = @"// This is a generated file. Do not commit it to version control and do not modify it. using System.Reflection; [assembly: AssemblyVersion(""0.0.0.0"")] [assembly: AssemblyFileVersion(""0.0.0.0"")] [assembly: AssemblyInformationalVersion(""0.0.0.0"")] ".Replace("\r\n", "\n") .Replace("\n", Environment.NewLine); // act var actualContents = GitVersion.GenerateFileContents(configuration, repository); // assert Assert.Equal(expectedContents, actualContents); }
public LocationsModel( ElasticsearchEnvironmentConfiguration elasticsearchEnvironmentConfiguration, ElasticsearchYamlConfiguration yamlConfiguration, VersionConfiguration versionConfig) { this.IsRelevant = !versionConfig.ExistingVersionInstalled; this.Header = "Locations"; this._elasticsearchEnvironmentConfiguration = elasticsearchEnvironmentConfiguration; this._yamlConfiguration = yamlConfiguration; this.Refresh(); this._refreshing = true; //when configurelocations is checked and place paths in samefolder is not set, set configureall locations to true var prop = this.WhenAny( vm => vm.ConfigureLocations, vm => vm.PlaceWritableLocationsInSamePath, vm => vm.InstallDir, (configureLocations, samePath, i) => configureLocations.GetValue() && !samePath.GetValue() ) .ToProperty(this, vm => vm.ConfigureAllLocations, out configureAllLocations); this.WhenAny( vm => vm.LogsDirectory, (c) => { var v = c.GetValue(); return(Path.IsPathRooted(v) ? Path.Combine(v, "elasticsearch.log") : null); }) .ToProperty(this, vm => vm.ElasticsearchLog, out elasticsearchLog); this.ThrownExceptions.Subscribe(e => { }); //If install, config, logs or data dir are set force ConfigureLocations to true this.WhenAny( vm => vm.InstallDir, vm => vm.ConfigDirectory, vm => vm.LogsDirectory, vm => vm.DataDirectory, (i, c, l, d) => !this._refreshing ) .Subscribe(x => { if (x) { this.ConfigureLocations = true; } }); this.WhenAny( vm => vm.ConfigureLocations, (c) => !this._refreshing && !c.Value ) .Subscribe(x => { if (x) { this.Refresh(); } }); this._refreshing = false; }
public ElasticsearchInstallationModel( IWixStateProvider wixStateProvider, JavaConfiguration javaConfiguration, ElasticsearchEnvironmentConfiguration elasticsearchEnvironmentConfiguration, IServiceStateProvider serviceStateProvider, IPluginStateProvider pluginStateProvider, ElasticsearchYamlConfiguration yamlConfiguration, LocalJvmOptionsConfiguration localJvmOptions, TempDirectoryConfiguration tempDirectoryConfiguration, IFileSystem fileSystem, ISession session, string[] args) : base(wixStateProvider, session, args) { this.JavaConfiguration = javaConfiguration ?? throw new ArgumentNullException(nameof(javaConfiguration)); this.ElasticsearchEnvironmentConfiguration = elasticsearchEnvironmentConfiguration; this.TempDirectoryConfiguration = tempDirectoryConfiguration; this._yamlConfiguration = yamlConfiguration; var versionConfig = new VersionConfiguration(wixStateProvider, this.Session.IsInstalled); this.SameVersionAlreadyInstalled = versionConfig.SameVersionAlreadyInstalled; this.UnInstalling = this.Session.IsUninstalling; this.InstallationInProgress = this._wixStateProvider.InstallationInProgress; this.Installing = this.Session.IsInstalling; this.Installed = this.Session.IsInstalled; this.Upgrading = this.Session.IsUpgrading; this.HigherVersionAlreadyInstalled = versionConfig.HigherVersionAlreadyInstalled; this.LocationsModel = new LocationsModel(elasticsearchEnvironmentConfiguration, yamlConfiguration, versionConfig, fileSystem); this.ServiceModel = new ServiceModel(serviceStateProvider, versionConfig); this.NoticeModel = new NoticeModel(versionConfig, serviceStateProvider, this.LocationsModel, this.ServiceModel); this.ConfigurationModel = new ConfigurationModel(yamlConfiguration, localJvmOptions); var pluginDependencies = this.WhenAnyValue( vm => vm.NoticeModel.ExistingVersionInstalled, vm => vm.LocationsModel.PreviousInstallationDirectory, vm => vm.LocationsModel.ConfigDirectory ); this.PluginsModel = new PluginsModel(pluginStateProvider, versionConfig.CurrentVersion, pluginDependencies); var upgradeFromXPackPlugin = this.WhenAnyValue(vm => vm.PluginsModel.PreviousInstallationHasXPack); var canAutomaticallySetup = this.WhenAnyValue(vm => vm.ServiceModel.StartAfterInstall, vm => vm.ServiceModel.InstallAsService) .Select(t => t.Item1 && t.Item2); this.XPackModel = new XPackModel(versionConfig, canAutomaticallySetup, upgradeFromXPackPlugin); var isUpgrade = versionConfig.InstallationDirection == InstallationDirection.Up; var observeHost = this.WhenAnyValue(vm => vm.ConfigurationModel.NetworkHost, vm => vm.ConfigurationModel.HttpPort, (h, p) => $"http://{(string.IsNullOrWhiteSpace(h) ? "localhost" : h)}:{p}"); var observeInstallationLog = this.WhenAnyValue(vm => vm.MsiLogFileLocation); var observeElasticsearchLog = this.WhenAnyValue(vm => vm.LocationsModel.ElasticsearchLog); this.ClosingModel = new ClosingModel(wixStateProvider.CurrentVersion, isUpgrade, observeHost, observeInstallationLog, observeElasticsearchLog, serviceStateProvider); this.AllSteps.AddRange(new List <IStep> { this.NoticeModel, this.LocationsModel, this.ServiceModel, this.ConfigurationModel, this.PluginsModel, this.XPackModel, this.ClosingModel }); this.AllSteps.ChangeTrackingEnabled = true; var observeValidationChanges = this.WhenAny( vm => vm.NoticeModel.ValidationFailures, vm => vm.LocationsModel.ValidationFailures, vm => vm.ConfigurationModel.ValidationFailures, vm => vm.PluginsModel.ValidationFailures, vm => vm.XPackModel.ValidationFailures, vm => vm.ServiceModel.ValidationFailures, vm => vm.ClosingModel.ValidationFailures, vm => vm.TabSelectedIndex, (welcome, locations, configuration, plugins, xpack, service, install, index) => { var firstInvalidScreen = this.Steps.FirstOrDefault(s => !s.IsValid) ?? this.ClosingModel; return(firstInvalidScreen); }); observeValidationChanges .Subscribe(firstInvalidStep => { this.TabFirstInvalidIndex = this.Steps .Select((s, i) => new { s, i = (int?)i }) .Where(t => !t.s.IsValid) .Select(t => t.i) .FirstOrDefault(); this.FirstInvalidStepValidationFailures = firstInvalidStep.ValidationFailures; }); this.WhenAny( vm => vm.NoticeModel.IsValid, vm => vm.LocationsModel.IsValid, vm => vm.ConfigurationModel.IsValid, vm => vm.PluginsModel.IsValid, vm => vm.XPackModel.IsValid, vm => vm.ServiceModel.IsValid, vm => vm.ClosingModel.IsValid, (welcome, locations, configuration, plugins, xpack, service, install) => { var firstInvalidScreen = this.Steps.Select((s, i) => new { s, i }).FirstOrDefault(s => !s.s.IsValid); return(firstInvalidScreen?.i ?? (this.Steps.Count - 1)); }) .Subscribe(selected => { this.TabSelectionMax = selected; //if one of the steps prior to the current selection is invalid jump back if (this.TabSelectedIndex > this.TabSelectionMax) { this.TabSelectedIndex = this.TabSelectionMax; } this.FirstInvalidStepValidationFailures = this.ActiveStep.ValidationFailures; }); this.Steps.Changed.Subscribe(e => { var firstInvalidScreen = this.Steps.Select((s, i) => new { s, i }).FirstOrDefault(s => !s.s.IsValid); var selectedTabIndex = firstInvalidScreen?.i ?? (this.Steps.Count - 1); this.TabSelectionMax = selectedTabIndex; //if one of the steps prior to the current selection is invalid jump back if (this.TabSelectedIndex > this.TabSelectionMax) { this.TabSelectedIndex = this.TabSelectionMax; } this.FirstInvalidStepValidationFailures = this.ActiveStep.ValidationFailures; }); this.Install = ReactiveCommand.CreateAsyncTask(observeValidationChanges.Select(s => s.IsValid), _ => { this.TabSelectedIndex += 1; return(this.InstallUITask()); }); this.Install.Subscribe(installationObservable => { installationObservable.Subscribe(installed => this.ClosingModel.Installed = installed); }); this.Refresh(); //validate the first stab explicitly on constructing this //main viewmodel. WPF triggers a validation already this.ParsedArguments = new ElasticsearchArgumentParser( this.AllSteps.Cast <IValidatableReactiveObject>().Concat(new[] { this }).ToList(), args); this.ActiveStep.Validate(); }