Пример #1
0
 public void ParseName_Invalid(string templateText, string name)
 {
     var template = new PathTemplate(templateText);
     Assert.Throws<FormatException>(() => template.ParseName(name));
     ResourceName result;
     Assert.False(template.TryParseName(name, out result));
     Assert.Null(result);
 }
Пример #2
0
        public void ParseName_Invalid(string templateText, string name)
        {
            var template = new PathTemplate(templateText);

            Assert.Throws <FormatException>(() => template.ParseName(name));
            TemplatedResourceName result;

            Assert.False(template.TryParseName(name, out result));
            Assert.Null(result);
        }
Пример #3
0
        /// <summary>
        /// Tries to parse the given instance resource name in string form into a new
        /// <see cref="InstanceName"/> instance.
        /// </summary>
        /// <remarks>
        /// This method still throws <see cref="ArgumentNullException"/> if <paramref name="instanceName"/> is null,
        /// as this would usually indicate a programming error rather than a data error.
        /// </remarks>
        /// <param name="instanceName">The instance resource name in string form. Must not be <c>null</c>.</param>
        /// <param name="result">When this method returns, the parsed <see cref="InstanceName"/>,
        /// or <c>null</c> if parsing fails.</param>
        /// <returns><c>true</c> if the name was parsed succssfully; <c>false</c> otherwise.</returns>
        public static bool TryParse(string instanceName, out InstanceName result)
        {
            GaxPreconditions.CheckNotNull(instanceName, nameof(instanceName));
            TemplatedResourceName resourceName;

            if (s_template.TryParseName(instanceName, out resourceName))
            {
                result = new InstanceName(resourceName[0], resourceName[1]);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// Tries to parse the given project resource name in string form into a new
        /// <see cref="ProjectName"/> instance.
        /// </summary>
        /// <remarks>
        /// This method still throws <see cref="ArgumentNullException"/> if <paramref name="projectName"/> is null,
        /// as this would usually indicate a programming error rather than a data error.
        /// </remarks>
        /// <param name="projectName">The project resource name in string form. Must not be <c>null</c>.</param>
        /// <param name="result">When this method returns, the parsed <see cref="ProjectName"/>,
        /// or <c>null</c> if parsing fails.</param>
        /// <returns><c>true</c> if the name was parsed succssfully; <c>false</c> otherwise.</returns>
        public static bool TryParse(string projectName, out ProjectName result)
        {
            GaxPreconditions.CheckNotNull(projectName, nameof(projectName));
            TemplatedResourceName resourceName;

            if (s_template.TryParseName(projectName, out resourceName))
            {
                result = new ProjectName(resourceName[0]);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
        /// <summary>
        /// Tries to parse the given monitored_resource_descriptor resource name in string form into a new
        /// <see cref="MonitoredResourceDescriptorName"/> instance.
        /// </summary>
        /// <remarks>
        /// This method still throws <see cref="ArgumentNullException"/> if <paramref name="monitoredResourceDescriptorName"/> is null,
        /// as this would usually indicate a programming error rather than a data error.
        /// </remarks>
        /// <param name="monitoredResourceDescriptorName">The monitored_resource_descriptor resource name in string form. Must not be <c>null</c>.</param>
        /// <param name="result">When this method returns, the parsed <see cref="MonitoredResourceDescriptorName"/>,
        /// or <c>null</c> if parsing fails.</param>
        /// <returns><c>true</c> if the name was parsed succssfully; <c>false</c> otherwise.</returns>
        public static bool TryParse(string monitoredResourceDescriptorName, out MonitoredResourceDescriptorName result)
        {
            GaxPreconditions.CheckNotNull(monitoredResourceDescriptorName, nameof(monitoredResourceDescriptorName));
            TemplatedResourceName resourceName;

            if (s_template.TryParseName(monitoredResourceDescriptorName, out resourceName))
            {
                result = new MonitoredResourceDescriptorName(resourceName[0], resourceName[1]);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Пример #6
0
        /// <summary>
        /// Tries to parse the given document_path resource name in string form into a new
        /// <see cref="DocumentPathName"/> instance.
        /// </summary>
        /// <remarks>
        /// This method still throws <see cref="ArgumentNullException"/> if <paramref name="documentPathName"/> is null,
        /// as this would usually indicate a programming error rather than a data error.
        /// </remarks>
        /// <param name="documentPathName">The document_path resource name in string form. Must not be <c>null</c>.</param>
        /// <param name="result">When this method returns, the parsed <see cref="DocumentPathName"/>,
        /// or <c>null</c> if parsing fails.</param>
        /// <returns><c>true</c> if the name was parsed succssfully; <c>false</c> otherwise.</returns>
        public static bool TryParse(string documentPathName, out DocumentPathName result)
        {
            GaxPreconditions.CheckNotNull(documentPathName, nameof(documentPathName));
            TemplatedResourceName resourceName;

            if (s_template.TryParseName(documentPathName, out resourceName))
            {
                result = new DocumentPathName(resourceName[0], resourceName[1], resourceName[2]);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Пример #7
0
        public void ParseName_Valid(string templateText, string name, string[] expectedResourceIds, string expectedServiceName)
        {
            var template     = new PathTemplate(templateText);
            var resourceName = template.ParseName(name);

            for (int i = 0; i < expectedResourceIds.Length; i++)
            {
                Assert.Equal(resourceName[i], expectedResourceIds[i]);
            }
            Assert.Equal(expectedServiceName, resourceName.ServiceName);
            // Should round-trip...
            Assert.Equal(name, resourceName.ToString());

            // And TryParse...
            TemplatedResourceName result;

            Assert.True(template.TryParseName(name, out result));
            Assert.NotNull(result);
        }
Пример #8
0
        public void ParseName_Valid(string templateText, string name, string[] expectedResourceIds, string expectedServiceName)
        {
            var template = new PathTemplate(templateText);
            var resourceName = template.ParseName(name);
            for (int i = 0; i < expectedResourceIds.Length; i++)
            {
                Assert.Equal(resourceName[i], expectedResourceIds[i]);
            }
            Assert.Equal(expectedServiceName, resourceName.ServiceName);
            // Should round-trip...
            Assert.Equal(name, resourceName.ToString());

            // And TryParse...
            ResourceName result;
            Assert.True(template.TryParseName(name, out result));
            Assert.NotNull(result);
        }