public void ShouldPickFirstRemoteInCaseNoOriginWasFound()
    {
        var repo        = SetupRepositoryWithRemote("some", inkscapeSSH);
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <GitlabLinkBuilder>();
    }
Exemplo n.º 2
0
    public void ShouldAzurePickFirstRemoteInCaseNoOriginWasFound()
    {
        var repo        = SetupRepositoryWithRemote("some", "[email protected]:v3/dosse/DosSE.ERP.Cloud/ERP.git");
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <AzureLinkBuilder>();
    }
Exemplo n.º 3
0
    public void ShouldCreateAnAzureUrlBuilderForHTTPSPushUrlsEvenWithoutGitSuffix()
    {
        var repo        = SetupRepositoryWithRemote("origin", "https://[email protected]/dosse/DosSE.ERP.Cloud/_git/ERP");
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <AzureLinkBuilder>();
    }
    public void ShouldPickFirstRemoteInCaseNoOriginWasFound()
    {
        var repo        = SetupRepositoryWithRemote("some", "[email protected]:versionize/versionize.git");
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <GithubLinkBuilder>();
    }
Exemplo n.º 5
0
    public void ShouldCreateAnAzureUrlBuilderForSSHPushUrls()
    {
        var repo        = SetupRepositoryWithRemote("origin", "[email protected]:v3/dosse/DosSE.ERP.Cloud/ERP.git");
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <AzureLinkBuilder>();
    }
Exemplo n.º 6
0
    public void ShouldCreateAComBitbucketUrlBuilderForSSHPushUrls()
    {
        var repo        = SetupRepositoryWithRemote("origin", sshComPushUrl);
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <BitbucketLinkBuilder>();
    }
    public void ShouldFallbackToNoopInCaseNoGitlabPushUrlWasDefined()
    {
        var repo        = SetupRepositoryWithRemote("origin", "https://hostmeister.com/versionize/versionize.git");
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <PlainLinkBuilder>();
    }
Exemplo n.º 8
0
    public void ShouldPickFirstRemoteInCaseNoOriginWasFound()
    {
        var repo        = SetupRepositoryWithRemote("some", sshOrgPushUrl);
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <BitbucketLinkBuilder>();
    }
Exemplo n.º 9
0
    public void ShouldCreateAnOrgBitbucketUrlBuilderForHTTPSPushUrls()
    {
        var repo        = SetupRepositoryWithRemote("origin", httpsOrgPushUrl);
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <BitbucketLinkBuilder>();
    }
    public void ShouldCreateAGithubUrlBuilderForHTTPSPushUrlsEvenWithoutGitSuffix()
    {
        var repo        = SetupRepositoryWithRemote("origin", "https://github.com/versionize/versionize");
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <GithubLinkBuilder>();
    }
    public void ShouldCreateAGitlabUrlBuilderForSSHPushUrls()
    {
        var repo        = SetupRepositoryWithRemote("origin", inkscapeSSH);
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <GitlabLinkBuilder>();
    }
    public void ShouldCreateAGithubUrlBuilderForSSHPushUrls()
    {
        var repo        = SetupRepositoryWithRemote("origin", "[email protected]:versionize/versionize.git");
        var linkBuilder = LinkBuilderFactory.CreateFor(repo);

        linkBuilder.ShouldBeAssignableTo <GithubLinkBuilder>();
    }
