Exemplo n.º 1
0
        public void AddTodoTasksToContext()
        {
            var builder = new DbContextOptionsBuilder <TodoContext>();

            builder.UseInMemoryDatabase("TodoDB");
            var options = builder.Options;

            using (var context = new TodoContext(options))
            {
                var todoTasks = new List <TodoTask>
                {
                    new TodoTask {
                        Id = 1, Name = "Item1", IsComplete = true
                    },
                    new TodoTask {
                        Id = 2, Name = "Item2", IsComplete = true
                    },
                };

                context.AddRange(todoTasks);
                context.SaveChanges();
            }

            using (var context = new TodoContext(options))
            {
                Assert.Equal(2, context.TodoTasks.Count());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post(List <IFormFile> files)
        {
            ValidateFile(files);
            var dataTable = ParseToDataTable(files);

            if (dataTable.Rows.Count == 0)
            {
                return(Ok(new { rows = dataTable.Rows.Count, columns = dataTable.Columns.Count }));
            }

            var timeBlocks = DataTableConverter.ToTimeBlocks(dataTable);

            Context.AddRange(timeBlocks);
            await Context.SaveChangesAsync();

            return(Ok(new { rows = dataTable.Rows.Count, columns = dataTable.Columns.Count }));
        }
Exemplo n.º 3
0
 //create Importances: hight,normal,low
 public static void CreateDefaultImportances(TodoContext context)
 {
     if (context.Importances.Count() == 0)
     {
         List <Importance> importances = new List <Importance>
         {
             new Importance {
                 Name = "low", DigitValue = 0
             },
             new Importance {
                 Name = "normal", DigitValue = 1
             },
             new Importance {
                 Name = "hight", DigitValue = 2
             }
         };
         context.AddRange(importances);
         context.SaveChanges();
     }
 }
        public void Setup()
        {
            builder = new DbContextOptionsBuilder <TodoContext>();
            builder.UseInMemoryDatabase("MyInMemoryDb");
            var options = builder.Options;

            context = new TodoContext(options);
            var todos = new List <TodoItem>
            {
                new TodoItem {
                    Id = 1, Name = "Mow the Lawn", IsComplete = false
                },
                new TodoItem {
                    Id = 2, Name = "Do the Dishes", IsComplete = false
                }
            };

            context.AddRange(todos);
            context.SaveChanges();
        }
Exemplo n.º 5
0
        public void Setup()
        {
            _todosContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>()
                                            .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options);

            _todos = new Todo[]
            {
                new Todo {
                    Id = Guid.NewGuid(), Text = Guid.NewGuid().ToString(), CreatedAt = DateTime.Now, IsCompleted = false
                },
                new Todo {
                    Id = Guid.NewGuid(), Text = Guid.NewGuid().ToString(), CreatedAt = DateTime.Now, IsCompleted = true
                },
                new Todo {
                    Id = Guid.NewGuid(), Text = Guid.NewGuid().ToString(), CreatedAt = DateTime.Now, IsCompleted = false
                }
            };

            _todosContext.AddRange(_todos);
            _todosContext.SaveChanges();

            _sut = new TodosController(_todosContext);
        }
Exemplo n.º 6
0
 public void AddRange(List <Todo> todos)
 {
     _context.AddRange(todos);
     _context.SaveChanges();
 }