Пример #1
0
 public void Construction()
 {
     var t = new Text("en", "hello world");
     Assert.AreEqual("en", t.Language);
     Assert.AreEqual("hello world", t.Value);
     Assert.AreEqual("hello world (en)", t.ToString());
 }
Пример #2
0
        public void Equality()
        {
            var a = new Text("en", "hello world");
            var b = new Text("en", "hello world");
            var c = new Text("en-AU", "g'day mate");
            //Text d = null;

            Assert.IsTrue(a.Equals(a));
            Assert.IsTrue(a.Equals(b));
            Assert.IsFalse(a.Equals(c));
            //Assert.IsFalse(a.Equals(d));

            Assert.IsTrue(b.Equals(a));
            Assert.IsTrue(b.Equals(b));
            Assert.IsFalse(b.Equals(c));
            //Assert.IsFalse(b.Equals(d));

            Assert.IsFalse(c.Equals(a));
            Assert.IsFalse(c.Equals(b));
            Assert.IsTrue(c.Equals(c));
            //Assert.IsFalse(c.Equals(d));

            Assert.IsTrue(a.Equals((object) a));
            Assert.IsTrue(a.Equals((object) b));
            Assert.IsFalse(a.Equals((object) c));
            Assert.IsFalse(a.Equals((object) null));
        }
Пример #3
0
        public void ImplicitCastFromString()
        {
            var thai = new Text("th", "สวัสดี");
            var chineseSimplified = new Text("zh-Hans", "你好");
            var chineseTraditional = new Text("zh-Hant", "你好");

            Assert.AreEqual("Thai", thai.Language.Description.WrittenIn("en").Value);
            Assert.AreEqual("Chinese (Simplified)", chineseSimplified.Language.Description.WrittenIn("en").Value);
            Assert.AreEqual("Chinese (Traditional)", chineseTraditional.Language.Description.WrittenIn("en").Value);
        }
Пример #4
0
        public void HasExactValue()
        {
            var greetings = new Text[]
            {
                new Text(english, "hello world"),
                new Text(oz, "g'day mate")
            };

            Assert.IsTrue(greetings.HasExactValue(english));
            Assert.IsTrue(greetings.HasExactValue(oz));
            Assert.IsFalse(greetings.HasExactValue(kiwi));
        }
Пример #5
0
        public void WrittenIn()
        {
            var greetings = new Text[]
            {
                new Text(english, "hello world"),
                new Text(oz, "g'day mate")
            };

            Assert.AreEqual("hello world", greetings.WrittenIn(english));
            Assert.AreEqual("g'day mate", greetings.WrittenIn(oz));
            Assert.AreEqual("g'day mate", greetings.WrittenIn("en-AU-SYDNEY"));
            Assert.AreEqual("hello world", greetings.WrittenIn(kiwi));
            Assert.AreEqual("hello world", greetings.WrittenIn("fr"));
            Assert.AreEqual("hello world", greetings.WrittenIn("fr-CN"));

            Assert.AreEqual("", new Text[0].WrittenIn(english));
        }
Пример #6
0
        public void EqualOperatator()
        {
            var a = new Text("en", "hello world");
            var b = new Text("en", "hello world");
            var c = new Text("en-AU", "g'day mate");
            #pragma warning disable 1718
            Assert.IsTrue(a == a);
            Assert.IsTrue(a == b);
            Assert.IsFalse(a == c);

            Assert.IsTrue(b == a);
            Assert.IsTrue(b == b);
            Assert.IsFalse(b == c);

            Assert.IsFalse(c == a);
            Assert.IsFalse(c == b);
            Assert.IsTrue(c == c);
            #pragma warning restore 1718
        }