Exemplo n.º 13
0
        public void Initialize()
        {
            _authorizationProvider  = new Mock <IAuthorizationProvider>();
            _dependencyResolverMock = new Mock <IDependencyResolver>();
            _personProvider         = new Mock <IPersonProvider>();

            var linkBuilderFactory = new LinkBuilderFactory();

            _authorizationProvider.Setup(p => p.IsAuthorized(It.IsAny <MethodInfo>())).Returns(true);
            _dependencyResolverMock.Setup(p => p.GetService(It.IsAny <Type>())).Returns(_personProvider.Object);

            var idFromExpressionProcessor     = new IdFromExpressionProcessor(_dependencyResolverMock.Object);
            var argumentsDefinitionsProcessor = new ArgumentDefinitionsProcessor();
            var templateArgumentsProcessor    = new TemplateArgumentsProcessor();

            var configurationMock = new Mock <IHttpConfiguration>(MockBehavior.Strict);
            var properties        = new ConcurrentDictionary <object, object>();

            configurationMock.SetupGet(c => c.Properties).Returns(() => properties);

            Container   = HateoasContainerFactory.Create(configurationMock.Object);
            LinkFactory = new LinkFactory(
                linkBuilderFactory,
                _authorizationProvider.Object,
                idFromExpressionProcessor,
                argumentsDefinitionsProcessor,
                templateArgumentsProcessor);
            var linksForFuncProvider = new ConfigurationProviderGetLinksForFuncProvider(new InMemoryCache <int, MethodInfo>());

            ConfigurationProvider = new ConfigurationProvider(configurationMock.Object, LinkFactory, linksForFuncProvider, new InMemoryCache <Type, Func <ConfigurationProvider, object, IEnumerable <IHateoasLink> > >());

            Enumerable = new List <Person>
            {
                new Person()
                {
                    Id      = Guid.Parse("ae213c3e-9ce8-489f-a5ff-5422b55bba44"),
                    HouseId = Guid.Parse("a7a52c3d-a5ef-47ff-97db-176f4b2609e4"),
                },
                new Person()
                {
                    Id      = Guid.Parse("6153d85e-8233-4d9f-b583-a78d2ba8d3d1"),
                    HouseId = Guid.Parse("9042e54f-dee6-45c9-8d9e-048026f5d5fa"),
                },
            };

            // this link is added to check if it is ignored
            Container.Register <Person>("some-extra-link").Get <PersonController>();
            Container.Register <Car>("some-extra-link").Get <CarController>();
        }
Exemplo n.º 14
0
        public static void Startup <TRegistrationClass>(
            TRegistrationClass registrationClass,
            IHttpConfiguration configuration,
            IAuthorizationProvider authorizationProvider  = null,
            IDependencyResolver dependencyResolver        = null,
            IList <IMessageSerializer> messageSerializers = null)
            where TRegistrationClass : IHateoasRegistrationProfile
        {
            var linkBuilderFactory = new LinkBuilderFactory();

            // todo: this is not very clean; user dependencyresolver etc
            if (authorizationProvider == null)
            {
                var httpContextWrapper = new HttpContextWrapper(HttpContext.Current);
                authorizationProvider = new WebApiAuthorizationProvider(httpContextWrapper);
            }

            var idFromExpressionProcessor     = new IdFromExpressionProcessor(dependencyResolver);
            var argumentsDefinitionsProcessor = new ArgumentDefinitionsProcessor();
            var templateArgumentsProcessor    = new TemplateArgumentsProcessor();

            var linkFactory = new LinkFactory(
                linkBuilderFactory: linkBuilderFactory,
                authorizationProvider: authorizationProvider,
                idFromExpressionProcessor: idFromExpressionProcessor,
                argumentsDefinitionsProcessor: argumentsDefinitionsProcessor,
                templateArgumentsProcessor: templateArgumentsProcessor
                );

            var inMemoryGenericLinksForMethodsCache = new InMemoryCache <int, MethodInfo>();
            var linksForFuncProvider =
                new ConfigurationProviderGetLinksForFuncProvider(inMemoryGenericLinksForMethodsCache);

            var getLinksForMethodCache =
                new InMemoryCache <Type, Func <ConfigurationProvider, object, IEnumerable <IHateoasLink> > >();
            var configurationProvider = new ConfigurationProvider(configuration, linkFactory, linksForFuncProvider,
                                                                  getLinksForMethodCache);

            var responseProvider = new ResponseProvider(configurationProvider);
            var handler          = new HateoasHttpHandler(responseProvider, messageSerializers ?? new List <IMessageSerializer>());

            configuration.MessageHandlers.Add(handler);

            var container = HateoasContainerFactory.Create(configuration);

            registrationClass.Register(container);
        }
Exemplo n.º 15
0
        public void GetLinkBuilderShouldReturnNewLinkBuilderForEachCall()
        {
            // arrange
            var factory = new LinkBuilderFactory();

            // act & assert
            var linkBuilder1 = factory
                               .GetLinkBuilder(null)
                               .Should().NotBeNull()
                               .And.BeOfType <LinkBuilder>();

            factory
            .GetLinkBuilder(null)
            .Should().NotBeNull()
            .And.BeOfType <LinkBuilder>()
            .And.NotBe(linkBuilder1);
        }
Exemplo n.º 16
0
        public void BaseTestInitialize()
        {
            // registration
            _httpConfiguration         = new HttpConfiguration();
            _httpConfigurationWrapper  = new HttpConfigurationWrapper(_httpConfiguration);
            _authorizationProviderMock = new Mock <IAuthorizationProvider>(MockBehavior.Strict);
            _authorizationProviderMock.Setup(a => a.IsAuthorized(It.IsAny <MethodInfo>())).Returns(true);
            _dependencyResolver = new Mock <IDependencyResolver>(MockBehavior.Strict);
            RegistrationClass   = new TestRegistrationClass();

            // request & response
            Request = new HttpRequestMessage(HttpMethod.Get, "http://hateoas.net");
            Request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
            Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, _httpConfigurationWrapper.HttpConfiguration);
            Response = new HttpResponseMessage(HttpStatusCode.OK);

            // handling
            var idFromExpressionProcessor     = new IdFromExpressionProcessor(_dependencyResolver.Object);
            var argumentsDefinitionsProcessor = new ArgumentDefinitionsProcessor();
            var templateArgumentsProcessor    = new TemplateArgumentsProcessor();

            var inMemoryGenericLinksForMethodsCache = new InMemoryCache <int, MethodInfo>();

            _linksForFuncProvider = new ConfigurationProviderGetLinksForFuncProvider(inMemoryGenericLinksForMethodsCache);

            var linkBuilderFactory = new LinkBuilderFactory();

            _linkFactory = new LinkFactory(
                linkBuilderFactory: linkBuilderFactory,
                authorizationProvider: _authorizationProviderMock.Object,
                idFromExpressionProcessor: idFromExpressionProcessor,
                argumentsDefinitionsProcessor: argumentsDefinitionsProcessor,
                templateArgumentsProcessor: templateArgumentsProcessor
                );

            _getLinksForMethodCache = new InMemoryCache <Type, Func <ConfigurationProvider, object, IEnumerable <IHateoasLink> > >();
            _configurationProvider  = new ConfigurationProvider(_httpConfigurationWrapper, _linkFactory, _linksForFuncProvider, _getLinksForMethodCache);
            _responseProvider       = new ResponseProvider(_configurationProvider);
        }
Exemplo n.º 17
0
        public void Initialize()
        {
            _authorizationProvider  = new Mock <IAuthorizationProvider>();
            _dependencyResolverMock = new Mock <IDependencyResolver>();
            _personProvider         = new Mock <IPersonProvider>();

            var linkBuilderFactory = new LinkBuilderFactory();

            _authorizationProvider.Setup(p => p.IsAuthorized(It.IsAny <MethodInfo>())).Returns(true);
            _dependencyResolverMock.Setup(p => p.GetService(It.IsAny <Type>())).Returns(_personProvider.Object);

            var idFromExpressionProcessor     = new IdFromExpressionProcessor(_dependencyResolverMock.Object);
            var argumentsDefinitionsProcessor = new ArgumentDefinitionsProcessor();
            var templateArgumentsProcessor    = new TemplateArgumentsProcessor();

            var configurationMock = new Mock <IHttpConfiguration>(MockBehavior.Strict);
            var properties        = new ConcurrentDictionary <object, object>();

            configurationMock.SetupGet(c => c.Properties).Returns(() => properties);

            Container   = HateoasContainerFactory.Create(configurationMock.Object);
            LinkFactory = new LinkFactory(
                linkBuilderFactory,
                _authorizationProvider.Object,
                idFromExpressionProcessor,
                argumentsDefinitionsProcessor,
                templateArgumentsProcessor);
            var linksForFuncProvider = new ConfigurationProviderGetLinksForFuncProvider(new InMemoryCache <int, MethodInfo>());

            ConfigurationProvider = new ConfigurationProvider(configurationMock.Object, LinkFactory, linksForFuncProvider, new InMemoryCache <Type, Func <ConfigurationProvider, object, IEnumerable <IHateoasLink> > >());

            Entity = new Person()
            {
                Id      = Guid.Parse("ae213c3e-9ce8-489f-a5ff-5422b55bba44"),
                HouseId = Guid.Parse("a7a52c3d-a5ef-47ff-97db-176f4b2609e4"),
            };
        }
