Object reference not set to an instance of an object error wpf nunit testing - observablecollection

Why I am getting an error "Object reference not set to an instance of an object” when I am trying to clear the values of an observable collection?
if(testcollection.Count>0) testcollection.Clear();

If the testcollection have value, that is not equals to null, then this may happened because of cross threading issue. Try to implement this with the help of Dispatcher.
Dispatcher.BeginInvoke();
Try the following link,
link1
link2

Based on the limited code you gave, it looks like testcollection is null when you are trying to access the count. Try this:
if (testcollection != null && testcollection.Count > 0) testcollection.Clear();

Related

Test if a property in objectContaining is an Array or undefined

I am using Jest (TypeScript on Node.js) for unit testing and would like to check if a specific property is either an Array or undefined using expect.objectContaining(). This property may or may not exist in the object, hence why I want my test to include both cases.
My initial idea was to use
propertyInQuestion: expect.any(Array || undefined)
inside objectContaining(), but it fails because an Array is expected. When I checked the documentation, it stated that an expected object must be a subset of the received object, so it contains properties that are present in the expected object. So what happens when a property is either present and must be of an Array type or is undefined and therefore not present in the object?
At the moment, test looks something like this
expect(someObject).toEqual(
expect.objectContaining({
propertyInQuestion: expect.any(Array),
something: expect.any(Array),
})
);
and the property I'd like to check is propertyInQuestion, which can either be an Array or undefined.
Any sort of help is appreciated. Thank you!

MissingMethodException in Xamarin.iOS

I was facing the MissingMethodExeption while using the reflection method in Xamarin.iOS. My code works fine when Linker Behavior is set to Don't Link. But i am getting the above exception when Linker behavior is set to Link SDK assemblies. I have tried the workaround to set the --linkskip=System.Core but exception raised. Can you please let me know if you have any answer for this problem.
I am getting the error while performing the following operation. Activator.CreateInstance(resultType) as ScriptObject. Here resultType is a Type and ScriptObject is a class which perform some operations for me.
A quick and dirty way to avoid some methods/types to be linked out is to reference them in unused code:
if (false) {
var a = new TypeToPreserve();
a.MethodToPreserve();
}

How to avoid creating objects to check or get content from Maps in Java

I am implementing my own Map in Java, using a custom class I made.
I already implemented the hashCode and equals without any problem.
I just have a question more related into performance and stuff like that.
So I will check many times in my application if a specific value is inside the map, for that, for that I have to create a object and then use the methods containsKey of Map.
My question is...
Is there any other way? without being always creating the object???
I cant have all the objects in my context universe, so that isn't a way...
I know I can just point the object to 'null' after using it, but still, it's not so elegant, creating objects just to check if there is the same object inside =S
Are there any other conventions?
Thank you very much in advance!
EDIT:
Stuff typed = new Stuff(stuff1, stuff2, (char) stuff3);
if(StuffWarehouse.containsKey(typed))
{
//do stuff
}
//after this I won't want to use that object again so...
typed = null;

If Statement in Template

I want to create my own template and my code is:
#{if _arg.status.equals(models.Status.FINISHED)}
#{doBody /}
#{/if}
When I pass an object reference to my tag its saying its null. If I call in my template its working as described in the docs:
${_arg.status}
The error message is:
Template execution error
Execution error occured in template
/app/views/tags/isNotFinished.html. Exception raised was
NullPointerException : Cannot get property 'status' on null object.
I am not getting any null pointer exception. What I am doing wrong here?
Thanks for your help.
It seems like _arg is not found in the scope you're working with. This seems to indicate you get arg implicitly in the tag. You might try omitting the _arg. from the tag.
I am not getting it really. But today I tried again with _arg and its working now as excpected. It can be closed now.

Using constructor to load data in subsonic3?

I'm getting an error while trying to load an record through the constructor.
The constructor is:
public Document(Expression<Func<Document,bool>> expression);
and i try to load a single item in like this
var x = new Document(f=>f.publicationnumber=="xxx");
publicationnumber isn't a key but tried making an it an unique key and still no go..
Am i totally wrong regarding the use of the constructor? and can someone please tell me how to use that constructor?
The error i'm getting is:
Test method TestProject1.UnitTest1.ParseFileNameTwoProductSingleLanguage threw exception: System.NullReferenceException:
with the following stacktrace:
SubSonic.Query.SqlQuery.Where[T](Expression1` expression)
Load`[T]`(T item, Expression1expression)
db.Document..ctor(Expression``1 expression) in C:\#Projects\DocumentsSearchAndAdmin\DocumentsSearchAndAdmin\Generated\ActiveRecord.cs: line 5613
rest removed for simplicity
Regards
Dennis
Use == instead of =, i.e.:
...(f=>f.publicationnumber == "xxx");
I've just gotten the SubSonic source, and found out that it had to with the expression parser and my lack of knowledge thereof .. my right side of the expression was actually an item in an string array - and s[PUBNO] (PUBNO is a const) and it was looking for an column named s instead of publicationnumber, i don't know if this i a bug or not in the linq classes
none the less - i've managed to get it to work by creating a local variable containing the value of s[PUBNO] and using that instead...
//dennis

Resources