Browse files

Account for difference between Mono and .Net in Configuration

  • Loading branch information...
1 parent c71b7ba commit 2b8934fa7d88373d97eabe39b2558b03ac31e082 Samuel Corder committed Mar 17, 2010
View
77 MongoDB.GridFS.Tests/GridTestBase.cs 100644 → 100755
@@ -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
- {
- /// <summary>
- /// Comma separated list of collections to clean at startup.
- /// </summary>
- public abstract string TestFileSystems{get;}
-
- /// <summary>
- /// Turns the TestFileSystems string into a comma delimited set of collections
- /// </summary>
- 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
+ {
+ /// <summary>
+ /// Comma separated list of collections to clean at startup.
+ /// </summary>
+ public abstract string TestFileSystems{get;}
+
+ /// <summary>
+ /// Turns the TestFileSystems string into a comma delimited set of collections
+ /// </summary>
+ 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));
+ }
+
+ }
+}
View
122 MongoDB.Net-Tests/MongoTestBase.cs 100644 → 100755
@@ -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"];
- }
- }
-
- /// <summary>
- /// Comma separated list of collections to clean at startup.
- /// </summary>
- public abstract string TestCollections{get;}
-
-
- /// <summary>
- /// Override to add custom initialization code.
- /// </summary>
- public virtual void OnInit(){}
-
- /// <summary>
- /// Override to add custom code to invoke during the test end.
- /// </summary>
- public virtual void OnDispose(){}
-
-
- /// <summary>
- /// Sets up the test environment. You can either override this OnInit to add custom initialization.
- /// </summary>
- [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"];
+ }
+ }
+
+ /// <summary>
+ /// Comma separated list of collections to clean at startup.
+ /// </summary>
+ public abstract string TestCollections{get;}
+
+
+ /// <summary>
+ /// Override to add custom initialization code.
+ /// </summary>
+ public virtual void OnInit(){}
+
+ /// <summary>
+ /// Override to add custom code to invoke during the test end.
+ /// </summary>
+ public virtual void OnDispose(){}
+
+
+ /// <summary>
+ /// Sets up the test environment. You can either override this OnInit to add custom initialization.
+ /// </summary>
+ [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);
+ }
+ }
+ }
}
View
42 MongoDBDriver/Configuration/ConnectionElement.cs 100644 → 100755
@@ -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; }
+ }
+ }
+}

0 comments on commit 2b8934f

Please sign in to comment.