Пример #1
0
        public async Task <IActionResult> PostTodoes([FromForm] TodoParameters paramTodoes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Todoes todoAdd = new Todoes();

            todoAdd.Descripcion = paramTodoes.descripcion;
            todoAdd.Estatus     = paramTodoes.estatus;
            todoAdd.Documento   = paramTodoes.documento != null ? paramTodoes.documento.FileName : "";

            if (todoAdd.Documento.Length > 0)
            {
                string timeStamp = DateTime.Now.Ticks.ToString();
                using (var fileStream = new FileStream("wwwroot/App_Data/" + timeStamp + "_" + paramTodoes.documento.FileName, FileMode.Create))
                {
                    paramTodoes.documento.CopyTo(fileStream);
                    todoAdd.Documento = fileStream.Name;
                }
            }
            _context.Add(todoAdd);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTodoes", new { id = todoAdd.TodoId }, todoAdd));
        }
Пример #2
0
        public async Task IsCrearTodoOk()
        {
            // Arrange
            var dbContext  = DbContextMocker.GetTodoesDbContext("TodoApp");
            var controller = new TodoesController(dbContext);

            // Act
            TodoParameters todo = new TodoParameters();

            todo.descripcion = "HOLA IsCrearTodo";
            //Microsoft.AspNetCore.Http.IFormFile formFile;
            //formFile.CopyToAsync()
            todo.documento = null;
            todo.estatus   = "PENDIENTE";

            var response = await controller.PostTodoes(todo);

            var value = (ObjectResult)response;

            //dbContext.Dispose();

            // Assert
            Assert.True(value.StatusCode.Value == 201);
        }