Skip to content
Browse files

Extracted the ICouchServer interface to improve decoupling and testab…

…ility.
  • Loading branch information...
1 parent 43da099 commit 87f011d0dd48d02900ca4f02f31aaf293df7c21a Sebastian Negomireanu committed Dec 10, 2009
View
4 Tests/Autoreconcile/CouchAutoreconcileTest.cs
@@ -160,8 +160,8 @@ public void ShouldCauseConflictOnNewDoc()
db.SaveDocument(doc2);
}
- private CouchServer server;
- private CouchDatabase db;
+ private ICouchServer server;
+ private ICouchDatabase db;
private string DbName;
private static string GetNewDbName()
View
4 Tests/CouchTest.cs
@@ -51,8 +51,8 @@ public void TearDown()
#endregion
- private CouchServer server;
- private CouchDatabase db;
+ private ICouchServer server;
+ private ICouchDatabase db;
private string DbName;
private static string GetNewDbName()
View
4 Tests/Lucene/CouchLuceneTest.cs
@@ -42,8 +42,8 @@ public void TearDown()
#endregion
- private CouchServer server;
- private CouchDatabase db;
+ private ICouchServer server;
+ private ICouchDatabase db;
private string DbName { get { return "divan_lucene_unit_tests" + DateTime.Now.Ticks; } }
View
4 src/CouchDesignDocument.cs
@@ -18,9 +18,9 @@ public class CouchDesignDocument : CouchDocument, IEquatable<CouchDesignDocument
public IList<CouchLuceneViewDefinition> LuceneDefinitions = new List<CouchLuceneViewDefinition>();
public string Language = "javascript";
- public CouchDatabase Owner;
+ public ICouchDatabase Owner;
- public CouchDesignDocument(string documentId, CouchDatabase owner)
+ public CouchDesignDocument(string documentId, ICouchDatabase owner)
: base("_design/" + documentId)
{
Owner = owner;
View
16 src/CouchServer.cs
@@ -15,7 +15,7 @@ namespace Divan
/// One nice approach is to create a specific subclass that knows about its databases.
/// DatabasePrefix can be used to separate all databases created from other CouchDB databases.
/// </summary>
- public class CouchServer
+ public class CouchServer : Divan.ICouchServer
{
public bool RunningOnMono = Type.GetType("Mono.Runtime") != null;
@@ -96,7 +96,7 @@ public bool HasDatabase(string name)
/// Get a CouchDatabase with given name.
/// We create the database if it does not exist.
/// </summary>
- public CouchDatabase GetDatabase(string name)
+ public ICouchDatabase GetDatabase(string name)
{
return GetDatabase<CouchDatabase>(name);
}
@@ -106,7 +106,7 @@ public CouchDatabase GetDatabase(string name)
/// We check if the database exists and delete
/// it if it does, then we recreate it.
/// </summary>
- public CouchDatabase GetNewDatabase(string name)
+ public ICouchDatabase GetNewDatabase(string name)
{
return GetNewDatabase<CouchDatabase>(name);
}
@@ -116,7 +116,7 @@ public CouchDatabase GetNewDatabase(string name)
/// We check if the database exists and delete it if it does,
/// then we recreate it.
/// </summary>
- public T GetNewDatabase<T>(string name) where T : CouchDatabase, new()
+ public T GetNewDatabase<T>(string name) where T : ICouchDatabase, new()
{
var db = new T { Name = name, Server = this };
if (db.Exists())
@@ -131,7 +131,7 @@ public T GetNewDatabase<T>(string name) where T : CouchDatabase, new()
/// Get specialized subclass of CouchDatabase. That class should
/// define its own database name. We presume it is already created.
/// </summary>
- public T GetExistingDatabase<T>() where T : CouchDatabase, new()
+ public T GetExistingDatabase<T>() where T : ICouchDatabase, new()
{
return new T {Server = this};
}
@@ -140,7 +140,7 @@ public T GetExistingDatabase<T>() where T : CouchDatabase, new()
/// Get specialized subclass of CouchDatabase with given name.
/// We presume it is already created.
/// </summary>
- public T GetExistingDatabase<T>(string name) where T : CouchDatabase, new()
+ public T GetExistingDatabase<T>(string name) where T : ICouchDatabase, new()
{
return new T {Name = name, Server = this};
}
@@ -149,7 +149,7 @@ public T GetExistingDatabase<T>(string name) where T : CouchDatabase, new()
/// Get specialized subclass of CouchDatabase. That class should
/// define its own database name. We ensure that it is created.
/// </summary>
- public T GetDatabase<T>() where T : CouchDatabase, new()
+ public T GetDatabase<T>() where T : ICouchDatabase, new()
{
var db = GetExistingDatabase<T>();
db.Create();
@@ -160,7 +160,7 @@ public T GetDatabase<T>() where T : CouchDatabase, new()
/// Get specialized subclass of CouchDatabase with given name.
/// We ensure that it is created.
/// </summary>
- public T GetDatabase<T>(string name) where T : CouchDatabase, new()
+ public T GetDatabase<T>(string name) where T : ICouchDatabase, new()
{
var db = GetExistingDatabase<T>(name);
db.Create();
View
1 src/Divan.csproj
@@ -68,6 +68,7 @@
<Compile Include="ICanJson.cs" />
<Compile Include="ICouchDatabase.cs" />
<Compile Include="ICouchDocument.cs" />
+ <Compile Include="ICouchServer.cs" />
<Compile Include="ICouchViewDefinition.cs" />
<Compile Include="ICouchViewDefinitionBase.cs" />
<Compile Include="Lucene\CouchLuceneHit.cs" />
View
23 src/ICouchServer.cs
@@ -0,0 +1,23 @@
+using System;
+namespace Divan
+{
+ public interface ICouchServer
+ {
+ void CreateDatabase(string name);
+ void Debug(string message);
+ void DeleteAllDatabases();
+ void DeleteDatabase(string name);
+ void DeleteDatabases(string regExp);
+ T GetDatabase<T>(string name) where T : ICouchDatabase, new();
+ ICouchDatabase GetDatabase(string name);
+ T GetDatabase<T>() where T : ICouchDatabase, new();
+ System.Collections.Generic.IList<string> GetDatabaseNames();
+ T GetExistingDatabase<T>() where T : ICouchDatabase, new();
+ T GetExistingDatabase<T>(string name) where T : ICouchDatabase, new();
+ ICouchDatabase GetNewDatabase(string name);
+ T GetNewDatabase<T>(string name) where T : ICouchDatabase, new();
+ bool HasDatabase(string name);
+ CouchRequest Request();
+ string ServerName { get; }
+ }
+}

0 comments on commit 87f011d

Please sign in to comment.
Something went wrong with that request. Please try again.