-
Notifications
You must be signed in to change notification settings - Fork 855
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
Unable to mock Table object returned from IDynamoDBContext.GetTargetTable #1310
Comments
Thanks for the feedback. |
Basically the same as #632 which is added to feature request backlog 2.5 years ago. Wouldn't count on it to happen... |
We do have some other issues around this topic too, but it is unlikely to happen until a next major version. |
Or add a public parameterless constructor. That way mocking frameworks can construct the object and we can mock the properties and methods we need to. The main problem is that most of these objects have no public constructors at all. Sure, they aren't needed for the library but it makes our code which uses your library not testable. Adding the public constructors is a good compromise that is fairly easy to do for a minor revision as it is not a breaking change. |
Is there a feature-request list where we can vote on this one? |
Adding my voice to this. Currently have a whole tranche of code I can't test because I can't mock the types in the DynamoDb package. This is one of them. |
I also just ran into the same issue when trying to add unit tests. I cannot mock the Table class. |
Hello, Any update regarding this? |
I also have the same problem, I can't seem to mock some classes to do my unit tests. The problem is that the maintainers say: "we accept PRS" but there are several open PRs that are even more than a year old. |
Hello, we have been working on the V4 of the AWS SDK for .NET. We have added the ability to mock various DynamoDB operations by adding interfaces in both the Data Model mode and Document Model mode in DynamoDB. Refer to this PR - #3450 Specifically for the This feature is available in the AWSSDK.DynamoDBv2 Version 4.0.0-preview.2 |
Comments on closed issues are hard for our team to see. |
Unable to mock
Table
object returned fromIDynamoDBContext.GetTargetTable
I am injecting
IDynamoDBContext
in a constructor, and then callingGetTargetTable
to get theTable
object representing the table for an entity. I then use thatTable
object to carry out some operations onDynamoDB
, or to extract metadata about the table (i.e table name, hash key name, etc).The problem is I cannot find a way to mock the return value of
GetTargetTable
as theTable
class doesn't appear to be mockable.Expected Behavior
I would expect
GetTargetTable
to return an interface that defines the operations which can be carried out on an entity's table, rather than the concreteTable
implementation.Current Behavior
GetTargetTable
returns concrete class rather than an abstraction (i.e interface)Possible Solution
Create an interface abstract over the
Table
class and haveGetTargetTabke
return the interface.Steps to Reproduce (for bugs)
Following class shows an example of the issue:
Context
Unable to unit tests services that consume
IDynamoDBContext
and rely on the instance returned byGetTargetTable
to carry out certain operations.Your Environment
The text was updated successfully, but these errors were encountered: