Exemplo n.º 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());
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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));
 }
Exemplo n.º 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());
        }
Exemplo n.º 12
0
        public void ImplictCastToString()
        {
            var t = new Text("en", "hello world");
            string s = t;

            Assert.AreEqual("hello world", s);
        }
Exemplo n.º 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");
        }