public static void Initialize(TodosContext context)
        {
            context.Database.EnsureCreated();

            if (context.Todo.Any())
            {
                return;
            }

            var tasks = new Todo[]
            {
                new Todo {
                    Name = "First task", Description = "whaaat m8, no wei hello", CreateDate = DateTime.Parse("2010-09-01")
                },
                new Todo {
                    Name = "Second task", Description = "whaaat m8, no wei hello", CreateDate = DateTime.Parse("2010-09-02")
                }
            };

            foreach (var item in tasks)
            {
                context.Todo.Add(item);
            }
            context.SaveChanges();
        }
Exemple #2
0
 public void canAddTodos()
 {
     using (var context = new TodosContext(_options))
     {
         var todos = new TodosRepo(context).GetAll().ToList();
         Assert.AreEqual(1, todos.Count());
         Assert.AreEqual("Test todo", todos[0].Description);
     }
 }
Exemple #3
0
 public void canGetListfromController()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var list = c.Get();
         Assert.AreEqual(1, list.Count());
     }
 }
Exemple #4
0
 public void AlreadyDeletedReturnsNotFoundObjectResult()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var item = c.Delete(2);
         Assert.True(item is NotFoundObjectResult);
     }
 }
Exemple #5
0
 public TodosService(TodosContext context)
 {
     todosContext = context;
     mapper       = new Mapper(new MapperConfiguration(cfg =>
     {
         cfg.CreateMap <TodoFolder, TodoFolderDTO>();
         cfg.CreateMap <TodoItem, TodoItemDTO>();
     })
                               );
 }
Exemple #6
0
 public void CanDeleteTodo()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var viewitem = c.Delete(2);
         var item = c.Get(2);
         Assert.True(item is NotFoundResult);
     }
 }
Exemple #7
0
 public void canAddTodo()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var list = c.Get();
         var newid = list.Last().ID + 1;
         var newitem = new Todos { ID = newid, Description = $"New item {newid}", IsComplete = false };
         c.Put(newid, newitem);
         int newcount = c.Get().Count();
         Assert.AreEqual(newid, newcount);
     }
 }
Exemple #8
0
 public void canUpdateTodo()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var viewitem = (OkObjectResult) c.Get(1);
         var item = (Todos)viewitem.Value;
         item.Description = "updated item";
         c.Post(item);
         var updatedview = (OkObjectResult)c.Get(1);
         var updatedDesc = ((Todos)updatedview.Value).Description;
         Assert.AreEqual(item.Description, updatedDesc);
     }
 }
Exemple #9
0
        public void getAll_Returns_all_Todos()
        {
            //instantiate the context
            var todosContext = new TodosContext(_logger, _configuration);

            //Call the context action
            var result = todosContext.getAll();

            //Assert the result
            Assert.NotNull(result);
            var todos = Assert.IsType <List <ToDoItemModel> >(result);

            //Assert the result
            todos.Should().BeEquivalentTo(todos, options => options.ComparingByMembers <ToDoItemModel>());
        }
Exemple #10
0
        public void create_Creates_one_Todo_And_Returns_1()
        {
            var todo = todosList.First();

            //instantiate the context
            var todosContext = new TodosContext(_logger, _configuration);

            //Call the context action
            var result = todosContext.create(todo);

            //Assert the result
            var returnedValue = Assert.IsType <int>(result);

            //Assert the result
            Assert.Equal(1, returnedValue);
        }
Exemple #11
0
 public void Setup()
 {
     _options = new DbContextOptionsBuilder<TodosContext>()
                     .UseInMemoryDatabase(databaseName: "todos")
                     .Options;
     // Run the test against one instance of the context
     using (var context = new TodosContext(_options))
     {
         var service = new TodosRepo(context);
         foreach (var item in service.GetAll())
         {
             service.Delete(item);
         }
         service.Add(new Todos { ID = 1, Description = "Test todo", IsComplete = false });
     }
 }
Exemple #12
0
        public void getTodoBy_Returns_one_Todo()
        {
            var todo = todosList.First();

            //instantiate the context
            var todosContext = new TodosContext(_logger, _configuration);

            //Call the context action
            var result = todosContext.getBy(t => t.id == todo.id);

            //Assert the result
            Assert.NotNull(result);
            var returnedTodo = Assert.IsType <ToDoItemModel>(result);

            //Assert the result
            returnedTodo.Should().BeEquivalentTo(todo, options => options.ComparingByMembers <ToDoItemModel>());
        }
 public TodoListsController(TodosContext context)
 {
     _context = context;
 }
Exemple #14
0
 public TodoController(TodosContext context)
 {
     this.context = context;
 }
 public TodosRepository(TodosContext context)
 {
     _context = context;
 }
Exemple #16
0
 public TodosRepo(TodosContext context)
 {
     _context = context;
 }
Exemple #17
0
 public TodosController()
 {
     _context = new TodosContext();
 }
Exemple #18
0
 public TodoService(TodosContext todoContext, IMapper mapper)
 {
     _todoContext = todoContext;
     _mapper      = mapper;
 }
Exemple #19
0
 public TodoListsController(TodosContext todosContext)
 {
     _todosContext = todosContext;
 }