Exemplo n.º 18
0
    public SemanticVersion Versionize(VersionizeOptions options)
    {
        var workingDirectory = _directory.FullName;

        using var repo = new Repository(workingDirectory);

        var isDirty = repo.RetrieveStatus(new StatusOptions()).IsDirty;

        if (!options.SkipDirty && isDirty)
        {
            Exit($"Repository {workingDirectory} is dirty. Please commit your changes.", 1);
        }

        var projects = Projects.Discover(workingDirectory);

        if (projects.IsEmpty())
        {
            Exit($"Could not find any projects files in {workingDirectory} that have a <Version> defined in their csproj file.", 1);
        }

        if (projects.HasInconsistentVersioning())
        {
            Exit($"Some projects in {workingDirectory} have an inconsistent <Version> defined in their csproj file. Please update all versions to be consistent or remove the <Version> elements from projects that should not be versioned", 1);
        }

        Information($"Discovered {projects.GetProjectFiles().Count()} versionable projects");
        foreach (var project in projects.GetProjectFiles())
        {
            Information($"  * {project}");
        }

        var versionTag       = repo.SelectVersionTag(projects.Version);
        var isInitialRelease = versionTag == null;
        var commitsInVersion = repo.GetCommitsSinceLastVersion(versionTag);

        var conventionalCommits = ConventionalCommitParser.Parse(commitsInVersion);

        var versionIncrement = new VersionIncrementStrategy(conventionalCommits);

        var nextVersion = isInitialRelease ? projects.Version : versionIncrement.NextVersion(projects.Version, options.Prerelease);

        // For non initial releases: for insignificant commits such as chore increment the patch version if IgnoreInsignificantCommits is not set
        if (!isInitialRelease && nextVersion == projects.Version)
        {
            if (options.IgnoreInsignificantCommits || options.ExitInsignificantCommits)
            {
                var exitCode = options.ExitInsignificantCommits ? 1 : 0;
                Exit($"Version was not affected by commits since last release ({projects.Version})", exitCode);
            }
            else
            {
                nextVersion = nextVersion.IncrementPatchVersion();
            }
        }

        if (!string.IsNullOrWhiteSpace(options.ReleaseAs))
        {
            try
            {
                nextVersion = SemanticVersion.Parse(options.ReleaseAs);
            }
            catch (Exception)
            {
                Exit($"Could not parse the specified release version {options.ReleaseAs} as valid version", 1);
            }
        }

        if (nextVersion < projects.Version)
        {
            Exit($"Semantic versioning conflict: the next version {nextVersion} would be lower than the current version {projects.Version}. This can be caused by using a wrong pre-release label or release as version", 1);
        }

        if (!options.DryRun && !options.SkipCommit && repo.VersionTagsExists(nextVersion))
        {
            Exit($"Version {nextVersion} already exists. Please use a different version.", 1);
        }

        var versionTime = DateTimeOffset.Now;

        // Commit changelog and version source
        if (!options.DryRun && (nextVersion != projects.Version))
        {
            projects.WriteVersion(nextVersion);

            foreach (var projectFile in projects.GetProjectFiles())
            {
                Commands.Stage(repo, projectFile);
            }
        }

        Step($"bumping version from {projects.Version} to {nextVersion} in projects");

        var changelog            = ChangelogBuilder.CreateForPath(workingDirectory);
        var changelogLinkBuilder = LinkBuilderFactory.CreateFor(repo);

        if (options.DryRun)
        {
            string markdown = ChangelogBuilder.GenerateMarkdown(nextVersion, versionTime, changelogLinkBuilder, conventionalCommits, options.Changelog);
            DryRun(markdown.TrimEnd('\n'));
        }
        else
        {
            changelog.Write(nextVersion, versionTime, changelogLinkBuilder, conventionalCommits, options.Changelog);
        }

        Step("updated CHANGELOG.md");

        if (!options.DryRun && !options.SkipCommit)
        {
            if (!repo.IsConfiguredForCommits())
            {
                Exit(@"Warning: Git configuration is missing. Please configure git before running versionize:
git config --global user.name ""John Doe""
$ git config --global user.email [email protected]", 1);
            }

            Commands.Stage(repo, changelog.FilePath);

            foreach (var projectFile in projects.GetProjectFiles())
            {
                Commands.Stage(repo, projectFile);
            }

            var author    = repo.Config.BuildSignature(versionTime);
            var committer = author;

            var releaseCommitMessage = $"chore(release): {nextVersion} {options.CommitSuffix}".TrimEnd();
            var versionCommit        = repo.Commit(releaseCommitMessage, author, committer);
            Step("committed changes in projects and CHANGELOG.md");

            repo.Tags.Add($"v{nextVersion}", versionCommit, author, $"{nextVersion}");
            Step($"tagged release as {nextVersion}");

            Information("");
            Information("i Run `git push --follow-tags origin master` to push all changes including tags");
        }
        else if (options.SkipCommit)
        {
            Information("");
            Information($"i Commit and tagging of release was skipped. Tag this release as `v{nextVersion}` to make versionize detect the release");
        }

        return(nextVersion);
    }
        public LinkBuilderFactoryTests()
        {
            urlHelperMock = new Mock <IUrlHelper>();

            linkBuilderFactory = new LinkBuilderFactory(urlHelperMock.Object);
        }