public void Apply_LabelParts_NonRelease_Is_Formatted(
            string[] parts,
            string version,
            int height,
            string expectedPart)
        {
            // Arrange
            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Configuration = Utils.GetConfiguration(version, label: parts),
                    Result        = Utils.GetVersionResult(height, false)
                };
                context.Result.Version = context.Configuration.Version;

                var divider      = parts.Length > 0 ? '.' : '-';
                var shaSub       = context.Result.Sha.Substring(0, 7);
                var fullExpected = $"{expectedPart}{divider}c{shaSub}";

                // Act
                _sut.Apply(context);

                // Assert
                context.Result.Formats.Should().ContainKey("Semver2");
                context.Result.Formats["Semver2"].Should().Be(fullExpected);
            }
        }
        /// <inheritdoc/>
        public VersionResult GetResult()
        {
            // Fetch repository configuration
            var repoConfig          = GetRespositoryConfiguration();
            var canonicalBranchName = _environment.CanonicalBranchName ?? _repo.Head.CanonicalName;

            // Compose base result data
            var result = new VersionResult
            {
                CanonicalBranchName = canonicalBranchName,
                BranchName          = _environment.BranchName ?? _repo.Head.FriendlyName,
                Sha = _repo.Head.Tip.Sha,

                // Value returned from repository has trailing slash so need to get parent twice.
                RepositoryPath = Directory.GetParent(_repo.Info.Path).Parent.FullName,
                IsRelease      = repoConfig.Branches.Release.Any(x => Regex.IsMatch(canonicalBranchName, x))
            };

            // Build context for further processing
            var branchConfig = GetBranchConfiguration(repoConfig, result.CanonicalBranchName);
            var context      = new VersionContext(_environment, branchConfig, result);

            // Update height based on context
            SetHeight(context);

            // Evaluate given processors
            foreach (var processor in _processors)
            {
                processor.Process(context);
            }

            return(context.Result);
        }
        public void Apply_Malformed_Json_At_Commit_Throws()
        {
            using (var fixture = new SimpleVersionRepositoryFixture())
            {
                // Arrange
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();

                // Write the version file (with parsing errors)
                var file = Path.Combine(fixture.RepositoryPath, Constants.VersionFileName);
                using (var writer = File.AppendText(file))
                {
                    writer.WriteLine("This will not parse");
                    writer.Flush();
                }

                fixture.Repository.Index.Add(Constants.VersionFileName);
                fixture.Repository.Index.Write();
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();

                var context = new VersionContext(fixture.Repository);

                // Act
                Action action = () => _sut.Apply(context);

                // Assert
                action.Should().Throw <InvalidOperationException>()
                .WithMessage($"Could not read '{Constants.VersionFileName}', has it been committed?");
            }
        }
