Skip to content

Adding Try Catch to Method returns empty List #1595

@Denisjc

Description

@Denisjc

When I add a Try Catch block to my method that is calling the mocked object I get nothing in return

But removing the Try Catch block makes the mock return the correct List

`
//Mock Setup

 var list = ClearanceDataHelpers.GetFullUnsuccessfulList();

  var unitOfWork = new Mock<IUnitOfWorkApp>();
  var repoMock = new Mock<IRepositoryViewAsync<ClearanceList>>();

  repoMock.Setup(r => r.GetListAsync(x => x.VisitorId == It.IsAny<int>())).ReturnsAsync(list);

  unitOfWork.Setup(x => x.ClearanceListRepo).Returns(repoMock.Object);
  return unitOfWork;

`

Unit Test Part
var dataService = new DataService(_logger.Object, _cache.Object, unitOfWork.Object); var clearance = dataService.GetLatestClearanceByVisitorAsync(1, 1).Result;

Service Method GetLatestClearanceByVisitorAsync - Fails
try { var list = await _unitOfWork.ClearanceListRepo.GetListAsync(x => x.VisitorId == visitorId); } catch (Exception ex) { }

Service Method GetLatestClearanceByVisitorAsync - Works with no Try Catch Block
var list = await _unitOfWork.ClearanceListRepo.GetListAsync(x => x.VisitorId == visitorId);

Back this issue
Back this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions