diff --git a/MongoDB.Driver.Benchmark/Main.cs b/MongoDB.Driver.Benchmark/Main.cs index a964074b..aa56f79d 100644 --- a/MongoDB.Driver.Benchmark/Main.cs +++ b/MongoDB.Driver.Benchmark/Main.cs @@ -24,7 +24,7 @@ public static void Main (string[] args) { SetupDocuments(); - Mongo m = new Mongo(); + Mongo m = MongoFactory.CreateMongo(); m.Connect(); Database db = m["benchmark"]; diff --git a/MongoDB.GridFS.Tests/App.config b/MongoDB.GridFS.Tests/App.config new file mode 100644 index 00000000..a1fc3917 --- /dev/null +++ b/MongoDB.GridFS.Tests/App.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/MongoDB.GridFS.Tests/GridFileInfoTest.cs b/MongoDB.GridFS.Tests/GridFileInfoTest.cs index 3151ca82..2db3cedc 100644 --- a/MongoDB.GridFS.Tests/GridFileInfoTest.cs +++ b/MongoDB.GridFS.Tests/GridFileInfoTest.cs @@ -10,7 +10,7 @@ namespace MongoDB.GridFS [TestFixture] public class GridFileInfoTest { - Mongo db = new Mongo(); + Mongo db = MongoFactory.CreateMongo(); [Test] public void TestCreateNonExisting(){ String filename = "newfile.txt"; diff --git a/MongoDB.GridFS.Tests/GridFileStreamTest.cs b/MongoDB.GridFS.Tests/GridFileStreamTest.cs index 527c775a..eb58573e 100755 --- a/MongoDB.GridFS.Tests/GridFileStreamTest.cs +++ b/MongoDB.GridFS.Tests/GridFileStreamTest.cs @@ -10,7 +10,7 @@ namespace MongoDB.GridFS [TestFixture] public class GridFileStreamTest { - Mongo db = new Mongo(); + Mongo db = MongoFactory.CreateMongo(); GridFile fs; String filesystem = "gfstream"; diff --git a/MongoDB.GridFS.Tests/GridFileTest.cs b/MongoDB.GridFS.Tests/GridFileTest.cs index 38e73825..70eeb843 100644 --- a/MongoDB.GridFS.Tests/GridFileTest.cs +++ b/MongoDB.GridFS.Tests/GridFileTest.cs @@ -9,7 +9,7 @@ namespace MongoDB.GridFS { [TestFixture] public class GridFileTest{ - Mongo db = new Mongo(); + Mongo db = MongoFactory.CreateMongo(); [Test] public void TestFileDoesNotExist(){ diff --git a/MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.csproj b/MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.csproj index f5b4f59b..4377844c 100644 --- a/MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.csproj +++ b/MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.csproj @@ -1,56 +1,59 @@ - - - - Debug - AnyCPU - 9.0.21022 - 2.0 - {0C293FE9-F670-4FEF-A60F-20F8C978B1CD} - Library - MongoDB.GridFS.Tests - v2.0 - MongoDB.GridFS.Tests - - - true - full - false - bin\Debug - DEBUG - prompt - 4 - false - - - none - false - bin\Release - prompt - 4 - false - - - - - False - ..\redist\nunit.framework.dll - - - - - - - - - - - {B125BBA6-BFFD-44FA-9254-9B1754CD8AF3} - MongoDB.Driver - - - {B42DBBF9-0A1F-4749-9787-013BF8D8F435} - MongoDB.GridFS - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {0C293FE9-F670-4FEF-A60F-20F8C978B1CD} + Library + MongoDB.GridFS.Tests + v2.0 + MongoDB.GridFS.Tests + + + true + full + false + bin\Debug + DEBUG + prompt + 4 + false + + + none + false + bin\Release + prompt + 4 + false + + + + + False + ..\redist\nunit.framework.dll + + + + + + + + + + + {B125BBA6-BFFD-44FA-9254-9B1754CD8AF3} + MongoDB.Driver + + + {B42DBBF9-0A1F-4749-9787-013BF8D8F435} + MongoDB.GridFS + + + + + + \ No newline at end of file diff --git a/MongoDB.Linq.Tests/App.config b/MongoDB.Linq.Tests/App.config index 1680d110..a1fc3917 100644 --- a/MongoDB.Linq.Tests/App.config +++ b/MongoDB.Linq.Tests/App.config @@ -1,10 +1,5 @@  - -
- - - \ No newline at end of file diff --git a/MongoDB.Linq.Tests/AppSettingsFactory.cs b/MongoDB.Linq.Tests/AppSettingsFactory.cs deleted file mode 100644 index 051fe13a..00000000 --- a/MongoDB.Linq.Tests/AppSettingsFactory.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Text; -using MongoDB.Driver; - -namespace MongoDB.Linq.Tests { - public static class AppSettingsFactory { - - public static string Host { get { return ConfigurationManager.AppSettings["mongo.host"]; } } - public static int Port { get { return int.Parse(ConfigurationManager.AppSettings["mongo.port"]); } } - - public static Mongo CreateMongo() { - return new Mongo(Host, Port); - } - - public static Connection CreateConnection() { - return new Connection(Host, Port); - } - } -} \ No newline at end of file diff --git a/MongoDB.Linq.Tests/MongoDB.Linq.Tests.csproj b/MongoDB.Linq.Tests/MongoDB.Linq.Tests.csproj index 9f9c5957..94d56729 100644 --- a/MongoDB.Linq.Tests/MongoDB.Linq.Tests.csproj +++ b/MongoDB.Linq.Tests/MongoDB.Linq.Tests.csproj @@ -1,4 +1,4 @@ - + Debug @@ -54,7 +54,6 @@ - diff --git a/MongoDB.Linq.Tests/TestQueryExecution.cs b/MongoDB.Linq.Tests/TestQueryExecution.cs index e2bcf7f8..9ef68e14 100644 --- a/MongoDB.Linq.Tests/TestQueryExecution.cs +++ b/MongoDB.Linq.Tests/TestQueryExecution.cs @@ -12,7 +12,7 @@ public class TestQueryExecution { [TestFixtureSetUp] public void GlobalSetup() { Debug.WriteLine("initiallizing connection"); - mongo = AppSettingsFactory.CreateMongo(); + mongo = MongoFactory.CreateMongo(); mongo.Connect(); } diff --git a/MongoDB.Net-Tests/App.config b/MongoDB.Net-Tests/App.config new file mode 100644 index 00000000..a1fc3917 --- /dev/null +++ b/MongoDB.Net-Tests/App.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj b/MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj index c57f657f..06748ab5 100644 --- a/MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj +++ b/MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj @@ -1,4 +1,4 @@ - + Debug @@ -72,6 +72,7 @@ + @@ -117,7 +118,4 @@ Always - - - \ No newline at end of file diff --git a/MongoDB.Net-Tests/MongoTestBase.cs b/MongoDB.Net-Tests/MongoTestBase.cs index daaa9a04..764f8580 100644 --- a/MongoDB.Net-Tests/MongoTestBase.cs +++ b/MongoDB.Net-Tests/MongoTestBase.cs @@ -20,8 +20,8 @@ public Database DB{ [TestFixtureSetUp] - public virtual void Init(){ - this.Mongo = new Mongo(); + public virtual void Init(){ + this.Mongo = MongoFactory.CreateMongo(); this.Mongo.Connect(); cleanDB(); } diff --git a/MongoDB.Net-Tests/TestAuthentication.cs b/MongoDB.Net-Tests/TestAuthentication.cs index 42dbd80e..19e8bfae 100644 --- a/MongoDB.Net-Tests/TestAuthentication.cs +++ b/MongoDB.Net-Tests/TestAuthentication.cs @@ -15,7 +15,7 @@ namespace MongoDB.Driver [TestFixture] public class TestAuthentication { - Mongo mongo = new Mongo(); + Mongo mongo = MongoFactory.CreateMongo(); Database db; String testuser = "testuser"; diff --git a/MongoDB.Net-Tests/TestB.cs b/MongoDB.Net-Tests/TestB.cs index 49354316..f28cda5e 100644 --- a/MongoDB.Net-Tests/TestB.cs +++ b/MongoDB.Net-Tests/TestB.cs @@ -17,8 +17,8 @@ public class TestB [Test()] public void TestCase(){ - TcpClient client = new TcpClient(); - client.Connect("localhost", 27017); + TcpClient client = new TcpClient(); + client.Connect(MongoFactory.Host, MongoFactory.Port); BufferedStream buff = new BufferedStream(client.GetStream()); BinaryWriter writer = new BinaryWriter(buff); diff --git a/MongoDB.Net-Tests/TestCollection.cs b/MongoDB.Net-Tests/TestCollection.cs index 98208445..a6dc80a5 100755 --- a/MongoDB.Net-Tests/TestCollection.cs +++ b/MongoDB.Net-Tests/TestCollection.cs @@ -7,7 +7,8 @@ namespace MongoDB.Driver [TestFixture] public class TestCollection { - Mongo db = new Mongo(); + Mongo db = MongoFactory.CreateMongo(); + private string pound = "\u00a3"; [Test] diff --git a/MongoDB.Net-Tests/TestCollectionMetaData.cs b/MongoDB.Net-Tests/TestCollectionMetaData.cs index 9f796e0f..3d2d0eee 100644 --- a/MongoDB.Net-Tests/TestCollectionMetaData.cs +++ b/MongoDB.Net-Tests/TestCollectionMetaData.cs @@ -8,8 +8,8 @@ namespace MongoDB.Driver { [TestFixture] public class TestCollectionMetaData - { - Mongo db = new Mongo(); + { + Mongo db = MongoFactory.CreateMongo(); [Test] public void TestGetOptions(){ diff --git a/MongoDB.Net-Tests/TestConcurrency.cs b/MongoDB.Net-Tests/TestConcurrency.cs index f49d997e..419a7fc6 100644 --- a/MongoDB.Net-Tests/TestConcurrency.cs +++ b/MongoDB.Net-Tests/TestConcurrency.cs @@ -13,12 +13,12 @@ public class TestConcurrency /* * Having all of these tests enabled will slow the test suite down a lot. In the future it may be better * to have them ifdef'ed so that the long running tests can be executed by just setting a compile flag. - */ - Mongo db = new Mongo(); + */ + Mongo db = MongoFactory.CreateMongo(); //[Test] - public void TestMultiThreadedWrites (){ - Mongo db = new Mongo(); + public void TestMultiThreadedWrites (){ + Mongo db = MongoFactory.CreateMongo(); db.Connect(); IMongoCollection col = db["tests"]["threadinserts"]; @@ -44,8 +44,8 @@ public void TestMultiThreadedWrites (){ } //[Test] - public void TestMultiThreadedReads(){ - Mongo db = new Mongo(); + public void TestMultiThreadedReads(){ + Mongo db = MongoFactory.CreateMongo(); db.Connect(); List colnames = new List{"smallreads", "smallreads", "smallreads", "smallreads"}; @@ -73,8 +73,8 @@ public void TestMultiThreadedReads(){ } [Test] - public void TestMultiThreadedReadsAndWrites(){ - Mongo db = new Mongo(); + public void TestMultiThreadedReadsAndWrites(){ + Mongo db = MongoFactory.CreateMongo(); db.Connect(); IMongoCollection col = db["tests"]["threadreadinserts"]; diff --git a/MongoDB.Net-Tests/TestConnection.cs b/MongoDB.Net-Tests/TestConnection.cs index a944c984..25df15db 100644 --- a/MongoDB.Net-Tests/TestConnection.cs +++ b/MongoDB.Net-Tests/TestConnection.cs @@ -1,71 +1,71 @@ -using System; -using System.IO; -using System.Net; -using System.Net.Sockets; - -using NUnit.Framework; - -using MongoDB.Driver.IO; -using MongoDB.Driver.Bson; - -namespace MongoDB.Driver -{ - [TestFixture()] - public class TestConnection - { - [Test] - public void TestSendQueryMessage(){ - //Connection conn = new Connection("10.141.153.2"); - Connection conn = new Connection(); - conn.Open(); - - QueryMessage qmsg = generateQueryMessage(); - conn.SendTwoWayMessage(qmsg); - - conn.Close(); - } - - [Test] - public void TestReconnectOnce(){ - Connection conn = new Connection(); - conn.Open(); - - WriteBadMessage(conn); - try{ - QueryMessage qmsg = generateQueryMessage(); - conn.SendTwoWayMessage(qmsg); - - }catch(IOException){ - //Should be able to resend. - Assert.IsTrue(conn.State == ConnectionState.Opened); - QueryMessage qmsg = generateQueryMessage(); - ReplyMessage rmsg = conn.SendTwoWayMessage(qmsg); - Assert.IsNotNull(rmsg); - - } - } - - protected void WriteBadMessage(Connection conn){ - //Write a bad message to the socket to force mongo to shut down our connection. - BinaryWriter writer = new BinaryWriter(conn.Tcpclnt.GetStream()); - System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding(); - Byte[] msg = encoding.GetBytes("Goodbye MongoDB!"); - writer.Write(16 + msg.Length + 1); - writer.Write(1); - writer.Write(1); - writer.Write(1001); - writer.Write(msg); - writer.Write((byte)0); - } - - protected QueryMessage generateQueryMessage(){ +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; + +using NUnit.Framework; + +using MongoDB.Driver.IO; +using MongoDB.Driver.Bson; + +namespace MongoDB.Driver +{ + [TestFixture()] + public class TestConnection + { + [Test] + public void TestSendQueryMessage(){ + //Connection conn = new Connection("10.141.153.2"); + Connection conn = MongoFactory.CreateConnection(); + conn.Open(); + + QueryMessage qmsg = generateQueryMessage(); + conn.SendTwoWayMessage(qmsg); + + conn.Close(); + } + + [Test] + public void TestReconnectOnce(){ + Connection conn = MongoFactory.CreateConnection(); + conn.Open(); + + WriteBadMessage(conn); + try{ + QueryMessage qmsg = generateQueryMessage(); + conn.SendTwoWayMessage(qmsg); + + }catch(IOException){ + //Should be able to resend. + Assert.IsTrue(conn.State == ConnectionState.Opened); + QueryMessage qmsg = generateQueryMessage(); + ReplyMessage rmsg = conn.SendTwoWayMessage(qmsg); + Assert.IsNotNull(rmsg); + + } + } + + protected void WriteBadMessage(Connection conn){ + //Write a bad message to the socket to force mongo to shut down our connection. + BinaryWriter writer = new BinaryWriter(conn.Tcpclnt.GetStream()); + System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding(); + Byte[] msg = encoding.GetBytes("Goodbye MongoDB!"); + writer.Write(16 + msg.Length + 1); + writer.Write(1); + writer.Write(1); + writer.Write(1001); + writer.Write(msg); + writer.Write((byte)0); + } + + protected QueryMessage generateQueryMessage(){ Document qdoc = new Document(); qdoc.Add("listDatabases", 1.0); - //QueryMessage qmsg = new QueryMessage(qdoc,"system.namespaces"); - QueryMessage qmsg = new QueryMessage(qdoc,"admin.$cmd"); - qmsg.NumberToReturn = -1; - - return qmsg; - } - } + //QueryMessage qmsg = new QueryMessage(qdoc,"system.namespaces"); + QueryMessage qmsg = new QueryMessage(qdoc,"admin.$cmd"); + qmsg.NumberToReturn = -1; + + return qmsg; + } + } } \ No newline at end of file diff --git a/MongoDB.Net-Tests/TestCursor.cs b/MongoDB.Net-Tests/TestCursor.cs index a54ac37e..88d2f64f 100644 --- a/MongoDB.Net-Tests/TestCursor.cs +++ b/MongoDB.Net-Tests/TestCursor.cs @@ -10,7 +10,7 @@ namespace MongoDB.Driver [TestFixture] public class TestCursor { - Mongo db = new Mongo(); + Mongo db = MongoFactory.CreateMongo(); [Test] public void TestCanReadSmall() @@ -62,7 +62,7 @@ public void TestCanReadAndKillCursor() } [Test] - public void TestCanLimit(){ + public void TestCanLimit(){ ICursor c = db["tests"]["reads"].FindAll().Limit(5); Assert.IsNotNull(c,"Cursor shouldn't be null"); @@ -141,4 +141,4 @@ protected void cleanDB(){ } } -} +} diff --git a/MongoDB.Net-Tests/TestDatabase.cs b/MongoDB.Net-Tests/TestDatabase.cs index f3dcb169..50a7370d 100644 --- a/MongoDB.Net-Tests/TestDatabase.cs +++ b/MongoDB.Net-Tests/TestDatabase.cs @@ -7,7 +7,7 @@ namespace MongoDB.Driver [TestFixture] public class TestDatabase { - Mongo mongo = new Mongo(); + Mongo mongo = MongoFactory.CreateMongo(); Database db; [Test] diff --git a/MongoDB.Net-Tests/TestDatabaseJS.cs b/MongoDB.Net-Tests/TestDatabaseJS.cs index 89ea1d23..a6f72edb 100644 --- a/MongoDB.Net-Tests/TestDatabaseJS.cs +++ b/MongoDB.Net-Tests/TestDatabaseJS.cs @@ -8,8 +8,8 @@ namespace MongoDB.Driver{ [TestFixture()] public class TestDatabaseJS - { - Mongo db = new Mongo(); + { + Mongo db = MongoFactory.CreateMongo(); Database tests; DatabaseJS js; diff --git a/MongoDB.Net-Tests/TestDatabaseMetaData.cs b/MongoDB.Net-Tests/TestDatabaseMetaData.cs index 4fe5119f..92b7bea5 100644 --- a/MongoDB.Net-Tests/TestDatabaseMetaData.cs +++ b/MongoDB.Net-Tests/TestDatabaseMetaData.cs @@ -7,8 +7,8 @@ namespace MongoDB.Driver { [TestFixture] public class TestDatabaseMetaData - { - Mongo db = new Mongo(); + { + Mongo db = MongoFactory.CreateMongo(); [Test] public void TestCreateCollectionNoOptions(){ diff --git a/MongoDB.Net-Tests/TestMapReduce.cs b/MongoDB.Net-Tests/TestMapReduce.cs index 9103909f..09e6ab25 100644 --- a/MongoDB.Net-Tests/TestMapReduce.cs +++ b/MongoDB.Net-Tests/TestMapReduce.cs @@ -6,8 +6,8 @@ namespace MongoDB.Driver { [TestFixture()] public class TestMapReduce - { - Mongo db = new Mongo(); + { + Mongo db = MongoFactory.CreateMongo(); Database tests; Collection mrcol; string mapfunction = "function(){\n" + diff --git a/MongoDB.Net-Tests/TestMapReduceBuilder.cs b/MongoDB.Net-Tests/TestMapReduceBuilder.cs index 34393845..28d74c27 100644 --- a/MongoDB.Net-Tests/TestMapReduceBuilder.cs +++ b/MongoDB.Net-Tests/TestMapReduceBuilder.cs @@ -10,8 +10,8 @@ namespace MongoDB.Driver [TestFixture()] public class TestMapReduceBuilder - { - Mongo db = new Mongo(); + { + Mongo db = MongoFactory.CreateMongo(); Database tests; Collection mrcol; string mapfunction = "function(){\n" + diff --git a/MongoDB.Net-Tests/TestMongo.cs b/MongoDB.Net-Tests/TestMongo.cs index 5637c802..818fa79c 100644 --- a/MongoDB.Net-Tests/TestMongo.cs +++ b/MongoDB.Net-Tests/TestMongo.cs @@ -22,8 +22,8 @@ public void TestDefaults() } [Test()] - public void TestExplicitConnection(){ - Mongo m = new Mongo(); + public void TestExplicitConnection(){ + Mongo m = MongoFactory.CreateMongo(); Assert.IsTrue(m.Connect()); } diff --git a/MongoDB.Net-Tests/TestPairedConnection.cs b/MongoDB.Net-Tests/TestPairedConnection.cs index f87aba0a..fab0f587 100644 --- a/MongoDB.Net-Tests/TestPairedConnection.cs +++ b/MongoDB.Net-Tests/TestPairedConnection.cs @@ -7,20 +7,20 @@ namespace MongoDB.Driver { [TestFixture] public class TestPairedConnection - { - private int DefaultMasterPort = Connection.DEFAULTPORT + 1; - private int DefaultSlavePort = Connection.DEFAULTPORT + 2; + { + private int DefaultMasterPort = MongoFactory.Port + 1; + private int DefaultSlavePort = MongoFactory.Port + 2; [Test] - public void TestConnectingToNonPaired(){ - PairedConnection pc = new PairedConnection(Connection.DEFAULTHOST,Connection.DEFAULTPORT, Connection.DEFAULTHOST, DefaultSlavePort); + public void TestConnectingToNonPaired(){ + PairedConnection pc = new PairedConnection(MongoFactory.Host, MongoFactory.Port, MongoFactory.Host, DefaultSlavePort); pc.Open(); Assert.AreEqual(ConnectionState.Opened, pc.State); Assert.IsFalse(pc.Paired); } [Test] - public void TestConnectingToMasterReplica(){ - PairedConnection pc = new PairedConnection(Connection.DEFAULTHOST,DefaultMasterPort, Connection.DEFAULTHOST, DefaultSlavePort); + public void TestConnectingToMasterReplica(){ + PairedConnection pc = new PairedConnection(MongoFactory.Host, DefaultMasterPort, MongoFactory.Host, DefaultSlavePort); pc.Open(); Assert.AreEqual(ConnectionState.Opened, pc.State); Assert.IsTrue(pc.Paired); @@ -28,8 +28,8 @@ public void TestConnectingToMasterReplica(){ } [Test] - public void TestConnectingToSlaveOk(){ - PairedConnection pc = new PairedConnection(Connection.DEFAULTHOST,DefaultSlavePort, Connection.DEFAULTHOST, DefaultMasterPort,true); + public void TestConnectingToSlaveOk(){ + PairedConnection pc = new PairedConnection(MongoFactory.Host, DefaultSlavePort, MongoFactory.Host, DefaultMasterPort, true); pc.Open(); Assert.AreEqual(ConnectionState.Opened, pc.State); Assert.IsTrue(pc.Paired); @@ -37,8 +37,8 @@ public void TestConnectingToSlaveOk(){ } [Test] - public void TestConnectingToSlaveNotOk(){ - PairedConnection pc = new PairedConnection(Connection.DEFAULTHOST,DefaultSlavePort, Connection.DEFAULTHOST, DefaultMasterPort,false); + public void TestConnectingToSlaveNotOk(){ + PairedConnection pc = new PairedConnection(MongoFactory.Host, DefaultSlavePort, MongoFactory.Host, DefaultMasterPort, false); pc.Open(); Assert.AreEqual(ConnectionState.Opened, pc.State); Assert.IsTrue(pc.Paired); @@ -47,8 +47,8 @@ public void TestConnectingToSlaveNotOk(){ [Test] public void TestConnectingToDownMaster(){ - int badport = 33333; - PairedConnection pc = new PairedConnection(Connection.DEFAULTHOST,badport, Connection.DEFAULTHOST, DefaultMasterPort,false); + int badport = 33333; + PairedConnection pc = new PairedConnection(MongoFactory.Host, badport, MongoFactory.Host, DefaultMasterPort, false); pc.Open(); Assert.AreEqual(ConnectionState.Opened, pc.State); Assert.IsTrue(pc.Paired); @@ -62,8 +62,8 @@ public void TestConnectingToDownBothThrowsException(){ * SocketException catches. If the PairedConnection.Open method is changed to * screw that up it will cause an infinite loop. */ - int badport = 33333; - PairedConnection pc = new PairedConnection(Connection.DEFAULTHOST,badport, Connection.DEFAULTHOST, badport); + int badport = 33333; + PairedConnection pc = new PairedConnection(MongoFactory.Host, badport, MongoFactory.Host, badport); bool thrown = false; try{ pc.Open(); @@ -75,8 +75,8 @@ public void TestConnectingToDownBothThrowsException(){ [Test] public void TestConnectingToSlaveUsingBadMasterInfoThrowsException(){ - int badport = 33333; - PairedConnection pc = new PairedConnection(Connection.DEFAULTHOST, DefaultSlavePort, Connection.DEFAULTHOST, badport, false); + int badport = 33333; + PairedConnection pc = new PairedConnection(MongoFactory.Host, DefaultSlavePort, MongoFactory.Host, badport, false); bool thrown = false; try{ pc.Open(); diff --git a/MongoDBDriver/Connection.cs b/MongoDBDriver/Connection.cs index 58673cd3..ae19bc2a 100644 --- a/MongoDBDriver/Connection.cs +++ b/MongoDBDriver/Connection.cs @@ -98,8 +98,8 @@ public void SendMessage(RequestMessage msg){ }catch(IOException){//Sending doesn't seem to always trigger the detection of a closed socket. this.Reconnect(); throw; - } - } + } + } /// /// Just sends a simple message string to the database. diff --git a/MongoDBDriver/MongoDB.Driver.csproj b/MongoDBDriver/MongoDB.Driver.csproj index fe181eb9..10114d05 100644 --- a/MongoDBDriver/MongoDB.Driver.csproj +++ b/MongoDBDriver/MongoDB.Driver.csproj @@ -1,4 +1,4 @@ - + Debug @@ -66,6 +66,7 @@ + @@ -96,6 +97,7 @@ + @@ -130,7 +132,4 @@ - - - - + \ No newline at end of file diff --git a/MongoDBDriver/MongoFactory.cs b/MongoDBDriver/MongoFactory.cs new file mode 100644 index 00000000..80223a3c --- /dev/null +++ b/MongoDBDriver/MongoFactory.cs @@ -0,0 +1,23 @@ +using System.Configuration; + +namespace MongoDB.Driver { + public static class MongoFactory { + + public static string Host; + public static int Port; + static MongoFactory() { + Host = ConfigurationManager.AppSettings["mongo.host"] ?? Connection.DEFAULTHOST; + if(!int.TryParse(ConfigurationManager.AppSettings["mongo.port"], out Port)) { + Port = Connection.DEFAULTPORT; + } + } + + public static Mongo CreateMongo() { + return new Mongo(Host, Port); + } + + public static Connection CreateConnection() { + return new Connection(Host, Port); + } + } +}