From bade4b4e2180ef69a8731aefe06fdcfc4b63f8a4 Mon Sep 17 00:00:00 2001 From: Steve Wagner Date: Sat, 22 May 2010 17:43:09 +0200 Subject: [PATCH] Add copy constructor for Oid. --- source/MongoDB.Tests/UnitTests/TestOid.cs | 13 +++++++++++-- source/MongoDB/Oid.cs | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/source/MongoDB.Tests/UnitTests/TestOid.cs b/source/MongoDB.Tests/UnitTests/TestOid.cs index c3a1577c..6df593f7 100644 --- a/source/MongoDB.Tests/UnitTests/TestOid.cs +++ b/source/MongoDB.Tests/UnitTests/TestOid.cs @@ -88,7 +88,7 @@ public void TestFormatJ() } [Test] - public void TestIDCharacters() + public void TestIdCharacters() { var thrown = false; try @@ -103,7 +103,7 @@ public void TestIDCharacters() } [Test] - public void TestIDLength() + public void TestIdLength() { var thrown = false; try @@ -247,5 +247,14 @@ public void TestToByteArray() Assert.AreEqual(12, bytes2.Length); Assert.AreEqual(bytes, bytes2); } + + [Test] + public void TestCopyConstructor() + { + var source = Oid.NewOid(); + var dest = new Oid(source); + + Assert.AreEqual(source,dest); + } } } \ No newline at end of file diff --git a/source/MongoDB/Oid.cs b/source/MongoDB/Oid.cs index 6a6fd9ab..26e6ddb8 100644 --- a/source/MongoDB/Oid.cs +++ b/source/MongoDB/Oid.cs @@ -51,6 +51,18 @@ public Oid(byte[] value) Array.Copy(value, _bytes, 12); } + /// + /// Initializes a new instance of the class. + /// + /// The oid. + public Oid(Oid oid) + { + if(oid == null) + throw new ArgumentNullException("oid"); + + _bytes = oid._bytes; + } + /// /// Gets the created. ///