Example #1
0
        public async void Handle_Succes_Test()
        {
            ProjectReadModel returnn = new ProjectReadModel();

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.ReadProjectWithChildren(It.IsAny <int>()))
            .Returns(Task.FromResult(returnn));

            ReadProjectCommand command = new ReadProjectCommand(1);
            ReadProjectHandler handler = new ReadProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.Equal(result, returnn);
        }
Example #2
0
        public async void Handle_Exception_Test()
        {
            ProjectReadModel returnn = new ProjectReadModel();

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.ReadProjectWithChildren(It.IsAny <int>()))
            .Throws(new Exception());

            ReadProjectCommand command = new ReadProjectCommand(1);
            ReadProjectHandler handler = new ReadProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.False((bool)result);
        }
        public async Task <IActionResult> ReadProject(int id)
        {
            if (id <= 0)
            {
                return(new BadRequestObjectResult("Invalid Id"));
            }

            var command = new ReadProjectCommand(id);
            var result  = this._mediator.Send(command).Result;

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

            return(new OkObjectResult(result));
        }
Example #4
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                if (!wasFirstLogged)
                {
                    await _logger.LogAsync(LogLevel.Info, $"{nameof(ReadProjectJob)} was started.", CancellationToken.None);
                }

                wasFirstLogged = true;

                await _mediator.Send(ReadProjectCommand.Create());
            }
            catch (Exception exception)
            {
                await _logger.LogAsync(LogLevel.Error, $"{nameof(ReadProjectJob)} terminated unexpectedly.", CancellationToken.None, exception);
            }
        }