public void AsynchronousTest3()
        {
            _mongoServerConnection = new ServerConnection(MONGO_CONNECTION_STRING_BAD);
            _mongoServerConnection.ConnectAsyncDelegate(_mongoServerConnection_Connected);
            _serverConnectionAutoResetEvent.WaitOne();

            Assert.AreEqual(ConnectionResult.Failure, _serverConnectionResult);
            Assert.IsTrue(_mongoServerConnection.State == MongoServerState.Disconnected);
            Assert.AreEqual("The operation has timed out.",_serverConnectionReturnMessage);
        }
 public void AsynchronousTest1()
 {
     _mongoServerConnection = new ServerConnection(MONGO_CONNECTION_STRING);
     Assert.AreEqual(MongoServerState.Disconnected, _mongoServerConnection.State);
     Assert.AreEqual(ConnectionResult.Empty,_serverConnectionResult);
     _mongoServerConnection.ConnectAsyncDelegate(_mongoServerConnection_Connected);
     Assert.AreEqual(MongoServerState.Disconnected, _mongoServerConnection.State);
     Assert.AreEqual(ConnectionResult.Empty, _serverConnectionResult);
     _serverConnectionAutoResetEvent.WaitOne();
     Assert.AreEqual(MongoServerState.Connected, _mongoServerConnection.State);/**/
     Assert.AreEqual(ConnectionResult.Success, _serverConnectionResult);/**/
     Assert.IsNotNull(_serverConnectionReturnMessage);
 }
        public void AsynchronousTest2()
        {
            _mongoServerConnection = new ServerConnection(MONGO_CONNECTION_STRING);
            Assert.AreEqual(ConnectionResult.Empty, _serverConnectionResult);
            _mongoServerConnection.ConnectAsyncDelegate(_mongoServerConnection_Connected);
            _serverConnectionAutoResetEvent.WaitOne();
            List<string> returned = _mongoServerConnection.GetDbNamesForConnection();
            Assert.AreEqual(ConnectionResult.Success, _serverConnectionResult);
            Assert.IsTrue(_mongoServerConnection.State == MongoServerState.Connected);
            Assert.IsNotNull(_serverConnectionReturnMessage);

            Assert.AreEqual(0, returned.Count(),"no database names since nothing has been written yet");
            AddMongoEntry();

            returned = _mongoServerConnection.GetDbNamesForConnection();

            Assert.AreEqual(1, returned.Count(), "only the driver-created database, local, should exist");
            Assert.AreEqual(MONGO_DATABASE_1_NAME, returned[0]);
        }
        public void AsynchronousTest4()
        {
            //System.Diagnostics.Debugger.Launch();
            // create our asynchronous server connection
            _mongoServerConnection = new ServerConnection(MONGO_CONNECTION_STRING);
            _mongoDatabaseConnection = new DatabaseConnection(_mongoServerConnection, MONGO_DATABASE_1_NAME);

            // testBase class receives the connection call back after the asynch connection occurs
            _mongoServerConnection.ConnectAsyncDelegate(_mongoServerConnection_Connected);
            _mongoDatabaseConnection.ConnectAsyncDelegate(_mongoDatabaseConnection_Connected);

            _databaseConnectionAutoResetEvent.WaitOne();

            MongoCollection<Entry> collection = _mongoDatabaseConnection.GetCollection<Entry>(MONGO_COLLECTION_1_NAME);
            Assert.AreEqual(MongoServerState.Connected, _mongoServerConnection.State);
            Assert.AreEqual(MongoServerState.Connected, _mongoDatabaseConnection.State);
            Assert.IsNotNull(_serverConnectionReturnMessage);
            Assert.IsNotNull(_databaseConnectionReturnMessage);
            Assert.AreEqual(0, collection.Count());
        }
        public void Asynchronous_GetInsertedTest2()
        {
            //System.Diagnostics.Debugger.Launch();
            string entryMessage = "Hello World";
            AddMongoEntry(message: entryMessage);

            // create our asynchronous server connection
            _mongoServerConnection = new ServerConnection(MONGO_CONNECTION_STRING);
            _mongoDatabaseConnection = new DatabaseConnection(_mongoServerConnection, MONGO_DATABASE_1_NAME);
            // testBase class receives the connection call back after the asynch connection occurs
            _mongoServerConnection.ConnectAsyncDelegate(_mongoServerConnection_Connected);
            _mongoDatabaseConnection.ConnectAsyncDelegate(_mongoDatabaseConnection_Connected);

            _databaseConnectionAutoResetEvent.WaitOne();// pause here until the asyncConnection completes to allow for linear testability

            Assert.AreEqual(ConnectionResult.Success, _databaseConnectionResult);/**/
            Assert.AreEqual(MongoServerState.Connected, _mongoDatabaseConnection.State);
            Assert.IsNotNull(_serverConnectionReturnMessage);
            Assert.IsNotNull(_databaseConnectionReturnMessage);

            _reader = new Reader(_mongoDatabaseConnection);

            // this call doesn't wait for asynchronous connection to finish
            _results.AddRange(_reader.Read<Entry>(MONGO_COLLECTION_1_NAME, "Message", entryMessage, "TimeStamp", _beforeTest, DateTime.Now));

            Assert.AreEqual(1, _results.Count());
        }

        [Test]
        public void BadConnectionStringAsync()
        {
            //System.Diagnostics.Debugger.Launch();
            _mongoServerConnection = new ServerConnection(MONGO_CONNECTION_STRING_BAD);

            _mongoDatabaseConnection = new DatabaseConnection(_mongoServerConnection, MONGO_DATABASE_1_NAME);
            Assert.AreEqual(MongoServerState.Disconnected, _mongoDatabaseConnection.State);
            _mongoDatabaseConnection.ConnectAsyncDelegate(_mongoDatabaseConnection_Connected);
            Assert.AreEqual(MongoServerState.Disconnected, _mongoDatabaseConnection.State);

            _databaseConnectionAutoResetEvent.WaitOne(); // wait for the async operation to complete to verify it's results

            Assert.AreEqual(MongoServerState.Disconnected, _mongoDatabaseConnection.State);/**/
            Assert.AreEqual(ConnectionResult.Failure, _databaseConnectionResult);/**/
            Assert.IsNotNull(_serverConnectionReturnMessage);
        }