Пример #4
0
        public void Apply_NotAzure_DoesNotApply()
        {
            // Arrange
            _env.GetVariable("TF_BUILD").Returns("False");
            var expectedBranchName          = "BranchName";
            var expectedCanonicalBranchName = "CanonicalBranchName";

            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Result =
                    {
                        BranchName          = expectedBranchName,
                        CanonicalBranchName = expectedCanonicalBranchName
                    }
                };

                // Act
                _sut.Apply(context);

                // Assert
                context.Result.BranchName.Should().Be(expectedBranchName);
                context.Result.CanonicalBranchName.Should().Be(expectedCanonicalBranchName);
            }
        }
        public void Apply_ValidVersions_SetsMembers(
            string version,
            string expectedVersion,
            int major,
            int minor,
            int patch,
            int revision)
        {
            // Arrange
            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Configuration =
                    {
                        Version = version
                    }
                };

                // Act
                _sut.Apply(context);

                // Assert
                context.Result.Version.Should().Be(expectedVersion);
                context.Result.Major.Should().Be(major);
                context.Result.Minor.Should().Be(minor);
                context.Result.Patch.Should().Be(patch);
                context.Result.Revision.Should().Be(revision);
            }
        }
        public void Apply_Feature_Branch_Changes_Version_Resets_On_Merge()
        {
            using (var fixture = new SimpleVersionRepositoryFixture())
            {
                // Arrange
                var config = fixture.GetConfig();

                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();

                fixture.BranchTo("feature/other");
                fixture.MakeACommit();

                config.Version = "0.1.1";
                fixture.SetConfig(config);

                fixture.MakeACommit();
                fixture.MakeACommit();

                fixture.Checkout("master");
                fixture.MergeNoFF("feature/other");

                var context = new VersionContext(fixture.Repository);

                // Act
                _sut.Apply(context);

                // Assert
                context.Result.Height.Should().Be(1);
            }
        }
        public void Apply_Feature_Branch_No_Change_Increments_Merge_Once()
        {
            using (var fixture = new SimpleVersionRepositoryFixture())
            {
                // Arrange
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();

                fixture.BranchTo("feature/other");
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();

                fixture.Checkout("master");
                fixture.MergeNoFF("feature/other");

                var context = new VersionContext(fixture.Repository);

                // Act
                _sut.Apply(context);

                context.Result.Height.Should().Be(6);
            }
        }
        public void Apply_MetadataParts_Release_Is_Formatted(
            string[] parts,
            string version,
            int height)
        {
            // Arrange
            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Configuration = Utils.GetConfiguration(version, meta: parts),
                    Result        = Utils.GetVersionResult(height)
                };
                context.Result.Version = context.Configuration.Version;

                string expected;
                if (parts.Length > 0)
                {
                    expected = $"{version}+{string.Join(".", parts)}";
                }
                else
                {
                    expected = $"{version}";
                }

                // Act
                _sut.Apply(context);

                // Assert
                context.Result.Formats.Should().ContainKey("Semver2");
                context.Result.Formats["Semver2"].Should().Be(expected);
            }
        }
        public void OneTimeSetUp()
        {
            MockLogger = new Mock <ILogger>();
            MockLogger.Setup(m => m.LogRecord(It.IsAny <string>())).Callback <string>((message) => _lastMessageFromLog = message);

            CurrentProductRepository = new PostgreSQLProductRepository(MockLogger.Object);

            _database = new VersionContext();
        }
Пример #10
0
        public void Ctor_ValidParameters_SetsEnvironment()
        {
            // Arrange / Act
            var sut = new VersionContext(_environment, _config, _result);

            // Assert
            sut.Environment.Should().BeSameAs(_environment);
            sut.Configuration.Should().BeSameAs(_config);
            sut.Result.Should().BeSameAs(_result);
        }
        public void Apply_Returns_Input(VersionContext context, IEnumerable <string> input)
        {
            // Arrange
            var sut = new BranchNameSuffixTokenRule();

            // Act
            var result = sut.Apply(context, input);

            // Assert
            result.Should().BeSameAs(input);
        }
        public void GetResult_BranchOverride_AppliesOverride()
        {
            // Arrange
            var expectedLabel = new List <string> {
                "{branchName}"
            };
            var expectedMeta = new List <string> {
                "meta"
            };

            var config = new RepositoryConfiguration
            {
                Version  = "0.1.0",
                Branches =
                {
                    Overrides        =
                    {
                        new BranchOverrideConfiguration
                        {
                            Match    = "feature/other",
                            Label    = expectedLabel,
                            Metadata = expectedMeta
                        }
                    }
                }
            };

            using var fixture = new SimpleVersionRepositoryFixture(config, _serializer);

            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            fixture.BranchTo("feature/other");
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            // Use a processor to capture the configuration during processing.
            var            processor = Substitute.For <IVersionProcessor>();
            VersionContext context   = null;

            processor.When(x => x.Process(Arg.Any <VersionContext>()))
            .Do(call => context = call.Arg <VersionContext>());

            var sut = new GitVersionRepository(fixture.RepositoryPath, _environment, _serializer, new[] { processor });

            // Act
            var result = sut.GetResult();

            context.Configuration.Label.Should().BeEquivalentTo(expectedLabel, options => options.WithStrictOrdering());
            context.Configuration.Metadata.Should().BeEquivalentTo(expectedMeta, options => options.WithStrictOrdering());
        }
        public void Apply_First_Commit_Height_Is_One()
        {
            using (var fixture = new SimpleVersionRepositoryFixture())
            {
                // Arrange
                var context = new VersionContext(fixture.Repository);

                // Act
                _sut.Apply(context);

                // Assert
                context.Result.Height.Should().Be(1);
            }
        }
Пример #14
0
        internal virtual void VerifyContext()
        {
            VersionContext versionContext          = VersionContextSupplier.VersionContext;
            long           lastClosedTransactionId = versionContext.LastClosedTransactionId();

            if (lastClosedTransactionId == long.MaxValue)
            {
                return;
            }
            if (IsPotentiallyReadingDirtyData(lastClosedTransactionId))
            {
                versionContext.MarkAsDirty();
            }
        }
Пример #15
0
 public VersionModel GetComputerByName(string ComputerName)
 {
     try
     {
         using (var ctx = new VersionContext())
         {
             return(ctx.VersionModels.First(vm => vm.ComputerName == ComputerName));
         }
     }
     catch
     {
         return(null);
     }
 }
Пример #16
0
        public void Ctor_WithEmptyRepo_SetsProperties()
        {
            using (var fixture = new EmptyRepositoryFixture())
            {
                // Arrange / Act
                var sut = new VersionContext(fixture.Repository);

                // Assert
                sut.Repository.Should().Be(fixture.Repository);
                sut.Configuration.Should().NotBeNull();
                sut.Result.BranchName.Should().Be(fixture.Repository.Head.FriendlyName);
                sut.Result.CanonicalBranchName.Should().Be(fixture.Repository.Head.CanonicalName);
                sut.Result.Sha.Should().BeNull();
            }
        }
Пример #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static <Key> boolean performLookup(ReadableState<Key> store, org.neo4j.io.pagecache.tracing.cursor.context.VersionContext versionContext, java.util.concurrent.ConcurrentMap<Key,ChangeEntry> changes, Key key, ValueSink sink) throws java.io.IOException
        private static bool PerformLookup <Key>(ReadableState <Key> store, VersionContext versionContext, ConcurrentMap <Key, ChangeEntry> changes, Key key, ValueSink sink)
        {
            ChangeEntry change = changes.get(key);

            if (change != null)
            {
                if (change.Version > versionContext.LastClosedTransactionId())
                {
                    versionContext.MarkAsDirty();
                }
                sink.Value(new BigEndianByteArrayBuffer(change.Data));
                return(true);
            }
            return(store.Lookup(key, sink));
        }
        public void Apply_NoCommits_ShouldThrow()
        {
            using (var fixture = new EmptyRepositoryFixture())
            {
                // Arrange
                var context = new VersionContext(fixture.Repository);

                // Act
                Action action = () => _sut.Apply(context);

                // Assert
                action.Should().Throw <InvalidOperationException>()
                .WithMessage($"Could not read '{Constants.VersionFileName}', has it been committed?");
            }
        }
        public void Apply_BranchOverride_AppliesOverride()
        {
            // Arrange
            var expectedLabel = new List <string> {
                "{branchName}"
            };
            var expectedMeta = new List <string> {
                "meta"
            };

            var config = new Configuration
            {
                Version  = "0.1.0",
                Branches =
                {
                    Overrides        =
                    {
                        new BranchConfiguration
                        {
                            Match    = "feature/other",
                            Label    = expectedLabel,
                            Metadata = expectedMeta
                        }
                    }
                }
            };

            using (var fixture = new SimpleVersionRepositoryFixture(config))
            {
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();

                fixture.BranchTo("feature/other");
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();

                var context = new VersionContext(fixture.Repository);

                // Act
                _sut.Apply(context);

                context.Configuration.Label.Should().BeEquivalentTo(expectedLabel, options => options.WithStrictOrdering());
                context.Configuration.Metadata.Should().BeEquivalentTo(expectedMeta, options => options.WithStrictOrdering());
            }
        }
Пример #20
0
        public VersionContext GetVersionContext()
        {
            if (versionContext == null)
            {
                versionContext = new VersionContext();

                versionContext.Assembly             = GetVersionFromFileVersionInfo(GetAssemblyVersion());
                versionContext.Assembly.Description = GetAssemblyDescription();

                versionContext.Bridge = GetVersionFromFileVersionInfo(GetBridgeAssemblyVersion());

                versionContext.Compiler = GetVersionFromFileVersionInfo(GetCompilerVersion());
            }

            return(versionContext);
        }
Пример #21
0
        public VersionContext GetVersionContext()
        {
            if (_versionContext == null)
            {
                _versionContext = new VersionContext();

                _versionContext.Assembly             = GetVersionFromFileVersionInfo(GetAssemblyVersion());
                _versionContext.Assembly.Description = GetAssemblyDescription();

                _versionContext.H5 = GetVersionFromFileVersionInfo(GetH5AssemblyVersion());

                _versionContext.Compiler = GetVersionFromFileVersionInfo(GetCompilerVersion());
            }

            return(_versionContext);
        }
