开发者

How to fake Azure Table Storage in .NET for Unit Testing? [closed]

开发者 https://www.devze.com 2023-02-03 00:39 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 4 years ago.

Improve this question

I am working on a system that uses Azure Table Storage. In other systems (e.g., SQL, File based, etc), I can write a fake that allows me to test my data persistence 开发者_如何学Gologic. However, I can't see an easy way to create a fake for the Azure Table Service.

I could create a new IIS project that behaves the same way, but that isn't a good way to write a unit test, it is more of an integration test.

Any thoughts on how to unit test data access code that uses the Azure Table Storage client?


I was considering this more for integration testing, but I suppose it could also work for unit testing. Meet Azure Storage Emulator. It sounds like a very awesome tool for testing Azure Blob, Queue and Table Services. I'm play around with it and try to post my findings if I can remember to do so.


This is something I'm currently considering myself, but I haven't tried it yet.

TableServiceContext inherets from DataServiceContext, so I figure if you could inject the TableServiceContext as a DataServiceContext, you could model the Table Store using data services.

Taking it a step further, if you use Entity Framework "Code First" to create your Entity Model - you could just use the Table Entities you've already created as the backing entities for your data service and everything should work smoothly.

That's the theory at least. I've never tried it.

http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.tableservicecontext_members.aspx


I use an in-memory implementation of ICloudTableStorage, which you can pass into eg ReliableCloudTableRepository.

You can find the code here: https://gist.github.com/4078750


I know there are several solutions posted here, but here's the one I came up with:

http://azurator.blogspot.com/2013/07/unit-testing-azure-table-storage-queries.html

This is only a solution for when you're querying objects using CloudTableQuery<T>, but it helped me a lot. If you're trying to get a more full implementation you could also create a shim for DataServiceContext.SaveChanges() that might get you the updating portion.

0

精彩评论

暂无评论...
验证码 换一张
取 消