public void Create_WithNullHttpWebResponse_ReturnsNullHttpResponse()
        {
            // Arrange
            IHttpWebResponseAdapter response = null;

            // Act
            var actualResponse = helper.Create(response);

            // Assert
            Assert.IsNull(actualResponse);
        }
Exemplo n.º 2
0
        public IActionResult ListUsers()
        {
            try
            {
                var users = _serviceUser.RecoverAll();

                return(HttpResponseHelper.Create(HttpStatusCode.Created, ApiConstants.MSG_GENERIC_SUCCESS, users));
            }
            catch (Exception ex)
            {
                return(HttpResponseHelper.Create(HttpStatusCode.InternalServerError, ApiConstants.ERR_GENERIC, ex));
            }
        }
Exemplo n.º 3
0
        public IActionResult Update([FromBody] AdministratorModel administratorModel)
        {
            try
            {
                var user = _serviceAdministrator.Update(administratorModel);

                return(HttpResponseHelper.Create(HttpStatusCode.Created, ApiConstants.MSG_GENERIC_UPDATE_SUCCESS, user));
            }
            catch (Exception ex)
            {
                return(HttpResponseHelper.Create(HttpStatusCode.BadRequest, ApiConstants.ERR_GENERIC, ex));
            }
        }
Exemplo n.º 4
0
        public IActionResult Create([FromBody] AdministratorModel administratorModel)
        {
            try
            {
                var admin = _serviceAdministrator.Insert(administratorModel);

                return(HttpResponseHelper.Create(HttpStatusCode.Created, ApiConstants.MSG_REGISTER_ADMIN_SUCCESS, admin));
            }
            catch (Exception ex)
            {
                return(HttpResponseHelper.Create(HttpStatusCode.BadRequest, ApiConstants.ERR_GENERIC, ex));
            }
        }
Exemplo n.º 5
0
        public ActionResult Login(UserLoginModel userLoginModel, [FromServices] IConfiguration config)
        {
            var user = _serviceUser.Login(userLoginModel.Email, userLoginModel.Password);

            if (user == null)
            {
                return(HttpResponseHelper.Create(HttpStatusCode.Unauthorized, ApiConstants.ERR_EMAIL_PASSWORD_INCORRECT));
            }

            var token = TokenHelper.GenerateUserToken(user, config.GetSection("AppSettings:Token").Value);

            return(HttpResponseHelper.Create(HttpStatusCode.OK, ApiConstants.MSG_LOGIN_SUCCESS, token));
        }
Exemplo n.º 6
0
        public ActionResult Register(CreateUserModel createUserModel)
        {
            if (_serviceUser.GetAll().FirstOrDefault(u => u.Email == createUserModel.Email) != null)
            {
                return(HttpResponseHelper.Create(HttpStatusCode.BadRequest, ApiConstants.ERR_EMAIL_IN_USE));
            }

            try
            {
                _serviceUser.Register(createUserModel);
                return(HttpResponseHelper.Create(HttpStatusCode.Created, ApiConstants.MSG_REGISTER_SUCCESS));
            }
            catch (Exception ex)
            {
                return(HttpResponseHelper.Create(HttpStatusCode.InternalServerError, ApiConstants.ERR_GENERIC, ex));
            }
        }