public async Task TestGetAction_And_ReturnsGroup_WhenEverythingIsOK() { string id = "test-id"; GroupSmallDetailDTO expected = new GroupSmallDetailDTO(new Group()) { GroupId = id }; var mockGetGroupSmallDetailQueryHandler = new Mock <IQueryHandler <GetGroupSmallDetailDTOQuery, GroupSmallDetailDTO> >(); mockGetGroupSmallDetailQueryHandler .Setup(x => x.HandleAsync(It.IsAny <GetGroupSmallDetailDTOQuery>())) .ReturnsAsync(expected); // Act var actionResult = await controller.Get(id, mockGetGroupSmallDetailQueryHandler.Object); Assert.IsInstanceOfType(actionResult, typeof(OkObjectResult)); var okResult = actionResult as OkObjectResult; GroupSmallDetailDTO actual = okResult.Value as GroupSmallDetailDTO; Assert.AreSame(expected, actual); Assert.AreEqual(id, actual.GroupId); }
public async Task <IActionResult> Get( string id, [FromServices] IQueryHandler <GetGroupSmallDetailDTOQuery, GroupSmallDetailDTO> _getGroupSmallDetailDTOQueryHandler ) { _logger.LogInformation("Running GET method to FETCH group by ID"); //Gets Bizfly identity from header. BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders(); GetGroupSmallDetailDTOQuery query = new GetGroupSmallDetailDTOQuery(bizflyIdentity, id); GroupSmallDetailDTO result = await _getGroupSmallDetailDTOQueryHandler.HandleAsync(query); if (ModelState.IsValid) { return(Ok(result)); } return(BadRequest(ModelState)); }
public async Task Test_DeleteActionWhenEverythingIsOk() { Group group = new Group("COMAPNY", "test-group", "5c261254-f832-49ad-9ad2-8c76c8e15359", GroupStatus.ACTIVE, null, null); GroupSmallDetailDTO groupDto = new GroupSmallDetailDTO(group); headerUserId = "5c261254-f832-49ad-9ad2-8c76c8e15359"; var mockDeleteGroupHandler = new Mock <IDefaultCommandHandler <DeleteGroupCommand> >(); mockDeleteGroupHandler.Setup(hdl => hdl.Handle(It.IsAny <DeleteGroupCommand>())) .Returns(Task.CompletedTask) .Verifiable(); var result = await controller.Delete("5c261254-f832-49ad-9ad2-8c76c8e15359", mockDeleteGroupHandler.Object); Assert.IsInstanceOfType(result, typeof(NoContentResult)); mockDeleteGroupHandler.Verify(); }
public async Task Test_DeleteActionWhen_HandlerThrowsError() { // Arrange string id = string.Empty; Group group = new Group("COMAPNY", "test-group", "5c261254-f832-49ad-9ad2-8c76c8e15359", GroupStatus.ACTIVE, null, null); GroupSmallDetailDTO groupDto = new GroupSmallDetailDTO(group); var mockDeleteGroupHandler = new Mock <IDefaultCommandHandler <DeleteGroupCommand> >(); List <ValidationFailure> failure = new List <ValidationFailure> { new ValidationFailure("id", "") }; mockDeleteGroupHandler .Setup(hdl => hdl.Handle(It.IsAny <DeleteGroupCommand>())) .Throws(new ValidationException(failure)) .Verifiable(); // Act var result = await controller.Delete(id, mockDeleteGroupHandler.Object); }