public async Task HandleGetAllCommand_ShouldCallListServiceGetAll() { // Data var model = new ListModel { Id = Guid.NewGuid(), Name = "Todo list" }; var getAllListsCommand = new GetAllListsCommand { UserId = "username" }; IEnumerable <ListModel> modelsList = new List <ListModel> { model }; // Setup _mockListService.Setup(x => x.GetAllLists(getAllListsCommand.UserId)).Returns(Task.FromResult(modelsList)).Verifiable(); _mockMessageContext.Setup(x => x.Reply(It.Is <GetResponse>(y => y.Models == modelsList), It.IsAny <ReplyOptions>())) .Returns(Task.CompletedTask).Verifiable(); // Test var handler = new ListsEventHandler(_mockListService.Object); await handler.Handle(getAllListsCommand, _mockMessageContext.Object); // Analysis _mockListService.Verify(); _mockMessageContext.Verify(); }
public async Task <IActionResult> GetAll() { var getAlllistsCommand = new GetAllListsCommand(); var user = await _userManagerWrapper.FindByNameAsync(User.Identity.Name); getAlllistsCommand.UserId = user.Id; var sendOptions = new SendOptions(); sendOptions.SetDestination("LifeManager.Lists"); var response = await _endpointInstance.Request <GetResponse>(getAlllistsCommand, sendOptions).ConfigureAwait(false); return(Ok(new { Response = response.Models })); }
public async Task Handle(GetAllListsCommand message, IMessageHandlerContext context) { var lists = await _listService.GetAllLists(message.UserId); await context.Reply(new GetResponse { Models = lists }); }