# Multiple interfaces

Classes can implement multiple interfaces. It might happen that the component under test expects the incoming dependency to implement more than one interface, like in the snippet below.

```csharp
public class Dependency : IDependency, IDisposable { ... }

public class Service
{
    private readonly IDependency _dependency;

    public Service (IDependency dependency) { _dependency = dependency; }

    public void DoSomething()
    {
        using (_dependency as IDisposable) { ... }
    }

    public void Dispose() { ... }
}
```

While being a signal that responsibilities are not properly split across interfaces, it's something that developers need to be able to cope with while developing unit tests.

Moq offers a way to decorate a mock with additional interfaces using the construct `As`, giving developers the possibility to configure and verify methods of the added interface.

```csharp
var mock = new Mock<IDependency>();
mock.As<IDisposable>().Setup(p => p.Dispose());
```

Alternatively, you can also store the reference returned by As into its own variable for later usage.

```csharp
var mockDisposable = mock.As<IDisposable>();
mockDisposable.Verify(p => p.Dispose(), Times.Once());
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.educationsmediagroup.com/unit-testing-csharp/moq/multiple-interfaces.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
