Ejemplo n.º 1
0
        private static INamingConvention GetNamingConvention(NamingConvention namingConvention)
        {
            INamingConvention target;

            switch (namingConvention)
            {
            case NamingConvention.Camel:
                target = new CamelCaseNamingConvention();
                break;

            case NamingConvention.Hyphenated:
                target = new HyphenatedNamingConvention();
                break;

            case NamingConvention.Pascal:
                target = new PascalCaseNamingConvention();
                break;

            case NamingConvention.Underscored:
                target = new UnderscoredNamingConvention();
                break;

            case NamingConvention.Null:
                target = new NullNamingConvention();
                break;

            default:
                throw new NotImplementedException(namingConvention.ToString());
            }

            return(target);
        }
Ejemplo n.º 2
0
        public void AttributeOverridesAndNamingConventionDoNotConflict()
        {
            var namingConvention = new CamelCaseNamingConvention();

            var yamlMember = new YamlMemberAttribute
            {
                Alias = "Required"
            };

            var serializer = new SerializerBuilder()
                             .WithNamingConvention(namingConvention)
                             .WithAttributeOverride <Foo>(f => f.IsRequired, yamlMember)
                             .Build();

            var yaml = serializer.Serialize(new Foo {
                IsRequired = true
            });

            Assert.Contains("required: true", yaml);

            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(namingConvention)
                               .WithAttributeOverride <Foo>(f => f.IsRequired, yamlMember)
                               .Build();

            var deserializedFoo = deserializer.Deserialize <Foo>(yaml);

            Assert.True(deserializedFoo.IsRequired);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// convert o array de personagens em formato yaml, também foi pensado em realizar essa solução usando string builder, ou serializado em outro objeto abstrato.
        /// </summary>
        /// <param name="character">Array contendo uma lista de personagens</param>
        /// <returns></returns>
        private string ConverInYaml(CharacterDTO[] character)
        {
            CamelCaseNamingConvention convention = new CamelCaseNamingConvention();
            var serializer = new SerializerBuilder().WithNamingConvention(convention).Build();

            var yaml = serializer.Serialize(character);

            yaml = yaml.Replace("- name: ", "").Replace("items:\r\n    ", "");
            yaml = yaml.Replace("items: []\r\n  ", "").Replace("    items: []\r\n", "");
            yaml = yaml.Replace("- id: ", "  \r\n  id: ").Replace("'", "");
            return(yaml);
        }
Ejemplo n.º 4
0
        public void AttributeOverridesAndNamingConventionDoNotConflictInLegacyConfiguration()
        {
            var overrides = new YamlAttributeOverrides();

            overrides.Add <Foo>(f => f.IsRequired, new YamlMemberAttribute
            {
                Alias = "Required"
            });

            var namingConvention = new CamelCaseNamingConvention();

            var serializer = new Serializer(namingConvention: namingConvention, overrides: overrides);
            var yaml       = serializer.Serialize(new Foo {
                IsRequired = true
            });

            Assert.Contains("required: true", yaml);

            var deserializer    = new Deserializer(namingConvention: namingConvention, overrides: overrides);
            var deserializedFoo = deserializer.Deserialize <Foo>(yaml);

            Assert.True(deserializedFoo.IsRequired);
        }
Ejemplo n.º 5
0
 public void TestCamelCase(string expected, string input)
 {
     var sut = new CamelCaseNamingConvention();
     Assert.Equal(expected, sut.Apply(input));
 }
        public void CamelCase(string srcName, string expectedName)
        {
            string actualName = new CamelCaseNamingConvention().GetPropertyName(srcName);

            Assert.Equal(expectedName, actualName);
        }
Ejemplo n.º 7
0
        public void TestCamelCase(string expected, string input)
        {
            var sut = new CamelCaseNamingConvention();

            Assert.Equal(expected, sut.Apply(input));
        }