Arrange async methods

3 posts, 0 answers
  1. Vikas
    Vikas avatar
    2 posts
    Member since:
    May 2014

    Posted 07 Dec 2015 Link to this post

    I am trying to test async method but i am getting null reference exception.

    I have a service that has a GetAll method which is async: public async Task<IQueryable<T>> GetAll()

    and the method under test is calling this method: await _service.GetAll();

    I am mocking the service and then doing an arrange on the getAll method, but i get a null reference exception when the method is called in the code under test.

    Mock.Arrange(() => mockService.GetAll()).Returns(Task.FromResult<IQueryable<Models.VM>>(vms.AsQueryable()));

     

    Thanks

    Vikas Mittal

  2. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 08 Dec 2015 Link to this post

    Hi Vikas,

    I don't see anything out-of-place with your snippet. Can you give us a full repro project so that we can investigate the issue?

    Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
  4. Vikas
    Vikas avatar
    2 posts
    Member since:
    May 2014

    Posted 08 Dec 2015 in reply to Stefan Link to this post

    It is working now.

     

    Thanks

    vikas

Back to Top