Skip to content

[Bug]: Mock.Of<> does not work with AWS interfaces #5069

@dealloc

Description

@dealloc

Description

I'm trying to mock AWS' interfaces for S3 and SimpleSystemsManagement:

var mock = Mock.Of<IAmazonSimpleSystemsManagement>();

Expected Behavior

I expect this to compile and have a working mock

Actual Behavior

Compilation fails:

8>Amazon_Runtime_IAmazonService_MockImpl.g.cs(6,68): Error CS0535 : 'Amazon_Runtime_IAmazonService_MockImpl' does not implement interface member 'IAmazonService.CreateDefaultClientConfig()'
8>Amazon_Runtime_IAmazonService_MockImpl.g.cs(6,68): Error CS0535 : 'Amazon_Runtime_IAmazonService_MockImpl' does not implement interface member 'IAmazonService.CreateDefaultServiceClient(AWSCredentials, ClientConfig)'
8>Amazon_Runtime_IAmazonService_MockImpl.g.cs(8,96): Error CS8920 : The interface 'IAmazonService' cannot be used as type argument. Static member 'IAmazonService.CreateDefaultClientConfig()' does not have a most specific implementation in the interface.
8>Amazon_Runtime_IAmazonService_MockImpl.g.cs(10,127): Error CS8920 : The interface 'IAmazonService' cannot be used as type argument. Static member 'IAmazonService.CreateDefaultClientConfig()' does not have a most specific implementation in the interface.
8>Amazon_Runtime_IAmazonService_MockMembers.g.cs(8,83): Error CS8920 : The interface 'IAmazonService' cannot be used as type argument. Static member 'IAmazonService.CreateDefaultClientConfig()' does not have a most specific implementation in the interface.
8>Amazon_Runtime_IAmazonService_MockFactory.g.cs(14,88): Error CS8920 : The interface 'IAmazonService' cannot be used as type argument. Static member 'IAmazonService.CreateDefaultClientConfig()' does not have a most specific implementation in the interface.
8>------- Finished building project: Company.Business.Pdf.Tests. Succeeded: False. Errors: 6. Warnings: 0

Steps to Reproduce

I suspect the source generators aren't capable of handling static members.

This is the offending line in AWS' interface:

    public interface IAmazonService
    {
        /// <summary>
        /// A readonly view of the configuration for the service client.
        /// </summary>
        IClientConfig Config
        {
            get;
        }

#if NET8_0_OR_GREATER
        /// <summary>
        /// Factory method for creating the service client config object used by the service client.
        /// This method is intended to be used by AWSSDK.Extensions.NETCore.Setup for creating
        /// AWS service clients registered in the dependency injection container.
        /// </summary>
        /// <returns></returns>
        static abstract ClientConfig CreateDefaultClientConfig();
    }

TUnit Version

TUnit -> 1.18.9 TUnit.Mocks -> 1.18.9-beta

.NET Version

NET 10.0

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

8>Amazon_Runtime_IAmazonService_MockImpl.g.cs(6,68): Error CS0535 : 'Amazon_Runtime_IAmazonService_MockImpl' does not implement interface member 'IAmazonService.CreateDefaultClientConfig()'
8>Amazon_Runtime_IAmazonService_MockImpl.g.cs(6,68): Error CS0535 : 'Amazon_Runtime_IAmazonService_MockImpl' does not implement interface member 'IAmazonService.CreateDefaultServiceClient(AWSCredentials, ClientConfig)'
8>Amazon_Runtime_IAmazonService_MockImpl.g.cs(8,96): Error CS8920 : The interface 'IAmazonService' cannot be used as type argument. Static member 'IAmazonService.CreateDefaultClientConfig()' does not have a most specific implementation in the interface.
8>Amazon_Runtime_IAmazonService_MockImpl.g.cs(10,127): Error CS8920 : The interface 'IAmazonService' cannot be used as type argument. Static member 'IAmazonService.CreateDefaultClientConfig()' does not have a most specific implementation in the interface.
8>Amazon_Runtime_IAmazonService_MockMembers.g.cs(8,83): Error CS8920 : The interface 'IAmazonService' cannot be used as type argument. Static member 'IAmazonService.CreateDefaultClientConfig()' does not have a most specific implementation in the interface.
8>Amazon_Runtime_IAmazonService_MockFactory.g.cs(14,88): Error CS8920 : The interface 'IAmazonService' cannot be used as type argument. Static member 'IAmazonService.CreateDefaultClientConfig()' does not have a most specific implementation in the interface.
8>------- Finished building project: Company.Business.Pdf.Tests. Succeeded: False. Errors: 6. Warnings: 0

Additional Context

This happens with all Amazon interfaces because they all inherit from IAmazonService which has static members

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions