question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE REQ] Public constructors on Operation types for testability

See original GitHub issue

Library 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:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
riezeboschcommented, Oct 6, 2020

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.

1reaction
jhestedcommented, Oct 5, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found