c# - How to debug this or possible causes? System.NullReferenceException was unhandled by user code on Moq.Verify -


I have something in my unit test

  public class MyTestClass () {private} Fake & lt; IAccountRepo & gt; AccountRepo; Private Admin Service Administration Service; [Setup] Public Zero Setup () {accountRepo = fixture.freeze & lt; Counterfeit & lt; IAccountRepo & gt; & Gt; (); AdminService = Stability. Create anonym & lt; AdminService & gt; (); } [Test] Public Test () {accountRepo.Setup (X => x.Insert (It.IsAny & lt; IUnitOfWork & gt; (), It.IsAny & LT; MyDomainObject & gt; ())); AdminService.ApplyAdminFee (1, 1, today); AccountRepo.Verify (x => x.indert (It.IsAny & lt; iUnitOfWork & gt; (), It.Is & lt; MyDomainObject & gt; (a => a.Id == 1)) ); }}   

I get this error.

  System.NullReferenceException by User Code was unrestricted Message = object reference is not set for an instance of an object. Source = Anonymous Host DynamicMethods Assembly StackTrace: lambda_method (Closed, MyDomainObject) Moq.It. On & lt; & Gt; C__DisplayClass2`1 & lt; Is & gt; B__1 (TValue Price) on Moq.Match`1.Matches (object value). . & Gt; & Lt; C__DisplayClassc ;. VerifyCalls & gt; The Moq.MethodCall.Matches (IInvocation call) on the B__B (i IInvocation) System.Linq.Enumerable.WhereListIterator`1 is on Moq.Mock & MoT.Matcher.Matches (object value) at lt. MoveNext () System.Linq.Enumerable.Count [TSource] (IEnumerable`1 source) on Moq.Mock.VerifyCalls (Interceptor targetInterceptor, Expectation of MethodCall, Expression Expression, Times Times) on Moq.Mock.Verify [T] on (at Mock Imitation, Expression`1 Expression, Times Bar, String FailMessage in Moq.Mock`1.Verify 383 InnerException Test () on (Expression`1 expression, times bar):   

I'm not sure why I'm not

Edit

I think I know what's going on. In my method I have the method of putting 3 calls (insert method takes in an object).

So I like

  accountRepo.Insert (MyDomainObject); AccountRepo.Insert (MyOtherDomainObject); AccountRepo.Insert (MyOtherOtherDomainObject);   

So those 2 other inserts are overriding it? How can I see it?

The problem is here: it.Is < MyDomainObject & gt; (A = & gt; a.Id == 1) . You can tell with stack trace.

I will change it like this: it.Is & lt; MyDomainObject & gt; (A = & gt; a! = Null & a.Id == 1)

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -