[FEATURE REQ] Public constructors on Operation types for testability
See original GitHub issueLibrary or service name. Azure.ResourceManager.Storage
Is your feature request related to a problem? Please describe.
[Fact]
public async Task Solve()
{
var operations = Substitute.For<StorageAccountsOperations>();
operations
.StartCreateAsync("rg", Arg.Any<string>(), Arg.Any<StorageAccountCreateParameters>())
.Returns(new StorageAccountsCreateOperation(null, null, null, null)); // <-- [CS1729] 'StorageAccountsCreateOperation' does not contain a constructor that takes 4 arguments
var storage = Substitute.For<StorageManagementClient>();
storage.StorageAccounts.Returns(operations);
var operation = await _storage.StorageAccounts.StartCreateAsync(_rg, $"sa{DateTime.Now.Ticks}",
new StorageAccountCreateParameters(new Sku(SkuName.StandardLRS), Kind.Storage, _location));
await operation.WaitForCompletionAsync();
}
Would be really happy to turn my integration tests into unit tests but that’s not impossible while these constructor(s) are internal.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Is it important to unit test a constructor?
Unit testing is about testing the public states, behaviors, ... No. Its functionality will be tested by every other unit test on the...
Read more >Unit testing and mocking with Azure SDK .NET
To create a test instance of an input model use one of the available public constructors and set additional properties you need.
Read more >Unit Testing and Coding: Why Testable Code Matters
In this article, I will show that unit testing itself is quite easy; the real problems that complicate unit testing, and introduce expensive...
Read more >"abstract" classes should not have "public" constructors
The abstract modifier in a class declaration is used to indicate that a class is intended only to be a base class of...
Read more >Guidelines for Java Testable Design
Dos and don'ts for Java testable design: avoid complex private methods, static methods, logic in constructors and to favor composition over ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure, but mine was first 😛 Thanks for the heads-up on the mocking guidelines, wouldn’t have found it myself but still doesn’t seem to be in place for the aforementioned operations.
I think it’s the same issue as described here https://github.com/Azure/azure-sdk-for-net/issues/15639.
It would also follow the guidelines described here https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-mocking