0

Here is the information about my development environment:

MongoDB 3.0.0

MongoDB C# Driver Version 1.7.0.4714

Microsoft Visual Studio Professional 2013

.NET Framework 4.0

We are about to do our first production release. We developed the application using the Domain-Driven Design approach. Unfortunately, we did Not write any unit test cases.

We haven't really adhered to proper coding practices that would allow for flexibility int the future. For example, in the following code we have Not used an Interface for the Database connectivity, but we have just directly instantiated the Database connectivity class:

public class BLLCs_BookStore_Catalog : ICs_BookStore_Catalog
{

    public IEnumerable<ELLCsBook> GetAParticularBook(ObjectId BookIdArg)
    {
        IMongoQuery qry = Query<ELLCsBook>.EQ(l => l.Id, BookIdArg);
        return DBConnection.database.GetCollection<ELLCsBook>(TableNameConstants.BooksTableName)
                                    .Find(qry);
    }
}

Sadly , there is a tonne of code that look like the aforementioned code.

The problem is that it would take an Enormous amount of effort, time and money to just refactor existing code to use an Interfaces. Therefore, integrating unit testing would be a real pain.

Does anyone have any suggestions as to how we could still do Unit testing?

CS Lewis
  • 489
  • 8
  • 30
  • 1
    http://programmers.stackexchange.com/q/312796/23940 – forsvarir Mar 17 '16 at 08:12
  • 2
    You may want to concentrate more on integration testing with a replacement database (either in memory, or one that's reset at the begging of the test run), alternately, you could look at mocking frameworks like typemock that allow you to mock code that traditional mocking approaches can't reach. – forsvarir Mar 17 '16 at 08:14
  • I've heard developers using SQLLite for in-memory testing if their application database is Microsoft SQL Server. What would be a good in-memory testing database for MongoDB? Thx. – CS Lewis Mar 17 '16 at 08:17

1 Answers1

2

I would highly suggest you to use Typemock Isolator. It allows to deal not only with interfaces, so no need to spend money and time for the refactoring.

Furthermore, it can make unit-test suggestions based on your code, so it also can save some time.

There is a good answer/example of how you can mock calls to mongo database using Typemock here.

Hope it helps!

Community
  • 1
  • 1
Eva
  • 449
  • 2
  • 8
  • Thx, however, Typemock is Not Open Source. Is there a free or open source alternative that can help me out? – CS Lewis Mar 21 '16 at 10:23
  • 1
    You can try a free trial. Frankly, there is no free alternative for it, Typemock is unique in comparsion with others. In my opinion, it's cheaper to buy a great tool than spend money+time on refactoring. – Eva Mar 21 '16 at 11:17