public void TestAddGetRemove()
        {
            IGenericList <TodoItem> dataBase = new GenericList <TodoItem>();
            TodoItem task1 = new TodoItem("Do something!");
            TodoItem task2 = new TodoItem("Do something else!");

            dataBase.Add(task1);
            dataBase.Add(task2);
            TodoRepository rep = new TodoRepository(dataBase);
            Guid           Id1 = task1.Id;

            Assert.AreEqual(task1, rep.Get(Id1));

            TodoItem task3 = new TodoItem("Do it!");

            Assert.AreEqual(task3, rep.Add(task3));

            Assert.IsTrue(rep.Remove(Id1));
        }
        public void TestMarkAsCompleted()
        {
            IGenericList <TodoItem> dataBase = new GenericList <TodoItem>();
            TodoItem task1 = new TodoItem("Do something!");

            dataBase.Add(task1);
            TodoRepository rep = new TodoRepository(dataBase);

            Guid Id = task1.Id;

            Assert.IsTrue(rep.MarkAsCompleted(Id));
        }
示例#3
0
        public void TestTodoRepositoryRemove()
        {
            TodoItem todo1 = new TodoItem("Some text 1");
            TodoItem todo2 = new TodoItem("Some text 2");
            TodoItem todo3 = new TodoItem("Some text 3");
            TodoItem todo4 = new TodoItem("Some text 4"); // not in the repo

            IGenericList <TodoItem> todoList = new GenericList <TodoItem>();

            todoList.Add(todo1);
            todoList.Add(todo2);
            todoList.Add(todo3);

            TodoRepository todoRepo = new TodoRepository(todoList);

            // Remove todo3 - should return true
            Assert.IsTrue(todoRepo.Remove(todo3.Id));
            // Mark todo4 (which is not in the repo) - should return false
            Assert.IsFalse(todoRepo.Remove(todo4.Id));
            // Now the item count should be 2
            Assert.AreEqual(todoRepo.GetAll().Count, 2);
        }
示例#4
0
        public void TestTodoRepositoryMarkAsCompleted()
        {
            TodoItem todo1 = new TodoItem("Some text 1");
            TodoItem todo2 = new TodoItem("Some text 2");
            TodoItem todo3 = new TodoItem("Some text 3");
            TodoItem todo4 = new TodoItem("Some text 4"); // not in the repo

            IGenericList <TodoItem> todoList = new GenericList <TodoItem>();

            todoList.Add(todo1);
            todoList.Add(todo2);
            todoList.Add(todo3);

            TodoRepository todoRepo = new TodoRepository(todoList);

            // Mark todo2 as complete
            Assert.IsTrue(todoRepo.MarkAsCompleted(todo2.Id));
            // Shouldn't be able to mark todo2 as complete if it is already complete
            Assert.IsFalse(todoRepo.MarkAsCompleted(todo2.Id));
            // Mark todo4 (which is not in the repo) - should return false
            Assert.IsFalse(todoRepo.MarkAsCompleted(todo4.Id));
        }
        public void TestUpdate()
        {
            IGenericList <TodoItem> dataBase = new GenericList <TodoItem>();
            TodoItem task1 = new TodoItem("Do something!");
            TodoItem task2 = new TodoItem("Do something else!");

            dataBase.Add(task1);
            task2.Id = task1.Id;
            TodoRepository rep = new TodoRepository(dataBase);


            Assert.AreEqual(rep.Update(task2), task2);
        }
示例#6
0
        public void TestTodoRepositoryGet()
        {
            IGenericList <TodoItem> todoList = new GenericList <TodoItem>();
            TodoItem todo = new TodoItem("Ran out of ideas for names, I guess.");

            todoList.Add(todo);
            TodoRepository todoRepo1 = new TodoRepository();
            TodoRepository todoRepo2 = new TodoRepository(todoList);

            // Repo should return null when it doesn't contain a GUID
            Assert.IsNull(todoRepo1.Get(todo.Id));
            // Otherwise it should return an item
            Assert.AreEqual(todoRepo2.Get(todo.Id), todo);
        }
示例#7
0
        public void GetFilteredTest()
        {
            GenericList <TodoItem> testGenericList = new GenericList <TodoItem>();

            for (int i = 0; i < 5; i++)
            {
                testGenericList.Add(new TodoItem(i.ToString()));
            }
            TodoRepository  testTodoRepository = new TodoRepository(testGenericList);
            List <TodoItem> testList1          = testTodoRepository.GetFiltered(i => i.Text.Equals("2"));
            List <TodoItem> testList2          = testGenericList.Where(i => i.Text.Equals("2")).ToList();

            Assert.AreEqual(testList1[0], testList2[0]);
        }
示例#8
0
        public void GetActiveTest()
        {
            GenericList <TodoItem> testGenericList = new GenericList <TodoItem>();

            for (int i = 0; i < 100; i++)
            {
                testGenericList.Add(new TodoItem(i.ToString()));
            }
            TodoRepository testTodoRepository = new TodoRepository(testGenericList);

            testTodoRepository.MarkAsCompleted(testGenericList.GetElement(2).Id);
            testTodoRepository.MarkAsCompleted(testGenericList.GetElement(30).Id);
            Assert.AreEqual(testTodoRepository.GetActive().Count, 98);
        }
        public void Enumerable_10Points()
        {
            IGenericList <int> list = new GenericList <int>();

            for (int i = 0; i < 100; i++)
            {
                list.Add(-i);
            }

            foreach (var i in list)
            {
                Assert.AreEqual(i, list.GetElement(-i));
            }
        }
示例#10
0
        public void TestTodoRepositoryGetFiltered()
        {
            TodoItem todo1 = new TodoItem("URGENT: Some text 1");
            TodoItem todo2 = new TodoItem("Some text 2");
            TodoItem todo3 = new TodoItem("URGENT: Some text 3");

            IGenericList <TodoItem> todoList = new GenericList <TodoItem>();

            todoList.Add(todo1);
            todoList.Add(todo2);
            todoList.Add(todo3);

            TodoRepository todoRepo = new TodoRepository(todoList);

            // Test for TodoItems that are URGENT
            List <TodoItem> activeList = todoRepo.GetFiltered((i) => (i.Text.StartsWith("URGENT")));

            // There must be exactly two URGENT items
            Assert.AreEqual(activeList.Count, 2);
            // Those two items must be todo1 and todo3
            Assert.IsTrue(
                ((activeList[0] == todo1) && (activeList[1] == todo3)) || ((activeList[0] == todo3) && (activeList[1] == todo1))
                );
        }
示例#11
0
        public void GetAllTest()
        {
            GenericList <TodoItem> testGenericList = new GenericList <TodoItem>();

            for (int i = 0; i < 101; i++)
            {
                testGenericList.Add(new TodoItem(i.ToString()));
            }
            TodoRepository testTodoRepository = new TodoRepository(testGenericList);

            List <TodoItem> testList   = testTodoRepository.GetAll();
            int             testAdding = testList.Sum(number => int.Parse(number.Text));

            Assert.AreEqual(testAdding, 5050);
        }
示例#12
0
        public void TodoRepositoryTest()
        {
            GenericList <TodoItem> testGenericList = new GenericList <TodoItem>();

            for (int i = 0; i < 100; i++)
            {
                testGenericList.Add(new TodoItem(i.ToString()));
            }
            TodoRepository testTodoRepository = new TodoRepository(testGenericList);

            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(testTodoRepository.Get(testGenericList.GetElement(i).Id), testGenericList.GetElement(i));
            }
        }