Пример #7
0
        public void LanguageTagCaseInsensitive()
        {
            var greetings = new Text[]
            {
                new Text(english, "hello world"),
                new Text(oz, "g'day mate")
            };

            Assert.AreEqual("hello world", greetings.WrittenIn(english));
            Assert.AreEqual("g'day mate", greetings.WrittenIn(oz));
            Assert.AreEqual("g'day mate", greetings.WrittenIn("EN-au-SYDNEY"));
            Assert.AreEqual("hello world", greetings.WrittenIn(kiwi));
            Assert.AreEqual("hello world", greetings.WrittenIn("FR"));
            Assert.AreEqual("hello world", greetings.WrittenIn("FR-cn"));

            Assert.IsTrue(greetings.HasExactValue(english));
            Assert.IsTrue(greetings.HasExactValue(english));
            Assert.IsTrue(greetings.HasExactValue(english));
            Assert.IsTrue(greetings.HasExactValue(oz));
            Assert.IsTrue(greetings.HasExactValue(oz));
            Assert.IsTrue(greetings.HasExactValue(oz));
            Assert.IsTrue(greetings.HasExactValue(oz));
            Assert.IsTrue(greetings.HasExactValue(oz));
        }
        public void FlattenText()
        {
            var texts = new Text[] { };
            Assert.IsTrue(ComplexText.FlattenText(texts).Count() == 0);

            texts = new Text[] 
            {
                new SimpleText("", 0, 0),
                new SimpleText("", 0, 0),
                new SimpleText("", 0, 0)
            };
            Assert.IsTrue(ComplexText.FlattenText(texts).Count() == 3);

            texts = new Text[]
            {
                new ComplexText(new[]
                {
                    new SimpleText("", 0, 0),
                    new SimpleText("", 0, 0),
                    new SimpleText("", 0, 0)
                },
                enableOptimizations: false),
                new ComplexText(new[]
                {
                    new SimpleText("", 0, 0),
                    new SimpleText("", 0, 0),
                    new SimpleText("", 0, 0)
                },
                enableOptimizations: false),
                new ComplexText(new[]
                {
                    new SimpleText("", 0, 0),
                    new SimpleText("", 0, 0),
                    new SimpleText("", 0, 0)
                },
                enableOptimizations: false),
            };
            Assert.IsTrue(ComplexText.FlattenText(texts).Count() == 9);

            var str = "abc";
            texts = new Text[]
            {
                new SimpleText(str, 0, 1),
                new SimpleText(str, 1, 1),
                new SimpleText(str, 2, 1)
            };
            Assert.IsTrue(ComplexText.FlattenText(texts).Count() == 3);
        }
Пример #9
0
        public void Hashing()
        {
            var a = new Text("en", "hello world");
            var b = new Text("en", "hello world");
            var c = new Text("en-AU", "g'day mate");

            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
            Assert.AreNotEqual(a.GetHashCode(), c.GetHashCode());
            ExceptionAssert.Throws<InvalidOperationException>(() => new Text().GetHashCode());
        }
Пример #10
0
 public void NullEquality()
 {
     var a = new Text("en", "hello world");
     Assert.IsFalse(a  ==  null);
     Assert.IsTrue(a != null);
     Assert.IsFalse(a.Equals(null));
 }
Пример #11
0
        public void LanguageTagsAreCaseInsensitive()
        {
            var t1 = new Text("en", "hello world");
            var t2 = new Text("EN", "hello world");

            Assert.AreEqual(t1, t2);
            Assert.AreEqual(t1.GetHashCode(), t2.GetHashCode());
        }
Пример #12
0
        public void ImplictCastToString()
        {
            var t = new Text("en", "hello world");
            string s = t;

            Assert.AreEqual("hello world", s);
        }
Пример #13
0
        public void ImmutableProperties()
        {
            var t = new Text();
            t.Language = "en";
            t.Value = "hello world";
            ExceptionAssert.Throws<InvalidOperationException>(() => t.Language = "en-NZ");
            ExceptionAssert.Throws<InvalidOperationException>(() => t.Value = "cheers");

            var t1 = new Text("en", "hello world");
            ExceptionAssert.Throws<InvalidOperationException>(() => t1.Language = "en-NZ");
            ExceptionAssert.Throws<InvalidOperationException>(() => t1.Value = "cheers");

            var t2 = new Text { Language = "en", Value = "hello world" };
            ExceptionAssert.Throws<InvalidOperationException>(() => t2.Language = "en-NZ");
            ExceptionAssert.Throws<InvalidOperationException>(() => t2.Value = "cheers");
        }