Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="GitLabReference"/>
        /// </summary>
        /// <param name="project">The project the referenced item belong to.</param>
        /// <param name="type">The type of the referenced item.</param>
        /// <param name="id">The referenced item's id.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="id"/> is 0 or a negative number</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="project"/> is <c>null</c></exception>
        public GitLabReference(GitLabProjectInfo project, GitLabReferenceType type, int id)
        {
            if (id < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            Project = project ?? throw new ArgumentNullException(nameof(project));
            Type    = type;
            Id      = id;
        }
Ejemplo n.º 2
0
        private Task <Uri?> TryGetWebUriAsync(IGitLabClient gitlabClient, GitLabReferenceType type, string projectPath, int id)
        {
            switch (type)
            {
            case GitLabReferenceType.Issue:
                return(TryGetIssueWebUriAsync(gitlabClient, projectPath, id));

            case GitLabReferenceType.MergeRequest:
                return(TryGetMergeRequestWebUriAsync(gitlabClient, projectPath, id));

            case GitLabReferenceType.Milestone:
                return(TryGetMilestoneWebUriAsync(gitlabClient, projectPath, id));

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 3
0
            public void ToString_returns_expected_value(string @namespace, string project, GitLabReferenceType type, int id, string expected)
            {
                // ARRANGE
                var sut = new GitLabReference(new("example.com", @namespace, project), type, id);

                // ACT
                var actual = sut.ToString();

                // ASSERT
                Assert.Equal(expected, actual);
            }
Ejemplo n.º 4
0
            public void TryParse_returns_expected_reference(string input, string currentNamespace, string currentProject, string expectedNamespace, string expectedProject, GitLabReferenceType expectedType, int expectedId)
            {
                // ARRANGE

                // ACT
                var success = GitLabReference.TryParse(input, new("example.com", currentNamespace, currentProject), out var parsed);

                // ASSERT
                Assert.True(success);
                Assert.Equal("example.com", parsed !.Project.Host);
                Assert.Equal(expectedNamespace, parsed.Project.Namespace);
                Assert.Equal(expectedProject, parsed.Project.Project);
                Assert.Equal(expectedType, parsed.Type);
                Assert.Equal(expectedId, parsed.Id);
            }