Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 144 lines (127 sloc) 3.901 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
#if(!MONO)
namespace Simple.Data.UnitTest
{
    using System.Data.Entity.Design.PluralizationServices;
    using System.Globalization;
    using Extensions;
    using NUnit.Framework;

[TestFixture]
    public class PluralizationTest
    {
[TestFixtureSetUp]
        public void FixtureSetup()
        {
            Database.SetPluralizer(new EntityPluralizer());
        }

        /// <summary>
        ///A test for IsPlural
        ///</summary>
[Test]
        public void IsPluralLowercaseUsersShouldReturnTrue()
        {
            Assert.IsTrue("Users".IsPlural());
        }

        /// <summary>
        ///A test for IsPlural
        ///</summary>
[Test]
        public void IsPluralUppercaseUsersShouldReturnTrue()
        {
            Assert.IsTrue("USERS".IsPlural());
        }

        /// <summary>
        ///A test for IsPlural
        ///</summary>
[Test]
        public void IsPluralLowercaseUserShouldReturnFalse()
        {
            Assert.IsFalse("User".IsPlural());
        }

        /// <summary>
        ///A test for IsPlural
        ///</summary>
[Test]
        public void IsPluralUppercaseUserShouldReturnFalse()
        {
            Assert.IsFalse("USER".IsPlural());
        }

        /// <summary>
        ///A test for Pluralize
        ///</summary>
[Test()]
        public void PluralizeUserShouldReturnUsers()
        {
            Assert.AreEqual("Users", "User".Pluralize());
        }

        /// <summary>
        ///A test for Pluralize
        ///</summary>
[Test()]
        // ReSharper disable InconsistentNaming
        public void PluralizeUSERShouldReturnUSERS()
        // ReSharper restore InconsistentNaming
        {
            Assert.AreEqual("USERS", "USER".Pluralize());
        }

        /// <summary>
        ///A test for Singularize
        ///</summary>
[Test()]
        public void SingularizeUsersShouldReturnUser()
        {
            Assert.AreEqual("User", "Users".Singularize());
        }

        /// <summary>
        ///A test for Singularize
        ///</summary>
[Test()]
        public void SingularizeUserShouldReturnUser()
        {
            Assert.AreEqual("User", "User".Singularize());
        }

        /// <summary>
        ///A test for Singularize
        ///</summary>
[Test()]
        // ReSharper disable InconsistentNaming
        public void SingularizeUSERSShouldReturnUSER()
        // ReSharper restore InconsistentNaming
        {
            Assert.AreEqual("USER", "USERS".Singularize());
        }

[Test]
        public void PluralizeCompanyShouldReturnCompanies()
        {
            Assert.AreEqual("Companies", "Company".Pluralize());
        }

[Test]
        public void SingularizeCompaniesShouldReturnCompany()
        {
            Assert.AreEqual("Company", "Companies".Singularize());
        }
    }

    class EntityPluralizer : IPluralizer
    {
        private readonly PluralizationService _pluralizationService =
            PluralizationService.CreateService(new CultureInfo("en"));

        public bool IsPlural(string word)
        {
            return _pluralizationService.IsPlural(word);
        }

        public bool IsSingular(string word)
        {
            return _pluralizationService.IsSingular(word);
        }

        public string Pluralize(string word)
        {
            bool upper = (word.IsAllUpperCase());
            word = _pluralizationService.Pluralize(word);
            return upper ? word.ToUpper(_pluralizationService.Culture) : word;
        }

        public string Singularize(string word)
        {
            return _pluralizationService.Singularize(word);
        }
    }
}
#endif
Something went wrong with that request. Please try again.