Beispiel #1
0
        /// <summary>
        /// Returns the name of a class or other property name with valid classname characters.
        /// </summary>
        /// <param name="input">Class name, field name, or property name to change.</param>
        /// <param name="type">Enum: Unchanged, Singular, Plural</param>
        /// <param name="isEntitySet">If EntitySet, then will check for Underscore.  EF designer does not pluralize EntitySets with underscores.</param>
        /// <returns></returns>
        public string SetWord(string input, ePluralizerTypes type, bool isEntitySet)
        {
            string result             = input;
            bool   containsUnderscore = false;

            if (isEntitySet)
            {
                containsUnderscore = input.Contains("_");
                type = ePluralizerTypes.Plural;
            }

            if (containsUnderscore)
            {
                return(result);
            }


            switch (type)
            {
            case ePluralizerTypes.Unchanged:
                break;

            case ePluralizerTypes.Singular:
                result = MakeSingular(input);
                break;

            case ePluralizerTypes.Plural:
                result = MakePlural(input);
                break;

            default:
                break;
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Fixes tablenames that will be used as class names to make sure
        /// they are valid classnames.
        /// </summary>
        /// <param name="tableName">The table name to fix.</param>
        /// <param name="isEntitySet">Should this be rendered as an EntitySet. Determines the pluralization.</param>
        /// <returns></returns>
        public static string CleanUpClassName(string tableName, bool isEntitySet)
        {
            string result = tableName;

            ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>(Settings.Pluralizer.ClassNames.Selected);

            PluralizerFactory factory = new PluralizerFactory();

            result = factory.SetWord(tableName, classType, isEntitySet);

            return(result);
        }
Beispiel #3
0
        public void pluralizer_factory_returns_unchanged_class_name_for_non_entity_type()
        {
            // Arrange
            string tableName = "Customer";
            string result    = tableName;

            ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged");

            PluralizerFactory factory = new PluralizerFactory();

            // Act
            result = factory.SetWord(tableName, classType);

            // Assert
            Assert.AreEqual(tableName, result);
        }
Beispiel #4
0
        public void pluralizer_factory_test()
        {
            // Arrange
            string tableName = "aspnet_Applications";
            string result    = tableName;

            ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged");

            PluralizerFactory factory = new PluralizerFactory();

            // Act
            result = factory.SetWord(tableName, classType);

            // Assert
            Assert.AreEqual(tableName, result);
        }
Beispiel #5
0
        public string ToPropertyName()
        {
            if (this.Alias.ToLower() == script.Settings.DataOptions.VersionColumnName.ToLower())
            {
                return(this.Alias);
            }
            else
            {
                ////return script.DnpUtils.SetPascalCase(this.Alias);
                //return this.Alias;

                ePluralizerTypes  propertyType = EnumFactory.Parse <ePluralizerTypes>(script.Settings.Pluralizer.PropertyNames.Selected);
                PluralizerFactory factory      = new PluralizerFactory();
                string            result       = factory.SetWord(this.Alias, propertyType);
                return(result);
            }
        }
Beispiel #6
0
        public void plural_table_name_is_replaced_with_singular_table_name_using_singular_type()
        {
            // Arrange
            string tableName = "aspnet_Applications";
            string actual    = "";
            string expected  = "aspnet_Application";

            ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Singular");

            PluralizerFactory factory = new PluralizerFactory();

            // Act
            actual = factory.SetWord(tableName, classType);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        public void table_name_with_underscore_is_correctly_kept_using_unchanged_pluralizerfactory()
        {
            // Arrange
            string tableName = "aspnet_Applications";
            string actual    = "";
            string expected  = "aspnet_Applications";

            ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged");

            PluralizerFactory factory = new PluralizerFactory();

            // Act
            actual = factory.SetWord(tableName, classType);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        public void pluralizer_factory_returns_plural_result_for_singular_class_name_based_on_plural_setting()
        {
            // Arrange
            string tableName = "Customer";
            string result    = tableName;

            ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Plural");

            PluralizerFactory factory = new PluralizerFactory();

            // Act
            result = factory.SetWord(tableName, classType);
            string expected = "Customers";

            // Assert
            Assert.AreEqual(expected, result);
        }
Beispiel #9
0
        public void pluralizer_factory_isentityset_returns_correct_result_for_input_with_underscore()
        {
            // Arrange
            string tableName   = "aspnet_Applications";
            string result      = tableName;
            bool   isEntitySet = true;

            ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged");

            PluralizerFactory factory = new PluralizerFactory();

            // Act
            result = factory.SetWord(tableName, classType, isEntitySet);

            // Assert
            Assert.AreEqual(tableName, result);
        }
Beispiel #10
0
 /// <summary>
 /// Constructs a proper property name based on the pluralizer settings in CondorXE Common tab.
 /// </summary>
 /// <returns></returns>
 public virtual string ToPropertyName()
 {
     if (this.Alias.ToLower() == _script.Settings.DataOptions.VersionColumnName.ToLower())
     {
         return(this.Alias);
     }
     else
     {
         if (!string.IsNullOrEmpty(_propertyName))
         {
             return(_propertyName);
         }
         ePluralizerTypes  propertyType = EnumFactory.Parse <ePluralizerTypes>(_script.Settings.Pluralizer.PropertyNames.Selected);
         PluralizerFactory factory      = new PluralizerFactory();
         _propertyName = factory.SetWord(this.Alias, propertyType);
         return(_propertyName);
     }
 }
Beispiel #11
0
        public void pluralizer_factory_isentityset_returns_plural_entitysetname_for_non_underscore_class_name()
        {
            // Arrange
            string tableName   = "Project";
            string result      = tableName;
            bool   isEntitySet = true;

            ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged");

            PluralizerFactory factory = new PluralizerFactory();

            // Act
            result = factory.SetWord(tableName, classType, isEntitySet);
            string expected = "Projects";

            // Assert
            Assert.AreEqual(expected, result);
        }
Beispiel #12
0
 /// <summary>
 /// Modify the input based on the settings on the Common tab.
 /// </summary>
 /// <param name="input">Class name, field name, or property name to change.</param>
 /// <param name="type">Enum: Unchanged, Singular, Plural</param>
 /// <returns></returns>
 public string SetWord(string input, ePluralizerTypes type)
 {
     return(SetWord(input, type, false));
 }