C++ covariance in parameters
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The return type is permissible since derived inherits from base, but the function parameter can't work - not all base instances will be a derived also. What's supposed to happen in the cases where func is called on a pointer to base with a parameter that's not a derived? The most derived implementation isn't callable.
|
Moq: Invalid callback. Setup on method with parameters cannot invoke callback with parameters
Date : March 29 2020, 07:55 AM
I hope this helps you . You need to call the generic overload of Callback with the specific types expected by the method. The following should work: sender.Setup(x => x.SendCommand(It.IsAny<MyCommand>(), false))
.Callback<ICommand, bool>((command, idFromContent) =>
{
var myCommand = command as MyCommand;
Assert.That(myCommand, Is.Not.Null);
Assert.That(myCommand.Id, Is.EqualTo(cmd.Id));
Assert.That(myCommand.Name, Is.EqualTo(cmd.Name));
})
.Verifiable();
sender.Verify(x => x.SendCommand(It.Is<MyCommand>(c =>
{
Assert.That(c, Is.Not.Null);
Assert.That(c.Id, Is.EqualTo(cmd.Id));
Assert.That(c.Name, Is.EqualTo(cmd.Name));
return true;
}), false), Times.Once());
|
Covariance and method parameters
Tag : scala , By : desmiserables
Date : March 29 2020, 07:55 AM
will help you The first error covariant type A occurs in contravariant position in type A of value param means that if a generic type Foo declares itself to be covariant over T (i.e. Foo[+T]), it means that its methods can only return T and not require it. Otherwise type consistency will be violated. For instance you could pass in an instance of Sample[Dog] where Sample[Animal] is required, and then something could call doit(new Duck) on it, even though Sample[Dog]#doit can only handle instances of Dog. However, return values behave the exact opposite way in this context (I'll let you figure out why). However this def doit[Int](param: Int)
def doit[B >: Int](param: B)
|
Why can't I use covariance with two generic type parameters?
Tag : chash , By : Alex Bartzas
Date : March 29 2020, 07:55 AM
should help you out Thing is, in the first case, the Base is known to be a class. In the second case, the type parameter T could be either class or a struct (this is how compiler thinks). Solve the case by specifying that T is a class, and the error will disappear: class Test2<TBase, TDerived> where TDerived : class, TBase
{
private List<TDerived> m_X;
public IEnumerable<TBase> GetEnumerable()
{
return m_X;
}
}
|
Moq & C#: Invalid callback. Setup on method with parameters cannot invoke callback with parameters
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further As mentioned in the comments the Callback parameters used do not match the method definition. Even though the Setup uses It.IsAny the method definition uses ILoggingContext parameter Change t2 toILoggingContext t2 = null;
.Callback<ICustomerRequest<IEnumerable<CustomerPreference>>,CancellationToken, ILoggingContext>((a, b, c) => {
t = a;
t1 = b;
t2 = c;
});
.Callback((ICustomerRequest<IEnumerable<CustomerPreference>> a,
CancellationToken b,
ILoggingContext c) => {
t = a;
t1 = b;
t2 = c;
});
this.customerPreferenceRepositoryMock
.Setup(x => x.UpdateAsync(
It.IsAny<ICustomerRequest<IEnumerable<CustomerPreference>>>(),
It.IsAny<CancellationToken>(),
It.IsAny<LoggingContext>()))
.Callback((ICustomerRequest<IEnumerable<CustomerPreference>> a,
CancellationToken b,
ILoggingContext c) => {
t = a;
t1 = b;
t2 = c;
//Use the input to create a response
//and pass it to the `ReturnsAsync` method
})
.ReturnsAsync(new GeneralResponseType()); //Or some pre initialized derivative.
|