Exemple #1
0
        public async Task ThrowExceptionIfToDoItemNotFound()
        {
            var mockRepository   = new Mock <IToDoItemRepository>();
            var expectedToDoItem = Builder <ToDoItem> .CreateNew().Build();

            mockRepository.Setup(x => x.Get(It.IsAny <Guid>())).ReturnsAsync(null as ToDoItem);

            var handler = new GetToDoItemQueryHandler(mockRepository.Object, new Mock <ILogger <GetToDoItemQueryHandler> >().Object);

            await Assert.ThrowsAsync <NotFoundException>(async() => await handler.Handle(new GetToDoItemQuery(), new System.Threading.CancellationToken()));
        }
Exemple #2
0
        public async Task ReturnCorrectViewModelForValidId()
        {
            var mockRepository   = new Mock <IToDoItemRepository>();
            var expectedToDoItem = Builder <ToDoItem> .CreateNew().Build();

            mockRepository.Setup(x => x.Get(It.IsAny <Guid>())).ReturnsAsync(expectedToDoItem);

            var handler = new GetToDoItemQueryHandler(mockRepository.Object, new Mock <ILogger <GetToDoItemQueryHandler> >().Object);

            var response = await handler.Handle(new GetToDoItemQuery(), new System.Threading.CancellationToken());

            Assert.Equal(expectedToDoItem.Name, response.Name);
        }