public async void Handle_Exception_Test() { this._unitOfUnitMock .Setup(mock => mock.OrganisationRepository.ReadOrganisationWithChildren(It.IsAny <int>())) .Throws(new Exception()); var command = new ReadOrganisationWithChildrenCommand(1); var handler = new ReadOrganisationWithChildrenHandler(this._unitOfUnitMock.Object); var result = await handler.Handle(command, new CancellationTokenSource().Token); Assert.False((bool)result); }
public async void Handle_Succes_Test() { OrganisationWithChildren resultpre = new OrganisationWithChildren(); this._unitOfUnitMock .Setup(mock => mock.OrganisationRepository.ReadOrganisationWithChildren(It.IsAny <int>())) .Returns(Task.FromResult(resultpre)); var command = new ReadOrganisationWithChildrenCommand(1); var handler = new ReadOrganisationWithChildrenHandler(this._unitOfUnitMock.Object); var result = await handler.Handle(command, new CancellationTokenSource().Token); Assert.Equal(result, resultpre); }
public async Task <IActionResult> ReadOrganisationWithChildren(int id) { if (id <= 0) { return(new BadRequestObjectResult("Invalid ID")); } var command = new ReadOrganisationWithChildrenCommand(id); var result = await this._mediator.Send(command); if (result == null) { return(new BadRequestObjectResult("Something went wrong")); } return(new OkObjectResult(result)); }