lundi 28 mars 2016

Unit testing a method that uses an external dll

I have a project named A that has a class named ClassA. ClassA has a method named ReadBlock() which creates a CloudBlockBlob object and calls one of its methods.

CloudBlockBlob is a class which is located in Microsoft.WindowsAzure.Storage.Blob namespace which is in Microsoft.WindowsAzure.Storage.dll.

My project A has a unit testing project named A.Tests. Now, I want to test method ReadBlock(). To test it, I need to mock the CloudBlockBlob object and intercept the calls to its methods, return custom values and verify that the methods were called.

  • How can I mock an object that is fully created inside a method?
  • Can I somehow change project A's dll reference and reference it to a mock dll that creates a mock object instead the real one?
  • Can I override project A's call for classes inside the Microsoft.WindowsAzure.Storage.Blob with an implementation of my own in A.Tests class?

UPDATE: The question is whether I can do this without modifying project A's code.

Please help,

Thanks!

Aucun commentaire:

Enregistrer un commentaire