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.
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.
发布评论
评论(4)
我使用 ICloudTableStorage 的内存中实现,您可以将其传递到例如 ReliableCloudTableRepository 中。
您可以在这里找到代码:https://gist.github.com/4078750
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
我知道这里发布了几种解决方案,但这是我提出的一个:
http://azurator.blogspot.com/2013/07/unit-testing-azure-table-storage-queries.html
这只是查询对象时的解决方案使用
CloudTableQuery
,但它对我帮助很大。如果您想获得更完整的实现,您还可以为 DataServiceContext.SaveChanges() 创建一个垫片,这可能会让您获得更新部分。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 forDataServiceContext.SaveChanges()
that might get you the updating portion.我更多地考虑将其用于集成测试,但我认为它也可以用于单元测试。了解 Azure 存储模拟器。这听起来像是一个非常棒的测试 Azure Blob、队列和表服务的工具。我正在尝试它,并尝试发布我的发现(如果我记得的话)。
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.
这是我目前正在考虑的事情,但我还没有尝试过。
TableServiceContext 继承自 DataServiceContext,因此我认为如果您可以将 TableServiceContext 作为 DataServiceContext 注入,则可以使用数据服务对表格存储进行建模。
更进一步,如果您使用实体框架“代码优先”来创建实体模型 - 您可以仅使用已经创建的表实体作为数据服务的支持实体,并且一切都应该顺利进行。
至少理论上是这样。我从来没有尝试过。
http://msdn.microsoft.com/en-us /library/microsoft.windowsazure.storageclient.tableservicecontext_members.aspx
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