public async Task CallRepositoryWhenHandling() { var handler = new ToDoItemsQueryHandler(_mockToDoRepository.Object); await handler .Handle(new ToDoItemsQuery(new AllToDoItems()), new System.Threading.CancellationToken()) .ConfigureAwait(false); _mockToDoRepository.Verify(x => x.GetItemsAsync(It.IsAny <ICacheableDataSpecification <ToDoItem> >()), Times.Once); }
public async Task CallRepositoryWhenHandling() { var handler = new ToDoItemsQueryHandler(_mockToDoRepository.Object); await handler .Handle(new ToDoItemsQuery(new AllToDoItems()), new System.Threading.CancellationToken()) .ConfigureAwait(false); _mockToDoRepository.Verify(x => x.GetAsync(It.IsAny <Expression <Func <ToDoItem, bool> > >()), Times.Once); }
public async Task ReturnToDoItem() { var handler = new ToDoItemsQueryHandler(_mockToDoRepository.Object); var response = await handler .Handle(new ToDoItemsQuery(new AllToDoItems()), new System.Threading.CancellationToken()) .ConfigureAwait(false); response.Should().NotBeNull(); response.Should().NotBeNullOrEmpty() .And.HaveCount(6); }
public async Task ReturnSuccessFalseOnError() { var mockRepo = new Mock <IRepository <ToDoItem> >(); mockRepo .Setup(x => x.GetItemsAsync(It.IsAny <ICacheableDataSpecification <ToDoItem> >())) .ThrowsAsync(new System.Exception("Error")) .Verifiable(); var handler = new ToDoItemsQueryHandler(mockRepo.Object); var result = await handler .Handle(new ToDoItemsQuery(new AllToDoItems()), new System.Threading.CancellationToken()) .ConfigureAwait(false); mockRepo.Verify(x => x.GetItemsAsync(It.IsAny <ICacheableDataSpecification <ToDoItem> >()), Times.Once); result.Should().BeNull(); }