Skip to content
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

Should BatchWrite<T> implement an interface? #1565

Closed
safv12 opened this issue Mar 31, 2020 · 13 comments
Closed

Should BatchWrite<T> implement an interface? #1565

safv12 opened this issue Mar 31, 2020 · 13 comments
Labels
dynamodb feature-request A feature should be added or improved. needs-major-version Can only be considered for the next major release p1 This is a high priority issue queued v4

Comments

@safv12
Copy link

safv12 commented Mar 31, 2020

I'm trying to write a unit test to validate the BatchWrite.Execute invocation, but I'm struggling with the mock of the CreateBatchWrite<T> method because I'm not able to instantiate the BatchWrite<T> class.

I'm using Moq to build the mocks, the code looks like:

this.dynamoDbMock
    .Setup(m => m.CreateBatchWrite<SomeType>(It.IsAny<DynamoDBOperationConfig>()))
    .Returns(Mock.Of<BatchWrite<SomeType>>());

But the Returns part is throwing an error because the BatchWrite class does not have a default constructor.

Possible Solution

I think is a good idea to define an interface for the BatchWrite class. In this way, the unit test will be easier to write.

public class BatchWrite<T> : BatchWrite, IBatchWriteOperations
@NGL321 NGL321 added feature-request A feature should be added or improved. dynamodb needs-triage This issue or PR still needs to be triaged. labels Jul 22, 2020
@github-actions
Copy link

We have noticed this issue has not recieved attention in a year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jul 23, 2021
@Kralizek
Copy link
Contributor

Kralizek commented Aug 2, 2021

@ashishdhingra any comment on this? This is just one of many issues regarding the hard testability of code using DynamoDB.

@hunanniu hunanniu reopened this Aug 19, 2021
@ashishdhingra ashishdhingra added needs-review and removed closed-for-staleness needs-triage This issue or PR still needs to be triaged. labels Sep 24, 2021
@ashishdhingra
Copy link
Contributor

@ashishdhingra any comment on this? This is just one of many issues regarding the hard testability of code using DynamoDB.

@Kralizek Some DynamoDB revamp work is planned in the coming sprints and this feature request might be included as well. We would post any updates here.

@jakubbujak
Copy link

This is one of the worst libraries regarding testability. Shame on you Amazon, shame 😡

@Kilowhisky
Copy link

I just ran into this as well. Can't test any data layer code at all because of this.

@rferreiraLGC
Copy link

rferreiraLGC commented Nov 17, 2022

I am also unable to run my tests due to this.

@rynkadink
Copy link

+1
This seems to have been designed without testability in mind, how can we test any data layer code when using this lib?

@ik130 ik130 added p1 This is a high priority issue needs-major-version Can only be considered for the next major release and removed needs-review labels Dec 1, 2022
@Cussa
Copy link

Cussa commented Feb 2, 2023

Any news on that?

@stitcharg
Copy link

I just found the same problem :(

@Kralizek
Copy link
Contributor

Kralizek commented Jan 9, 2024

Still waiting for the rework...

@LBognanni
Copy link

+1, I worked around this by using the nullabilty operator when interacting with the BatchWrite object (ie batch?.AddPutItem(thing))

I would also contend that the detail of BatchWrite should be ideally be hidden for the consumer and the dynamo context should expose something like SaveAsync<T>(IEnumerable<T> things) that handles batching internally

@96malhar
Copy link
Contributor

96malhar commented Sep 3, 2024

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 BatchWrite<T> class, it now implements the IBatchWrite<T> interface which can be mocked inside unit tests.

This feature is available in the AWSSDK.DynamoDBv2 Version 4.0.0-preview.2

@96malhar 96malhar closed this as completed Sep 3, 2024
Copy link

github-actions bot commented Sep 3, 2024

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamodb feature-request A feature should be added or improved. needs-major-version Can only be considered for the next major release p1 This is a high priority issue queued v4
Projects
None yet
Development

No branches or pull requests