Beispiel #1
0
        public async Task Handle_NoteNotFound_ShouldThrowNotFoundException()
        {
            // Arrange
            var note = await _wolkDbContext.CreateAndSaveNote();

            var request = new GetNoteQuery(note.Id + 1);

            // Act / Assert
            await Assert.ThrowsExceptionAsync <NotFoundException>(() =>
                                                                  _handler.Handle(request, CancellationToken.None));
        }
        public void Handle_OnExistingNote_ReturnsNoteViewModel()
        {
            var request = new GetNoteQuery
            {
                NoteId = 1
            };
            var note = new Note
            {
                Id          = 1,
                Description = "test",
                NoteBoardId = "DSC-11",
                SortIndex   = 123,
                Title       = "title"
            };

            var noteRepositoryMock = new Mock <INoteRepository>();

            noteRepositoryMock
            .Setup(x => x.Get(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(note));

            var sut = new GetNoteQueryHandler(noteRepositoryMock.Object);

            var result = sut.Handle(request, new CancellationToken()).GetAwaiter().GetResult();

            result.Should().NotBeNull();
            result.Note.Should().NotBeNull();
            result.Note.Id.Should().Be(1);
        }
        public void Handle_OnNotExistingNote_ThrowsNotFoundException()
        {
            var request = new GetNoteQuery
            {
                NoteId = 1
            };

            var noteRepositoryMock = new Mock <INoteRepository>();

            noteRepositoryMock
            .Setup(x => x.Get(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Note>(null));

            var sut = new GetNoteQueryHandler(noteRepositoryMock.Object);

            Action act = () => sut.Handle(request, new CancellationToken()).GetAwaiter().GetResult();

            act.Should().ThrowExactly <NotFoundException>();
        }