Where is 'With' method defined. ReactiveUI - system.reactive

I saw here that we can use
(new TestScheduler()).With(sched =>{
// Code run in this block will have both RxApp.MainThreadScheduler
// and RxApp.TaskpoolScheduler assigned to the new TestScheduler.
});
But where is With method defined. I cant find any. Please help.
Microsoft.Reactive.Testing.TestScheduler does not contain a definition for With and no extension method With accepting a first argument of type Microsoft.Reactive.Testing.TestScheduler could be found

This is an extension method defined here and you need nuget package reactiveui-testing to have it available.

Related

Using flutter/dart vscode shows "method isn't defined" when i check for a specific mixin before calling it

This is my first time messing with dart and i'm stuck with this silly error. I'm 90% confident that the error lies on the vscode part of it, because there aren't errors showing when running the app.
Maybe I'm approaching the problem in the wrong way, I simply want to call a mixin function in objects that implements the mixin. In java for example it would be required to cast the component variable, but I couldn't get cast to work in this situation.
Code
Error
The method 'onPanUpdate' isn't defined for the class 'Component'.
Try correcting the name to the name of an existing method, or defining a method named 'onPanUpdate'.
Source Code
Repo link
Component class source
Maybe I'm approaching the problem in the wrong way, I simply want to call a mixin function in objects that implements the mixin. In java for example it would be required to cast the component variable, but I couldn't get cast to work in this situation.
For this to work it must be done with the following code:
for (var component in this.components) {
if (component is PanDetector) {
(component as PanDetector).onPanUpdate(details);
}
}
Especial thanks to #Moqbel

Unable to properly stub a method with an argument instanciating a new Date

I'm working on a scala project and in my unit test I have to stub a method that takes as argument a Date(that is instanciated when calling the method), and I can't get to stub it porperly
However, I was able to find a turnaround using this post How to mock new Date() in java using Mockito
But I wonder if there is a better way to do this because I find that solution not very satisfying ...
here is the code I try to stub :
def foo(): Future[JsonObject] ={
[...]
for {
a <- b.bar(arg,atDate = Some(Date.from(Instant.now())))
} yield a
}
I tried to stub it like that
val b = mock[B]
when(b.bar(arg, _:Option[Date])).thenReturn(Future.successful(List()))
this doesn't parse,so I have to change it to :
val b = mock[B]
when(b.bar(arg, _:Option[Date])).thenReturn({ d:Date => Future.successful(List())})
and when I run it I have the following error :
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.
Maybe I'm missing something in the error message but I don't find it helpful.
Is there any way to tell the stub to take whatever value for the date?
Also why does it require to put a function in thenReturn part, although the return type of the function is Future[List[A]]?
thanks in advance
You have to use the any matcher, so your code looks like (here I'm assuming arg is a variable defined somewhere else in your test code)
when(b.bar(ArgumentMatchers.eq(arg), ArgumentMatchers.any())).thenReturn(Future.successful(List()))
Now that's a bit verbose, so if you upgrade to mockito-scala and use the idiomatic syntax it would look like
b.bar(arg, *) returns Future.successful(List())
if you have/use cats, you can even do
b.bar(arg, *) returnsF List()
for more info check the docs here

Eclipse JDT AST: how to find a calling method returns value of an instance variable?

I'm using Eclipse JDT AST to parse a given java source code. While parsing the code, when it hits a method invocation, I want to find out whether that particular method returns or sets a value of an instance variable (basically to find out whether the callee method is a getter/setter of the same class of caller method).
E.g.:
public void test(){
//when parsing the following line I want to check whether "getName"
//returns a value of an instance variable.
String x = getName();
//when parsing the following line I want to check whether "setName"
//sets the value of an instance variable.
setName("some-name");
}
I've used the AST plugin also find out a possible path which would help me to refer it from the API, but couldn't.
Please let me know whether this is possible and if so, which approach that would help me to get the required information.
Don't think that there is an api which tells you whether a method is a getter or a setter.
You will have to write code to do this. For a getter, you can probably simply check if the last statement in the method is a return statement which returns an instance variable.

Why is my C# template method complaining about accepting a specific type?

I'm diving into ASP.NET MVC 2 and I'm walking through a tutorial and I'm getting an error related to a template method in my unit tests. The erroneous code is...
var displayedProducts = (IList<Product>)result.ViewData.Model;
displayedProducts.Count.ShouldEqual(2);
and the method definition for ShouldEqual is...
public static void ShouldEqual<T>(this T actualValue, T expectedValue)
{
Assert.AreEqual(expectedValue, actualValue);
}
and the error is...
'int' does not contain a definition for 'ShouldEqual' and no extension method 'ShouldEqual' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
but because I'm so new to all this, I don't see what I missing.
Does anyone see the problem?
Can someone explain to me how ShouldEqual is a member function of Count
Thanks so much for your help! If more code is needed, please let me know.
I recognize this... this is from the Steve Sanderson book?
I can reproduce this error if I comment out the using statement for the namespace where ShouldEqual is declared.
In the file where you have
var displayedProducts = (IList<Product>)result.ViewData.Model;
displayedProducts.Count.ShouldEqual(2);
can you check and make sure you have a using statement for the namespace that ShouldEqual is in?
ShouldEqual is compiler trick only. It's a stand alone function (static class (CLASSNAME) and method). The compiler replaces the call with...
CLASSNAME.ShouldEqual<int>(displayedProducts.Count, 2);
See here for more information : http://msdn.microsoft.com/en-us/library/bb383977.aspx

RhinoMocks - Pass Action<T> as parameter

In RhinoMocks, there's Stub extension method, that takes Action<T>. For some reason this:
CurrentInvoice.Stub(i => i.TaxYear).Return(1);
works great, but this:
CurrentInvoice.Stub(new Action<Invoice>(i => i.TaxYear)).Return(1);
produces the compiler error:
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
The intellisense for this method explicitly says that it expects Action<Invoice>, so I can't understand why the first works, but not the second.
The main relevance of this is that I'd like to be able to pass some of these configuration lambdas as parameters to a method, and I run into this same issue.
Thanks
Are you sure you're not accidentally using an overload for Stub which takes a Func<T, TResult> in the first line? I can't see why the first call would work otherwise.
Do you have a link to API documentation?