From 2b8934fa7d88373d97eabe39b2558b03ac31e082 Mon Sep 17 00:00:00 2001 From: Samuel Corder Date: Wed, 17 Mar 2010 22:21:00 -0400 Subject: [PATCH] Account for difference between Mono and .Net in Configuration --- MongoDB.GridFS.Tests/GridTestBase.cs | 77 ++++++----- MongoDB.Net-Tests/MongoTestBase.cs | 122 +++++++++--------- .../Configuration/ConnectionElement.cs | 42 +++--- 3 files changed, 120 insertions(+), 121 deletions(-) mode change 100644 => 100755 MongoDB.GridFS.Tests/GridTestBase.cs mode change 100644 => 100755 MongoDB.Net-Tests/MongoTestBase.cs mode change 100644 => 100755 MongoDBDriver/Configuration/ConnectionElement.cs diff --git a/MongoDB.GridFS.Tests/GridTestBase.cs b/MongoDB.GridFS.Tests/GridTestBase.cs old mode 100644 new mode 100755 index 15ba38c0..221124ab --- a/MongoDB.GridFS.Tests/GridTestBase.cs +++ b/MongoDB.GridFS.Tests/GridTestBase.cs @@ -1,39 +1,38 @@ -using System; -using System.Configuration; -using System.Text; - -using NUnit.Framework; - -using MongoDB.Driver; - -namespace MongoDB.GridFS -{ - public abstract class GridTestBase : MongoTestBase - { - /// - /// Comma separated list of collections to clean at startup. - /// - public abstract string TestFileSystems{get;} - - /// - /// Turns the TestFileSystems string into a comma delimited set of collections - /// - public override string TestCollections { - get { - StringBuilder sb = new StringBuilder(); - foreach(string fs in this.TestFileSystems.Split(',')){ - sb.Append(fs + ".files,"); - sb.Append(fs + ".chunks,"); - } - sb.Remove(sb.Length - 1,1); //remove last , - Console.WriteLine(sb.ToString()); - return sb.ToString(); - } - } - - public long CountChunks(string filesystem, Object fileid){ - return DB[filesystem + ".chunks"].Count(new Document().Append("files_id", fileid)); - } - - } -} +using System; +using System.Configuration; +using System.Text; + +using NUnit.Framework; + +using MongoDB.Driver; + +namespace MongoDB.GridFS +{ + public abstract class GridTestBase : MongoTestBase + { + /// + /// Comma separated list of collections to clean at startup. + /// + public abstract string TestFileSystems{get;} + + /// + /// Turns the TestFileSystems string into a comma delimited set of collections + /// + public override string TestCollections { + get { + StringBuilder sb = new StringBuilder(); + foreach(string fs in this.TestFileSystems.Split(',')){ + sb.Append(fs + ".files,"); + sb.Append(fs + ".chunks,"); + } + sb.Remove(sb.Length - 1,1); //remove last , + return sb.ToString(); + } + } + + public long CountChunks(string filesystem, Object fileid){ + return DB[filesystem + ".chunks"].Count(new Document().Append("files_id", fileid)); + } + + } +} diff --git a/MongoDB.Net-Tests/MongoTestBase.cs b/MongoDB.Net-Tests/MongoTestBase.cs old mode 100644 new mode 100755 index 35bec14e..f0bdf3e2 --- a/MongoDB.Net-Tests/MongoTestBase.cs +++ b/MongoDB.Net-Tests/MongoTestBase.cs @@ -1,62 +1,62 @@ -using System; -using System.Configuration; - -using NUnit.Framework; - -namespace MongoDB.Driver -{ - - public abstract class MongoTestBase - { - public Mongo Mongo{get;set;} - public Database DB{ - get{ - return this.Mongo["tests"]; - } - } - - /// - /// Comma separated list of collections to clean at startup. - /// - public abstract string TestCollections{get;} - - - /// - /// Override to add custom initialization code. - /// - public virtual void OnInit(){} - - /// - /// Override to add custom code to invoke during the test end. - /// - public virtual void OnDispose(){} - - - /// - /// Sets up the test environment. You can either override this OnInit to add custom initialization. - /// - [TestFixtureSetUp] - public virtual void Init(){ - string connstr = ConfigurationManager.AppSettings["tests"]; - if(String.IsNullOrEmpty(connstr)) throw new ArgumentNullException("Connection string not found."); - this.Mongo = new Mongo(connstr); - this.Mongo.Connect(); - CleanDB(); - OnInit(); - } - - - [TestFixtureTearDown] - public virtual void Dispose(){ - OnDispose(); - this.Mongo.Disconnect(); - } - - protected void CleanDB(){ - foreach(string col in this.TestCollections.Split(',')){ - DB["$cmd"].FindOne(new Document(){{"drop", col.Trim()}}); - Console.WriteLine("Dropping " + col); - } - } - } +using System; +using System.Configuration; + +using NUnit.Framework; + +namespace MongoDB.Driver +{ + + public abstract class MongoTestBase + { + public Mongo Mongo{get;set;} + public Database DB{ + get{ + return this.Mongo["tests"]; + } + } + + /// + /// Comma separated list of collections to clean at startup. + /// + public abstract string TestCollections{get;} + + + /// + /// Override to add custom initialization code. + /// + public virtual void OnInit(){} + + /// + /// Override to add custom code to invoke during the test end. + /// + public virtual void OnDispose(){} + + + /// + /// Sets up the test environment. You can either override this OnInit to add custom initialization. + /// + [TestFixtureSetUp] + public virtual void Init(){ + string connstr = ConfigurationManager.AppSettings["tests"]; + if(String.IsNullOrEmpty(connstr)) throw new ArgumentNullException("Connection string not found."); + this.Mongo = new Mongo(connstr); + this.Mongo.Connect(); + CleanDB(); + OnInit(); + } + + + [TestFixtureTearDown] + public virtual void Dispose(){ + OnDispose(); + this.Mongo.Disconnect(); + } + + protected void CleanDB(){ + foreach(string col in this.TestCollections.Split(',')){ + DB["$cmd"].FindOne(new Document(){{"drop", col.Trim()}}); + //Console.WriteLine("Dropping " + col); + } + } + } } \ No newline at end of file diff --git a/MongoDBDriver/Configuration/ConnectionElement.cs b/MongoDBDriver/Configuration/ConnectionElement.cs old mode 100644 new mode 100755 index 0a6a4d5c..6821ec18 --- a/MongoDBDriver/Configuration/ConnectionElement.cs +++ b/MongoDBDriver/Configuration/ConnectionElement.cs @@ -1,21 +1,21 @@ -using System; -using System.Configuration; - -namespace MongoDB.Driver.Configuration -{ - - public class ConnectionElement : ConfigurationElement - { - [ConfigurationProperty("key", IsRequired = true)] - public string Name{ - get{return (String)this["key"];} - set{this["key"] = value;} - } - - [ConfigurationProperty("connectionString", DefaultValue = "Server=localhost:27017", IsRequired = true)] - public string ConnectionString{ - get { return (String)this["connectionString"]; } - set { this["connectionString"] = value; } - } - } -} +using System; +using System.Configuration; + +namespace MongoDB.Driver.Configuration +{ + + public class ConnectionElement : ConfigurationElement + { + [ConfigurationProperty("key", IsRequired = true)] + public string Name{ + get{return (String)this["key"];} + set{this["key"] = value;} + } + + [ConfigurationProperty("connectionString", DefaultValue = "Server=localhost:27017")] + public string ConnectionString{ + get { return (String)this["connectionString"]; } + set { this["connectionString"] = value; } + } + } +}