Fork me on GitHub

Tearing Down Document Storage Edit on GitHub

For the purpose of automated testing where you need to carefully control the state of the document storage, Marten supplies the IDocumentCleaner service to quickly remove persisted document state or even to completely tear down the entire document storage.

This service is exposed as the IDocumentStore.Advanced.Clean property. You can see the usages of the document cleaner below:

public void clean_out_documents(IDocumentStore store)
    // Completely remove all the database schema objects related
    // to the User document type

    // Tear down and remove all Marten related database schema objects

    // Deletes all the documents stored in a Marten database

    // Deletes all of the persisted User documents

    // For cases where you may want to keep some document types,
    // but eliminate everything else. This is here specifically to support
    // automated testing scenarios where you have some static data that can
    // be safely reused across tests
    store.Advanced.Clean.DeleteDocumentsExcept(typeof(Company), typeof(User));