Пример #22
0
        public void Resolve_ReplacesToken_IfNeeded(string input, string expected)
        {
            // Arrange
            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Result = Utils.GetVersionResult(10)
                };

                // Act
                var result = _sut.Resolve(context, input);

                // Assert
                result.Should().Be(expected);
            }
        }
Пример #23
0
        public void Apply_AppendsToken_IfNeeded(bool isRelease, IEnumerable <string> input, IEnumerable <string> expected)
        {
            // Arrange
            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Configuration = Utils.GetConfiguration("1.2.3"),
                    Result        = Utils.GetVersionResult(10, isRelease)
                };

                // Act
                var result = _sut.Apply(context, input);

                // Assert
                result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering());
            }
        }
        public void Apply_Single_Branch_Increments_Each_Commit()
        {
            using (var fixture = new SimpleVersionRepositoryFixture())
            {
                // Arrange
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();
                fixture.MakeACommit();

                var context = new VersionContext(fixture.Repository);

                // Act
                _sut.Apply(context);

                // Assert
                context.Result.Height.Should().Be(5);
            }
        }
Пример #25
0
        public void Resolve_ReplacesToken_IfNeeded(string input, int id, string expected)
        {
            // Arrange
            using (var fixture = new EmptyRepositoryFixture())
            {
                var contextResult = Utils.GetVersionResult(10);
                contextResult.CanonicalBranchName = $"refs/pull/{id}/merge";

                var context = new VersionContext(fixture.Repository)
                {
                    Result = contextResult
                };

                // Act
                var result = _sut.Resolve(context, input);

                // Assert
                result.Should().Be(expected);
            }
        }
Пример #26
0
        public void Apply_ReturnsInput()
        {
            // Arrange
            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Configuration = Utils.GetConfiguration("1.2.3"),
                    Result        = Utils.GetVersionResult(10)
                };

                var input = new[] { "this", "will", "not", "change", "{pr}" };

                // Act
                var result = _sut.Apply(context, input);

                // Assert
                result.Should().BeEquivalentTo(input, options => options.WithStrictOrdering());
            }
        }
        private static VersionContext MatchedContext(SchemaVersion version)
        {
            var context = new VersionContext
            {
                Group = new VersionGroup($"{version.Revision}"), Map = new Dictionary <string, Version>()
            };

            context.Map.Add(version.Data.Name, new Version {
                Major = version.Fingerprint, Minor = 0
            });

            foreach (var entry in version.Data.GetMap())
            {
                context.Map.Add(entry.Value.Name, new Version {
                    Major = ValueHash.ComputeHash(entry.Value), Minor = 0
                });
            }

            context.Identifiers = new string[0];
            return(context);
        }
        public void Apply_InvalidVersion_Throws(string version)
        {
            // Arrange
            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Configuration =
                    {
                        Version = version
                    }
                };

                // Act
                Action action = () => _sut.Apply(context);

                // Asset
                action.Should().Throw <InvalidOperationException>()
                .WithMessage($"Version '{context.Configuration.Version}' is not in a valid format");
            }
        }
Пример #29
0
        public void Resolve_ReplacesToken_IfNeeded(bool usePadding, int height, string input, string expected)
        {
            // Arrange
            var sut = new HeightTokenRule(usePadding);

            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Result =
                    {
                        Height = height
                    }
                };

                // Act
                var result = sut.Resolve(context, input);

                // Assert
                result.Should().Be(expected);
            }
        }
Пример #30
0
        public void Apply_Appends_IfRequired(string version, IEnumerable <string> input, IEnumerable <string> expected)
        {
            // Arrange
            var sut = new HeightTokenRule();

            using (var fixture = new EmptyRepositoryFixture())
            {
                var context = new VersionContext(fixture.Repository)
                {
                    Configuration =
                    {
                        Version = version
                    }
                };

                // Act
                var result = sut.Apply(context, input);

                // Assert
                result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering());
            }
        }
	public VersionContext version() {
		VersionContext _localctx = new VersionContext(Context, State);
		EnterRule(_localctx, 14, RULE_version);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 840; k_version();
			State = 845;
			ErrorHandler.Sync(this);
			_la = TokenStream.La(1);
			while (_la==SCOL) {
				{
				{
				State = 841; Match(SCOL);
				State = 842; other_param();
				}
				}
				State = 847;
				ErrorHandler.Sync(this);
				_la = TokenStream.La(1);
			}
			State = 848; Match(COL);
			State = 849; vervalue();
			State = 850; Match(CRLF);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}