Beispiel #1
0
        public void CreateLottery_IncorrectFieldValues_ThrowsException(int index, string message)
        {
            var lotteryDto = GetCreateLotteryDtoList()[index];

            var result = Assert.ThrowsAsync <LotteryException>(async() => await _sut.CreateLotteryAsync(lotteryDto));

            Assert.That(result.Message, Is.EqualTo(message));
        }
Beispiel #2
0
        public async Task <IActionResult> CreateLottery(CreateLotteryRequest request)
        {
            CreateLotteryResponse response = await _lotteryService.CreateLotteryAsync(request);

            if (response.IsValid())
            {
                return(Ok(response));
            }

            return(BadRequest(response.GetErrors()));
        }
Beispiel #3
0
        public async Task <IHttpActionResult> CreateLottery(CreateLotteryViewModel lotteryViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createLotteryDto = _mapper.Map <CreateLotteryViewModel, LotteryDto>(lotteryViewModel);

            SetOrganizationAndUser(createLotteryDto);

            try
            {
                await _lotteryService.CreateLotteryAsync(createLotteryDto);
            }
            catch (LotteryException e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok());
        }
Beispiel #4
0
        public async Task CreateLottery_Should_Return_Bad_Request()
        {
            // Arrange
            var lotteryViewModel = new CreateLotteryViewModel
            {
                Title = "test"
            };

            var lotteryDto = new LotteryDto
            {
                Title = "test"
            };

            _mapper.Map <CreateLotteryViewModel, LotteryDto>(lotteryViewModel).Returns(lotteryDto);
            _lotteryService.CreateLotteryAsync(lotteryDto).Throws(new LotteryException("Exception"));

            // Act
            var response = await _lotteryController.CreateLottery(lotteryViewModel);

            // Assert
            Assert.IsInstanceOf <BadRequestErrorMessageResult>(response);
            await _lotteryService.Received(1).CreateLotteryAsync(lotteryDto);
        }