Comments (2)
Hi @ggirard07, IIRC the code behind DefaultValue.Empty
performs a strict type check and doesn't take type inheritance into account.
Before you ask: yes, of course this could be changed. We've had similar requests in the past. (If I find the time, I'll link to some of them later.) However, I have been hesitant to change the behavior of DefaultValue.Empty
because it is a core part of Moq and functional changes to it it could affect much pre-existing user code.
Now that Moq vNext has been shelved (for the time being) and we're free to do a new major version, perhaps we'll be able to change that behavior in v5.
from moq4.
The following (partially) works as long as the signature of the method being invoked clearly uses ILookup<>
(i.e. won't work with IServiceProvider
since the return type isn't known):
using Moq;
using Xunit;
var mock = new Mock<ILookupProvider>();
mock.SetReturnsDefault(new Dictionary<string, string>().ToLookup(x => x.Key, x => x.Value));
var lookup = mock.Object.GetLookup<string, string>();
Assert.NotNull(lookup);
public interface ILookupProvider
{
ILookup<TKey, TValue> GetLookup<TKey, TValue>();
}
from moq4.
Related Issues (20)
- Exception throw in dotnet8 (working in dotnet6) HOT 2
- VerifySet throws TargetInvocationException when constructer refers to itself
- Add ability for asynchronously waiting for an invocation
- Moq library throwing TypeIniatilizationException. HOT 1
- Request: Ability to setup a property of type Task<ConcreteType> by mocking interface
- Supporting .NET8 HOT 2
- Mock.Protected().Verify fails sometimes
- Moq "set" matcher fails when setting StringValues with string HOT 1
- It.IsAny<StructObject>() isn't
- Documentation Unavailable Online HOT 2
- Consider adding IgnoresAccessChecksTo("Unsupported")
- Explicit support for matching cancellation tokens with It class. (It.IsCancellationToken())
- Moq Setup does not work with "object" as generic type? HOT 1
- IVerifies.Verifiable* documentation comments errata?
- Support for post-invocation callbacks on void methods?
- Semantic error in unit test MatchesIsNotInEnumerable()?
- Documentation link is broken HOT 6
- Constructing Mock<DerivedControl>.Object throws TypeLoadException
- How do you Verify an IAsyncEnumerable<T> ?
- Add Way to Exclude Calls from VerifyNoOtherCalls HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moq4.