Esempio n. 1
0
        public void Process_NoTemplateFound()
        {
            var entry = new BumpyConfigEntry {
                Glob = "unsupported.foo"
            };

            Assert.Throws <ConfigException>(() => ConfigProcessor.Process(entry));
        }
Esempio n. 2
0
        public void Process_ApplyTemplate()
        {
            var entry = new BumpyConfigEntry {
                Glob = "*.csproj"
            };

            var newEntry = ConfigProcessor.Process(entry);

            Assert.False(string.IsNullOrWhiteSpace(newEntry.Regex));
        }
Esempio n. 3
0
        /// <summary>
        /// Validates instances of <see cref="BumpyConfigEntry"/>. Will also enrich an instance
        /// with additional data.
        /// </summary>
        /// <param name="entry">The object to validate and enrich</param>
        /// <returns>The given object or a new enriched object</returns>
        public static BumpyConfigEntry Process(BumpyConfigEntry entry)
        {
            if (string.IsNullOrWhiteSpace(entry.Glob))
            {
                throw new ConfigException("Glob cannot be empty");
            }

            if (string.IsNullOrWhiteSpace(entry.Regex))
            {
                return(ApplyTemplate(entry));
            }

            return(entry);
        }
Esempio n. 4
0
        private static BumpyConfigEntry ApplyTemplate(BumpyConfigEntry entry)
        {
            if (Template.TryFindTemplate(entry.Glob, out var template))
            {
                return(new BumpyConfigEntry
                {
                    Glob = entry.Glob,
                    Profile = entry.Profile,
                    Encoding = template.Encoding,
                    Regex = template.Regex
                });
            }

            throw new ConfigException($"Could not find a template for glob '{entry.Glob}'");
        }