forked from samus/mongodb-csharp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Account for difference between Mono and .Net in Configuration
- Loading branch information
Samuel Corder
authored and
Samuel Corder
committed
Mar 18, 2010
1 parent
c71b7ba
commit 2b8934f
Showing
3 changed files
with
120 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |
42 changes: 21 additions & 21 deletions
42
MongoDBDriver/Configuration/ConnectionElement.cs
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} | ||
} |