Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 137 lines (125 sloc) 4.823 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
/* Copyright 2010-2012 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

using MongoDB.Bson;

namespace MongoDB.BsonUnitTests
{
[TestFixture]
    public class BsonEqualsTests
    {
[Test]
        public void TestBsonArrayEquals()
        {
            BsonArray lhs = new BsonArray { 1, 2, 3 };
            BsonArray rhs = new BsonArray().Add(1).Add(2).Add(3);
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonBinaryDataEquals()
        {
            BsonBinaryData lhs = new BsonBinaryData(new byte[] { 1, 2, 3 }, BsonBinarySubType.Binary);
            BsonBinaryData rhs = new BsonBinaryData(new byte[] { 1, 2, 3 }, BsonBinarySubType.Binary);
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonDocumentEquals()
        {
            BsonDocument lhs = new BsonDocument
            {
                { "Hello", "World" },
                { "Foo", "Bar" }
            };
            BsonDocument rhs = new BsonDocument
            {
                { "Hello", "World" },
                { "Foo", "Bar" }
            };
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonElementEquals()
        {
            BsonElement lhs = new BsonElement("Hello", "World");
            BsonElement rhs = new BsonElement("Hello", "World");
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonJavaScriptEquals()
        {
            BsonJavaScript lhs = new BsonJavaScript("n = 1");
            BsonJavaScript rhs = new BsonJavaScript("n = 1");
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonJavaScriptWithScopeEquals()
        {
            BsonJavaScriptWithScope lhs = new BsonJavaScriptWithScope("n = 1", new BsonDocument { { "x", "2" } });
            BsonJavaScriptWithScope rhs = new BsonJavaScriptWithScope("n = 1", new BsonDocument { { "x", "2" } });
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonObjectIdEquals()
        {
            BsonObjectId lhs = new ObjectId(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
            BsonObjectId rhs = new ObjectId(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonRegularExpressionEquals()
        {
            BsonRegularExpression lhs = new BsonRegularExpression("pattern", "options");
            BsonRegularExpression rhs = new BsonRegularExpression("pattern", "options");
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonSymbolEquals()
        {
            BsonSymbol lhs = BsonSymbolTable.Lookup("name");
            BsonSymbol rhs = BsonSymbolTable.Lookup("name");
            Assert.AreSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }

[Test]
        public void TestBsonTimestampEquals()
        {
            BsonTimestamp lhs = new BsonTimestamp(1L);
            BsonTimestamp rhs = new BsonTimestamp(1L);
            Assert.AreNotSame(lhs, rhs);
            Assert.AreEqual(lhs, rhs);
            Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
        }
    }
}
Something went wrong with that request. Please try again.