示例#1
0
        public async Task AgregaNuevaCategoria_DatosCorrectos_RegresaVerdaderoAsync()
        {
            //Inicialización de datos (Arrange)
            Servicios.Inicializa();
            contexto = Servicios.caducaContext;
            var categoriaDAO = new CategoriaDAO(contexto, locService);
            var categoria    = new Categoria();

            categoria.Clave  = 2;
            categoria.Nombre = "Antibióticos";
            //Método a probar (Act)
            var esCorrecto = await categoriaDAO.AgregarAsync(categoria);

            //Comprobación de resultados (Assert)
            Assert.IsTrue(esCorrecto);
        }
示例#2
0
        public async Task <IActionResult> PostCategoria([FromBody] Categoria categoria)
        {
            var authorizationResult = await _authorizationService
                                      .AuthorizeAsync(User, permiso, Operaciones.Crear);

            //Si el resultado no fue exitoso regresamos una lista vacia
            if (!authorizationResult.Succeeded)
            {
                return(StatusCode(403, String.Format(this._localizer.GetLocalizedHtmlString("ForbiddenUpdate"), "La categoría")));
            }

            if (!await categoriaDAO.AgregarAsync(categoria))
            {
                return(StatusCode(categoriaDAO.customError.StatusCode,
                                  categoriaDAO.customError.Message));
            }
            this.Id = categoria.Id;
            return(CreatedAtAction("GetCategoria", new { id = categoria.Id }, categoria));
        }