public void Test_JTokenErrors_Functional()
        {
            var errors = new JTokenErrors();

            Assert.False(errors.HasAny);

            errors.Add("error text 1");
            Assert.True(errors.HasAny);

            string text1 = errors.Compose();

            Assert.Equal("1. error text 1", text1);

            errors.Add("error text 2");
            Assert.True(errors.HasAny);

            string text2 = errors.Compose();

            Assert.Equal($"1. error text 1{Environment.NewLine}2. error text 2", text2);
        }
示例#2
0
        internal static ProjectInfo TryRead(JToken project, JTokenErrors errors)
        {
            if (errors == null)
            {
                throw new ArgumentNullException(nameof(errors));
            }

            ProjectInfo result = null;

            if (project != null)
            {
                string projectName       = project.RequireString(GitlabKeys.Name, errors);
                string projectUrl        = project.RequireString(GitlabKeys.WebUrl, errors);
                string pathWithNamespace = project.RequireString(GitlabKeys.PathWithNamespace, errors);

                if (!errors.HasAny)
                {
                    string server = null;
                    if (projectUrl.EndsWith(pathWithNamespace))
                    {
                        server = projectUrl.Substring(0, projectUrl.Length - pathWithNamespace.Length);
                    }
                    else
                    {
                        errors.Add(project.Parent == null
                                       ? $"Can not retrieve the server url out of \"{GitlabKeys.WebUrl}\""
                                       : $"Can not retrieve the server url out of \"{project.Parent.Path}.{GitlabKeys.WebUrl}\"");
                    }

                    if (!errors.HasAny)
                    {
                        result = new ProjectInfo
                        {
                            Name   = projectName,
                            Url    = projectUrl,
                            Server = server
                        };
                    }
                }
            }

            return(result);
        }