none
Is Mocking possible when using SqlBulkCopy operaitons? RRS feed

  • Question

  • I am using sqlbulkcopy operations while inserting the large amount of data into SQL server. When I try to do the unit testing, i do not found the way to mock the SQLBulkCopy.. Is any framework available for the same? Or if any other ways to implement the Unit test, Please let me know. 
    Monday, February 19, 2018 10:56 AM

All replies

  • Perhaps mocking is not the best idea here, a alternate would be to have a test database, seed if need be to mix things up with some data from the development database. Prior to each unit test method runs copy data from dev to test database, perform the merge and do your assertions.

    I have a MSDN code sample that does the above in regards to setting things up but does not do the merge yet the pattern is sound.

    All setup is done in a base class that the test class inherits.

    Lastly, this forum is really for C# questions, if you like myself or another moderator can move your question to the unit test forum.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, February 19, 2018 11:06 AM
    Moderator
  • You're not doing a unit test, and you mock out the method that is implemented by a class Interface to mock out the call to the SQLBlukCopy.

    http://www.artima.com/weblogs/viewpost.jsp?thread=126923

    A test is not a unit test if:

    <copied>

    • It talks to the database
    • It communicates across the network
    • It touches the file system
    • It can't run at the same time as any of your other unit tests
    • You have to do special things to your environment (such as editing config files) to run it.

    <end>

    Monday, February 19, 2018 12:03 PM
  • This is one way to do the testing. But this is not actual unit testing. Also if we do this way, then again we need to maintain separate test DB as well, if in future anything is change from database perspective. So instead of doing actual system testing, if we have any moq framework for the same that will be good.  
    Monday, February 19, 2018 3:18 PM
  • Hi Sachin Londhe,

    I agree with what Kareninstructor said. In your mind, you want to do something which could update the DB avoid something change in future. But actually, after testing, the things we get is what we really want.

    Best Regards,

    Wendy 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, February 25, 2018 5:17 PM
    Moderator