Comments (10)
Hi @j82w ,
From my priority point of view,
- CosmosContainer
- CosmosDatabase
- CosmosClient
For example, I tried to Mock the CreateContainerIfNotExistsAsync, we need this effort. However, it doesn't work because of the error. If we have an interface on it. Things might be much easier.
var cosmosDatabaseMock = new Mock<CosmosDatabase>();
var cosmosContainersMock = new Mock<CosmosContainers>();
var containerResponseMock = new Mock<CosmosContainerResponse>();
var containerMock = new Mock<CosmosContainer>();
var container = containerMock.Object;
containerResponseMock.Setup(p => p.Container).Returns(container);
cosmosContainersMock.Setup(p => p.CreateContainerIfNotExistsAsync("Todo", "/UserName", null, null, default(CancellationToken)))
.ReturnsAsync(containerResponseMock.Object);
cosmosDatabaseMock.Setup(p => p.Containers).Returns(cosmosContainersMock.Object);
var repository = new GenericRepository<Todo>(cosmosDatabaseMock.Object);
Assert.Equal(container, repository.container);
cosmosContainersMock.Verify(p => p.CreateContainerIfNotExistsAsync("Todo", "/UserName", null, null, default(CancellationToken)));
from azure-cosmos-dotnet-v3.
Hi Tsuyoshi,
Can you please provide a list of objects that can not be mocked?
from azure-cosmos-dotnet-v3.
I also try to Mock the method, like this.
this._containerResponseMock = new Mock<CosmosContainerResponse>();
var expectedCosmosItemResponseMock = new Mock<CosmosItemResponse<Todo>>();
expectedCosmosItemResponseMock.Setup(p => p.Resource).Returns(ExpectedTodo);
expectedCosmosItemResponseMock.Setup(p => p.StatusCode).Returns(HttpStatusCode.OK);
this._containerResponseMock.Setup(p =>
p.Container.Items.CreateItemAsync<Todo>(ExpectedPartitionKey, InputTodo, null, default(CancellationToken)))
.Returns(Task.FromResult(expectedCosmosItemResponseMock.Object));
it causes
Castle.DynamicProxy.InvalidProxyConstructorArgumentsException : Can not instantiate proxy of class: Microsoft.Azure.Cosmos.CosmosContainer.
Could not find a parameterless constructor.
Seems lack of default constructor.
I'm a new to this API, so I might misunderstand the implementation. I'm ok if I can write unit testing. (I usually use TDD method). If my implementation is not proper, please let me know how can I write the unit testing using Moq.
from azure-cosmos-dotnet-v3.
We want this to be unit testable. I will create task to add the interface. We are still working on planning so I don't currently have a time frame, but it will be done before the SDK goes GA.
from azure-cosmos-dotnet-v3.
Awesome! I appreciate you. I'm trying to understand the new API and how to write unit testing for it.
I'll write a blog what I learned and current workaround for unit testing.
from azure-cosmos-dotnet-v3.
Thanks for the feedback. If you find any other blockers or have any ideas on how to make it easier to unit test please let us know.
from azure-cosmos-dotnet-v3.
This. Right Here. I also opened #53 with a similar problem (as you're asking for feedback but they're separate from what he's asking)
from azure-cosmos-dotnet-v3.
@TsuyoshiUshio and @darthmolen please take a look at the PR
from azure-cosmos-dotnet-v3.
@J82 awesome!
from azure-cosmos-dotnet-v3.
from azure-cosmos-dotnet-v3.
Related Issues (20)
- [Client Telemetry] - Trace error not recording exception HOT 1
- [Client Telemetry] - Index out of range HOT 3
- Negative latency is getting recorded
- CFP AVAD: Remove unsupported WithStartTime and WithStartFromBeginning from Builder
- ??
- Support for Manager Identity modification HOT 1
- Add option for exempting dictionary keys from camel-case naming strategy on CosmosSerializationOptions
- CosmosException Diagnostics shows 404/429 error but StatusCode returns 200 HOT 12
- Reg DeleteAllItemsByPartitionKeyStreamAsync Preview feature in CosmosDB client HOT 3
- PatchItemAsync failing with HTTP400 when using CosmosPropertyNamingPolicy.CamelCase instead of [JsonProperty("id") HOT 9
- PkRangeStats
- [Thin Client Integration] Analyze and Implement Changes in Cosmos Diagnostics
- CF/P AVAD: Issues with Serialization/Deserialization with JsonSerializerOptions on Custom serializer and UseSystemTextJsonSerializerWithOptions.
- CFP AVAD: Add public access to FeedRange from ChangeFeedProcessorContext
- PartitionKey.None.GetHashCode() throws an ArgumentNullException HOT 4
- [BUG][Thin Client Integration] Fix Rntbd deserializer: Throwing exception when deserializing error responses HOT 1
- [Vector Index] Remove Unsupported Data Types from Embedding Contract
- [Cosmos Diagnostics] - Reverse the Network Interactions Order when Diagnostics is Truncated
- Cannot disable Analytical store in container (setting AnalyticalStoreTimeToLiveInSeconds to null has not effect) HOT 7
- Incomplete example documentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-cosmos-dotnet-v3.