Adding virtual to Insert, Update, and Save

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Feature Request
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Adding virtual to the overloads of Insert, Update, and Save in MongoCollection will make unit testing much easier. I pulled the source and made the change for Insert and it does work as expected.

      Example usage in unit test (using RhinoMocks):

      public class DatabaseFactory
      {
      public static MongoDatabase Create()

      { var server = MockRepository.GenerateStub<MongoServer>(new MongoConnectionSettings()); var database = MockRepository.GenerateStub<MongoDatabase>(server, "doesntmatter"); var foos= MockRepository.GenerateStub<MongoCollection<BsonDocument>>(database, "foos"); database.Stub(x => x.GetCollection("foos")).Return(foos); questions.Stub(x => x.Insert<BsonDocument>(new BsonDocument())); // add other mocked document collections here return database; }

      }

      This allows defensively checking boundary conditions in repositories, and if they all pass the database isn't actually called. The server process can actually be turned off and all unit tests can be run, and then turned on for integration tests.

      Maybe a mocking super genius has a better way, but this is the best I could come up with after a while of fiddling around.

        1. WithInterfaces.txt
          0.8 kB
        2. WithVirtual.txt
          1 kB

            Assignee:
            Robert Stam
            Reporter:
            Robert Schooley
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: