Skip to content

Commit

Permalink
Restructuring a bit of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Sep 10, 2012
1 parent 7636332 commit 1b7eb3b
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Raven.Tests/Indexes/CompiledIndex.cs
Expand Up @@ -24,7 +24,7 @@ public CompiledIndex()
{
store =

NewDocumentStore(new AggregateCatalog
NewDocumentStore(catalog:new AggregateCatalog
{Catalogs = {new TypeCatalog(typeof (ShoppingCartEventsToShopingCart), typeof (MapOnlyView))}});
db = store.DocumentDatabase;
}
Expand Down
4 changes: 2 additions & 2 deletions Raven.Tests/Issues/RavenDB_295.cs
Expand Up @@ -55,7 +55,7 @@ public void CanUpdateSuggestions()
[Fact]
public void CanUpdateSuggestions_AfterRestart()
{
using (var store = NewDocumentStore())
using (var store = NewDocumentStore(deleteDirectoryOnDispose: false))
{
using (var session = store.OpenSession())
{
Expand All @@ -78,7 +78,7 @@ public void CanUpdateSuggestions_AfterRestart()
});
Assert.NotEmpty(suggestionQueryResult.Suggestions);
}
using (var store = NewDocumentStoreRestart())
using (var store = NewDocumentStore(deleteDirectoryOnDispose: true, deleteDirectory: false))
{
using (var session = store.OpenSession())
{
Expand Down
39 changes: 14 additions & 25 deletions Raven.Tests/RavenTest.cs
Expand Up @@ -46,24 +46,11 @@ static RavenTest()
File.Delete("test.log");
}

public EmbeddableDocumentStore NewDocumentStoreRestart(string requestedStorage = null)
{
return NewDocumentStoreInternal(deleteDirectory: false, requestedStorage: requestedStorage);
}

public EmbeddableDocumentStore NewDocumentStore(string requestedStorage = null)
{
return NewDocumentStoreInternal(deleteDirectory: true, requestedStorage: requestedStorage);
}

public EmbeddableDocumentStore NewDocumentStore(ComposablePartCatalog catalog, string requestedStorage = null)
{
return NewDocumentStoreInternal(deleteDirectory: true, catalog: catalog, requestedStorage: requestedStorage);
}

private EmbeddableDocumentStore NewDocumentStoreInternal(bool deleteDirectory,
string requestedStorage,
ComposablePartCatalog catalog = null)
public EmbeddableDocumentStore NewDocumentStore(
bool deleteDirectory = true,
string requestedStorage = null,
ComposablePartCatalog catalog = null,
bool deleteDirectoryOnDispose = true)
{
path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase);
path = Path.Combine(path, "TestDb").Substring(6);
Expand Down Expand Up @@ -97,13 +84,15 @@ public EmbeddableDocumentStore NewDocumentStore(ComposablePartCatalog catalog, s

CreateDefaultIndexes(documentStore);

if (deleteDirectoryOnDispose)
documentStore.Disposed += ClearDatabaseDirectory;

return documentStore;
}
catch
{
// We must dispose of this object in exceptional cases, otherwise this test will break all the following tests.
if (documentStore != null)
documentStore.Dispose();
documentStore.Dispose();
throw;
}
}
Expand Down Expand Up @@ -328,9 +317,6 @@ protected void ClearDatabaseDirectory()
{
IOExtensions.DeleteDirectory(DbName);
IOExtensions.DeleteDirectory(DbDirectory);

// Delete tenants created using the EnsureDatabaseExists method.
IOExtensions.DeleteDirectory("Tenants");
break;
}
catch (IOException)
Expand Down Expand Up @@ -362,14 +348,17 @@ public IDocumentStore NewRemoteDocumentStore()
Url = "http://localhost:8079"
};

store.AfterDispose += (sender, args) => ravenDbServer.Dispose();
store.AfterDispose += (sender, args) =>
{
ravenDbServer.Dispose();
ClearDatabaseDirectory();
};
ModifyStore(store);
return store.Initialize();
}

public virtual void Dispose()
{
ClearDatabaseDirectory();
GC.Collect(2);
GC.WaitForPendingFinalizers();
}
Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Triggers/AttachmentDeleteTrigger.cs
Expand Up @@ -23,7 +23,7 @@ public class AttachmentDeleteTrigger: RavenTest

public AttachmentDeleteTrigger()
{
store = NewDocumentStore((new TypeCatalog(typeof (RefuseAttachmentDeleteTrigger))));
store = NewDocumentStore(catalog:(new TypeCatalog(typeof (RefuseAttachmentDeleteTrigger))));
db = store.DocumentDatabase;
}

Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Triggers/AttachmentPutTriggers.cs
Expand Up @@ -23,7 +23,7 @@ public class AttachmentPutTriggers: RavenTest

public AttachmentPutTriggers()
{
store = NewDocumentStore((new TypeCatalog(typeof (AuditAttachmentPutTrigger), typeof(RefuseBigAttachmentPutTrigger))));
store = NewDocumentStore(catalog:(new TypeCatalog(typeof (AuditAttachmentPutTrigger), typeof(RefuseBigAttachmentPutTrigger))));
db = store.DocumentDatabase;
}

Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Triggers/AttachmentReadTrigger.cs
Expand Up @@ -24,7 +24,7 @@ public class AttachmentReadTrigger : RavenTest

public AttachmentReadTrigger()
{
store = NewDocumentStore((new TypeCatalog(typeof (HideAttachmentByCaseReadTrigger))));
store = NewDocumentStore(catalog:(new TypeCatalog(typeof (HideAttachmentByCaseReadTrigger))));
db = store.DocumentDatabase;
}

Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Triggers/DeleteTriggers.cs
Expand Up @@ -20,7 +20,7 @@ public class DeleteTriggers : RavenTest

public DeleteTriggers()
{
store = NewDocumentStore((new TypeCatalog(typeof (CascadeDeleteTrigger))));
store = NewDocumentStore( catalog: (new TypeCatalog(typeof (CascadeDeleteTrigger))));
db = store.DocumentDatabase;
}

Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Triggers/IndexTriggers.cs
Expand Up @@ -22,7 +22,7 @@ public class IndexTriggers : RavenTest

public IndexTriggers()
{
store = NewDocumentStore((new TypeCatalog(typeof(IndexToDataTable))));
store = NewDocumentStore(catalog:(new TypeCatalog(typeof(IndexToDataTable))));
}

public override void Dispose()
Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Triggers/PutTriggers.cs
Expand Up @@ -22,7 +22,7 @@ public class PutTriggers : RavenTest

public PutTriggers()
{
store = NewDocumentStore((new TypeCatalog(typeof (VetoCapitalNamesPutTrigger), typeof(AuditPutTrigger))));
store = NewDocumentStore(catalog:(new TypeCatalog(typeof (VetoCapitalNamesPutTrigger), typeof(AuditPutTrigger))));
db = store.DocumentDatabase;
}

Expand Down

0 comments on commit 1b7eb3b

Please sign in to comment.