Esempio n. 1
0
        public void RegisterToRaceNoError()
        {
            var viewModel = new RegisterToRaceViewModel();

            var result = _Sut.RegisterToRace(viewModel);

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(viewModel, (result as OkObjectResult).Value);
        }
Esempio n. 2
0
        public void RegisterToRaceBusinessError()
        {
            var viewModel = new RegisterToRaceViewModel();
            var exception = new BusinessException("", BLErrorCodes.Duplicate);

            _BLMock.Setup(bl => bl.RegisterToRace(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())).Throws(exception);

            var result = _Sut.RegisterToRace(viewModel);

            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual((int)BLErrorCodes.Duplicate, (int)(result as BadRequestObjectResult).Value);
        }
Esempio n. 3
0
        public void RegisterToRaceException()
        {
            var viewModel        = new RegisterToRaceViewModel();
            var exceptionMessage = "a";
            var exception        = new Exception(exceptionMessage);

            _BLMock.Setup(bl => bl.RegisterToRace(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())).Throws(exception);

            var result = _Sut.RegisterToRace(viewModel);

            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            Assert.AreEqual(500, (result as StatusCodeResult).StatusCode);

            _LoggerMock.VerifyLog(LogLevel.Error, Times.Once, $"Error in {typeof(AppApiController)}: {exceptionMessage}");
        }
Esempio n. 4
0
        public IActionResult RegisterToRace(RegisterToRaceViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                viewModel.Name = _AppApiBL.RegisterToRace(viewModel.RaceId, viewModel.TeamId, viewModel.UniqueId);
                return(Ok(viewModel));
            }
            catch (BusinessException ex)
            {
                return(BadRequest((ErrorCodes)ex.ErrorCode));
            }
            catch (Exception ex)
            {
                _Logger.LogError(ex, $"Error in {typeof(AppApiController)}: {ex.Message}");
                return(StatusCode(500));
            }
        }