public async void Get_Items_Returns_Not_Empty_Collection() { // arrange var repository = new Mock <IItemRepository>(); repository .Setup(repo => repo.GetItemsAsync(It.IsAny <GetItemsRequest>())) .Returns(Task.FromResult( new GetItemsResponse(true, new List <IItem> { new Item { ItemId = Guid.NewGuid(), Title = "Test", Value = 1, MaxValue = 1 } }))); var useCase = new GetItemsUseCase(repository.Object); var outputPort = new GetItemsPresenter(); var controller = new ItemController(useCase, outputPort); var definition = new { Items = new List <Item>(), Success = true }; //to avoid interface deserialization and saving type // act var resultJson = await controller.GetItems(null, 1, 1); // assert var result = JsonConvert.DeserializeAnonymousType(((ContentResult)resultJson).Content, definition); Assert.True(result.Items.Count == 1); }
public async void GetItems_Request_Handled() { var mockItemRepository = new Mock <IItemRepository>(); mockItemRepository .Setup(repo => repo.GetItemsAsync(It.IsAny <GetItemsRequest>())) .Returns(Task.FromResult(new GetItemsResponse(true, new List <IItem> { new Item() }))); var useCase = new GetItemsUseCase(mockItemRepository.Object); var mockOutputPort = new Mock <IOutputPort <GetItemsResponse> >(); mockOutputPort .Setup(outputPort => outputPort.Handle(It.IsAny <GetItemsResponse>())).Verifiable(); //act await useCase.Handle(new GetItemsRequest(null, 1, 1), mockOutputPort.Object); // assert mockOutputPort.Verify(port => port.Handle(It.IsAny <GetItemsResponse>()), Times.Once); }