Example #1
0
        public void TestEmpty()
        {
            var empty = MongoSymbol.Empty;

            Assert.IsTrue(MongoSymbol.IsEmpty(empty));
            Assert.IsFalse(MongoSymbol.IsEmpty(new MongoSymbol("a")));
        }
Example #2
0
        public void TestToString()
        {
            const string val = "symbol";
            var          sym = new MongoSymbol(val);

            string str = sym;

            Assert.AreEqual(val, str);
            Assert.IsTrue(str == sym);
            Assert.AreEqual(str, sym.ToString());
        }
        public void TestComparing(){
            var a = new MongoSymbol("a");
            var a2 = new MongoSymbol("a");
            var b = new MongoSymbol("b");

            Assert.AreEqual(0, a.CompareTo(a2));
            Assert.AreEqual(0, a2.CompareTo(a2));

            Assert.AreEqual(-1, a.CompareTo(b));
            Assert.AreEqual(1, b.CompareTo(a));
        }
Example #4
0
        public void TestComparing()
        {
            var a  = new MongoSymbol("a");
            var a2 = new MongoSymbol("a");
            var b  = new MongoSymbol("b");

            Assert.AreEqual(0, a.CompareTo(a2));
            Assert.AreEqual(0, a2.CompareTo(a2));

            Assert.AreEqual(-1, a.CompareTo(b));
            Assert.AreEqual(1, b.CompareTo(a));
        }
Example #5
0
        public void CanBeXmlSerializedWhenValueNull()
        {
            var source     = new MongoSymbol(null);
            var serializer = new XmlSerializer(typeof(MongoSymbol));

            var writer = new StringWriter();

            serializer.Serialize(writer, source);
            var dest = (MongoSymbol)serializer.Deserialize(new StringReader(writer.ToString()));

            Assert.AreEqual(source, dest);
        }
Example #6
0
        public void CanBeBinarySerialized()
        {
            var source    = new MongoSymbol("value");
            var formatter = new BinaryFormatter();

            var mem = new MemoryStream();

            formatter.Serialize(mem, source);
            mem.Position = 0;

            var dest = (MongoSymbol)formatter.Deserialize(mem);

            Assert.AreEqual(source, dest);
        }
Example #7
0
        public void TestWriteSymbol()
        {
            var expected = "0700000073796D626F6C00";

            var         ms     = new MemoryStream();
            var         writer = new BsonWriter(ms, new BsonDocumentDescriptor());
            MongoSymbol val    = "symbol";

            Assert.IsTrue(String.IsInterned(val) != null);
            writer.WriteValue(BsonType.Symbol, val);
            var hexdump = BitConverter.ToString(ms.ToArray()).Replace("-", "");

            Assert.AreEqual(expected, hexdump);
        }
        public void TestEquals(){
            var a = new MongoSymbol("a");
            var a2 = new MongoSymbol("a");
            const string astr = "a";

            var b = new MongoSymbol("b");
            const string bstr = "b";

            Assert.IsTrue(a.Equals(a2));
            Assert.IsTrue(a2.Equals(a));
            Assert.IsTrue(a.Equals(astr));

            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
            Assert.IsFalse(a.Equals(bstr));
        }
Example #9
0
        public void TestEquals()
        {
            var          a    = new MongoSymbol("a");
            var          a2   = new MongoSymbol("a");
            const string astr = "a";

            var          b    = new MongoSymbol("b");
            const string bstr = "b";

            Assert.IsTrue(a.Equals(a2));
            Assert.IsTrue(a2.Equals(a));
            Assert.IsTrue(a.Equals(astr));

            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
            Assert.IsFalse(a.Equals(bstr));
        }
Example #10
0
        public void TestValue()
        {
            Assert.IsTrue(string.IsInterned("s") != null);

            var s = new MongoSymbol("s");

            Assert.IsNotNull(s.Value);
            Assert.IsTrue(string.IsInterned(s.Value) != null, "First value was not interned");

            var val = new StringBuilder().Append('s').ToString();

            Assert.IsFalse(string.IsInterned(val) == null);
            var s2 = new MongoSymbol(val);

            Assert.IsTrue(string.IsInterned(s2.Value) != null, "Second value was not interned");

            Assert.IsTrue(ReferenceEquals(s.Value, s2.Value));
        }
        public void TestNotEqOperator(){
            var a = new MongoSymbol("a");
            var a2 = new MongoSymbol("a");
            const string astr = "a";

            var b = new MongoSymbol("b");
            const string bstr = "b";

            Assert.IsFalse(a != a);
            Assert.IsFalse(a != a2);
            Assert.IsFalse(a2 != a);
            Assert.IsFalse(a != astr);
            Assert.IsFalse(astr != a);

            Assert.IsTrue(a != b);
            Assert.IsTrue(a != bstr);
            Assert.IsTrue(bstr != a);

            Assert.IsTrue(a != null);
        }
Example #12
0
        public void TestNotEqOperator()
        {
            var          a    = new MongoSymbol("a");
            var          a2   = new MongoSymbol("a");
            const string astr = "a";

            var          b    = new MongoSymbol("b");
            const string bstr = "b";

            Assert.IsFalse(a != a);
            Assert.IsFalse(a != a2);
            Assert.IsFalse(a2 != a);
            Assert.IsFalse(a != astr);
            Assert.IsFalse(astr != a);

            Assert.IsTrue(a != b);
            Assert.IsTrue(a != bstr);
            Assert.IsTrue(bstr != a);

            Assert.IsTrue(a != null);
        }
        public void TestEqOperator(){
            var a = new MongoSymbol("a");
            var a2 = new MongoSymbol("a");
            const string astr = "a";

            var b = new MongoSymbol("b");
            const string bstr = "b";

            Assert.IsTrue(a == a);
            Assert.IsTrue(a == a2);
            Assert.IsTrue(a2 == a);
            Assert.IsTrue(a == astr);
            Assert.IsTrue(astr == a);

            Assert.IsTrue(a == new StringBuilder().Append('a').ToString()); //Not interned like the hard coded ones above.

            Assert.IsFalse(a == b);
            Assert.IsFalse(a == bstr);
            Assert.IsFalse(bstr == a);

            Assert.IsFalse(a == null);
        }
Example #14
0
        public void TestEqOperator()
        {
            var          a    = new MongoSymbol("a");
            var          a2   = new MongoSymbol("a");
            const string astr = "a";

            var          b    = new MongoSymbol("b");
            const string bstr = "b";

            Assert.IsTrue(a == a);
            Assert.IsTrue(a == a2);
            Assert.IsTrue(a2 == a);
            Assert.IsTrue(a == astr);
            Assert.IsTrue(astr == a);

            Assert.IsTrue(a == new StringBuilder().Append('a').ToString()); //Not interned like the hard coded ones above.

            Assert.IsFalse(a == b);
            Assert.IsFalse(a == bstr);
            Assert.IsFalse(bstr == a);

            Assert.IsFalse(a == null);
        }
        public void TestValue(){
            Assert.IsTrue(string.IsInterned("s") != null);

            var s = new MongoSymbol("s");
            Assert.IsNotNull(s.Value);
            Assert.IsTrue(string.IsInterned(s.Value) != null, "First value was not interned");

            var val = new StringBuilder().Append('s').ToString();
            Assert.IsFalse(string.IsInterned(val) == null);
            var s2 = new MongoSymbol(val);
            Assert.IsTrue(string.IsInterned(s2.Value) != null, "Second value was not interned");

            Assert.IsTrue(ReferenceEquals(s.Value, s2.Value));
        }
        public void CanBeBinarySerialized()
        {
            var source = new MongoSymbol("value");
            var formatter = new BinaryFormatter();

            var mem = new MemoryStream();
            formatter.Serialize(mem, source);
            mem.Position = 0;

            var dest = (MongoSymbol)formatter.Deserialize(mem);

            Assert.AreEqual(source, dest);
        }
        public void CanBeXmlSerializedWhenValueNull()
        {
            var source = new MongoSymbol(null);
            var serializer = new XmlSerializer(typeof(MongoSymbol));

            var writer = new StringWriter();
            serializer.Serialize(writer, source);
            var dest = (MongoSymbol)serializer.Deserialize(new StringReader(writer.ToString()));

            Assert.AreEqual(source, dest);
        }
        public void TestToString(){
            const string val = "symbol";
            var sym = new MongoSymbol(val);

            string str = sym;
            Assert.AreEqual(val, str);
            Assert.IsTrue(str == sym);
            Assert.AreEqual(str, sym.ToString());
        }