New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot mock DynamoDBv2 AsyncSearch for unit testing AWS calls #772
Comments
I have the same issue with AsyncSearch. |
Any update on this issue? |
Any update on this, causing us some pain |
Thanks @Supercheez, I'll have a look at the PR. |
Do you have chance to look at it ? |
Hello, Any update regarding this? |
This would be very nice please |
|
Frankly, The TDD approach of this lib is pretty shocking, why have you got interfaces that expose internally constructed objects such as Just adding a public empty constructor would allow a safe non breaking fix for this - albeit not the best, but it should not have taken over 2 years to come to this conclusion. |
When will we see movement on this issue. Not being able to write proper unit tests is very frustrating. Just add the empty and public constructor so that we can mock the class. |
@kwbauer - I ended up caving in and wrapping this code in a new class with what should be the appropriate interface in this library. - It means that my unit tests are testing the wrapper, and not the actual call within the AWSSDK which means I'm not 100% happy about it, but it will do. Code snippets below. internal interface IAsyncSearch<T>
{
bool IsDone { get; }
Task<IReadOnlyList<T>> GetNextSetAsync(CancellationToken cancellationToken);
Task<IReadOnlyList<T>> GetRemainingAsync(CancellationToken cancellationToken);
}
internal sealed class AsyncSearchWrapper<T> : IAsyncSearch<T>
{
private readonly AsyncSearch<T> asyncSearch;
public AsyncSearchWrapper(AsyncSearch<T> asyncSearch)
{
this.asyncSearch = asyncSearch;
}
public bool IsDone => this.asyncSearch.IsDone;
public async Task<IReadOnlyList<T>> GetNextSetAsync(CancellationToken cancellationToken)
{
return await this.asyncSearch.GetNextSetAsync(cancellationToken);
}
public async Task<IReadOnlyList<T>> GetRemainingAsync(CancellationToken cancellationToken)
{
return await this.asyncSearch.GetRemainingAsync(cancellationToken);
}
}
internal sealed class WrappedDbContext : IWrappedDbContext
{
private readonly IDynamoDBContext context;
public WrappedDbContext(IDynamoDBContext context)
{
this.context = context;
}
public IAsyncSearch<T> Query<T>(object hashKeyValue, DynamoDBOperationConfig operationConfig = null)
{
var search = this.context.Value.QueryAsync<T>(hashKeyValue, operationConfig);
return new AsyncSearchWrapper<T>(search);
}
} I also renamed the context method to Hope this helps.
|
Just got burned by this. +1 for some way to mock AsyncSearch. @assyadh Have you had a chance to look at the PR yet? |
After following @Hardconkers code I have successfully managed to mock out the IAsyncSearch. Here's an example:
I've also included the implementation
|
Hi Guys, |
There is a PR here #1187 , but was never merged. |
Bump |
1 similar comment
Bump |
Bump |
Bump |
Bump |
Bump |
1 similar comment
Bump |
BUMP!!! |
Bump |
bump |
1 similar comment
bump |
It is ridiculous not to do anything about it for 5 years (sic!) 😡 😡 😡 |
bump Just wondering if there has been any movement on this? |
I put out this PR to provide a way to mock AsyncSearch. It is not perfect given the constraints we have to avoid making breaking changes but I would appreciate some thoughts on the PR. |
If anyone wants workaround you can use approach propsed in this comment: Works fine 😃 But still it would be better to have that out of the box from library 👎 |
@jakubbujak Are you saying that my PR that would go in the box would not suffice? |
I did not write anything like that, it may be, but I did not have time to review it :) |
Version 3.7.4.9 of the AWSSDK.DynamoDBv2 package was recently released with #2089 that adds the ability to subclass
|
|
Would like to be able to properly unit test my code which uses the AWS SDK, and in particular the AsyncSearch class.
Possible Solution
The text was updated successfully, but these errors were encountered: