Skip to content

Commit

Permalink
Account for difference between Mono and .Net in Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Corder authored and Samuel Corder committed Mar 18, 2010
1 parent c71b7ba commit 2b8934f
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 121 deletions.
77 changes: 38 additions & 39 deletions 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));
}

}
}
122 changes: 61 additions & 61 deletions 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);
}
}
}
}
42 changes: 21 additions & 21 deletions 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.