Esempio n. 1
0
        public async Task <IActionResult> CreateActivityResearcher([FromBody] ActivityResearcher model)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult("Invalid model inputs"));
            }

            CreateActivityResearcherCommand command = new CreateActivityResearcherCommand(model);

            try
            {
                var result = await this._mediator.Send(command);

                if (result == null)
                {
                    return(new BadRequestObjectResult("Something went wrong"));
                }
                if (result.GetType() == typeof(bool) && (bool)result == false)
                {
                    return(new BadRequestObjectResult("Something went wrong"));
                }
                if (result.GetType() == typeof(string))
                {
                    return(new BadRequestObjectResult(result));
                }
                return(new OkObjectResult(result));
            }
            catch (Exception e)
            {
                throw;
            }
        }
        public async void ReturnExceptionIfBadInformation()
        {
            var test = new Exception("");

            _unitOfWork.Setup(mock => mock.ActivityRepository.CreateActivityResearcher(It.IsAny <ActivityResearcher>()))
            .Throws(test);

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

            Assert.False((bool)returnValue);
        }
Esempio n. 3
0
        public async void ReturnFalseIfBadInformation()
        {
            Activity tempActivity = null;

            _unitOfWork.Setup(mock => mock.ActivityRepository.Create(It.IsAny <Activity>()))
            .Returns(tempActivity);

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

            Assert.False((bool)returnValue);
        }
        public async void ReturnFalseIfBadInformation()
        {
            var tempActivityResearcher = new ActivityResearcher()
            {
                ActivityId   = -1,
                Created      = DateTime.Now,
                ResearcherId = -1,
                UserId       = -1,
                Id           = -1
            };

            _unitOfWork.Setup(mock => mock.ActivityRepository.CreateActivityResearcher(It.IsAny <ActivityResearcher>()))
            .Returns(false);

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

            Assert.False((bool)returnValue);
        }