コード例 #1
0
        public async Task <IActionResult> ReadAllTitle()
        {
            var command = new ReadAllTitleCommand();
            var result  = await this._mediator.Send(command);

            if (result == null)
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }

            return(new OkObjectResult(result));
        }
コード例 #2
0
        public async void ReturnListOfTitle()
        {
            _unitOfWork.Setup(mock => mock.TitleRepository.ReadAll())
            .Returns(Task.FromResult(list));

            var            command     = new ReadAllTitleCommand();
            var            handler     = new ReadAllTitleHandler(_unitOfWork.Object);
            List <DBTitle> returnValue = (List <DBTitle>) await handler.Handle(command, new CancellationToken());

            Assert.NotNull(returnValue);
            Assert.Equal(3, returnValue.Count);
        }
コード例 #3
0
        public async void ReturnFalse_IfResultIsNull()
        {
            List <DBTitle> list = null;

            _unitOfWork.Setup(mock => mock.TitleRepository.ReadAll())
            .Returns(Task.FromResult(list));
            var command = new ReadAllTitleCommand();

            var handler     = new ReadAllTitleHandler(_unitOfWork.Object);
            var returnValue = await handler.Handle(command, new CancellationToken());

            Assert.Null(returnValue);
        }
コード例 #4
0
        public async void ReturnNull_IfExceptionOccurs()
        {
            var exc = new Exception();

            _unitOfWork.Setup(mock => mock.TitleRepository.ReadAll())
            .Throws(exc);
            var command = new ReadAllTitleCommand();

            var handler     = new ReadAllTitleHandler(_unitOfWork.Object);
            var returnValue = await handler.Handle(command, new CancellationToken());

            Assert.Null(returnValue);
        }