public void AddTORepositorty() { TodoRepository rep = new TodoRepository(); TodoItem item1 = new TodoItem("Test1"); TodoItem item2 = new TodoItem("Test2"); rep.Add(item1); Assert.AreEqual(item1, rep.Get(item1.Id)); rep.Add(item2); Assert.AreEqual(item2, rep.Get(item2.Id)); Assert.AreEqual(item1, rep.Get(item1.Id)); Assert.AreEqual(2, rep.Count()); }
public void GetTest1() { TodoItem item1 = new TodoItem("1"); TodoItem item2 = new TodoItem("2"); TodoItem item3 = new TodoItem("3"); TodoRepository repository = new TodoRepository(); repository.Add(item1); repository.Add(item2); repository.Add(item3); Assert.AreEqual(item1, repository.Get(item1.Id)); }
public void RemoveTest1() { TodoItem item1 = new TodoItem("1"); TodoItem item2 = new TodoItem("2"); TodoItem item3 = new TodoItem("3"); TodoRepository repository = new TodoRepository(); repository.Add(item1); repository.Add(item2); repository.Add(item3); Assert.IsTrue(repository.Remove(item1.Id)); }
public void MarkAsCompletedTest1() { TodoItem item1 = new TodoItem("1"); TodoItem item2 = new TodoItem("2"); TodoItem item3 = new TodoItem("3"); TodoRepository repository = new TodoRepository(); repository.Add(item1); repository.Add(item2); repository.Add(item3); Assert.IsTrue(repository.MarkAsCompleted(item2.Id)); }
public void GetActiveTest() { ITodoRepository repository = new TodoRepository(); var todoItem = new TodoItem("Eggs"); repository.Add(todoItem); Assert.IsTrue(repository.MarkAsCompleted(todoItem.Id)); todoItem = new TodoItem("Soda"); repository.Add(todoItem); todoItem = new TodoItem("Apples"); repository.Add(todoItem); Assert.AreEqual(2, repository.GetActive().Count); }
public void GetAllTest() { ITodoRepository repository = new TodoRepository(); var temp1 = new TodoItem("Hello"); var temp2 = new TodoItem("It's me"); var temp3 = new TodoItem("Hay!"); repository.Add(temp1); repository.Add(temp2); repository.Add(temp3); Assert.AreEqual(3, repository.GetAll().Count); }
public void Completed() { TodoRepository rep = new TodoRepository(); TodoItem item1 = new TodoItem("Test1"); TodoItem item2 = new TodoItem("Test2"); item1.DateCompleted = null; item2.DateCompleted = null; rep.Add(item2); rep.Add(item1); rep.MarkAsCompleted(item2.Id); Assert.AreEqual(1, rep.GetCompleted().Count); Assert.AreEqual(1, rep.GetActive().Count); }
public void RemoveFromRepository() { TodoRepository rep = new TodoRepository(); TodoItem item1 = new TodoItem("Test1"); TodoItem item2 = new TodoItem("Test2"); TodoItem item3 = new TodoItem("Test3"); rep.Add(item2); rep.Add(item1); Assert.AreEqual(false, rep.Remove(item3.Id)); Assert.AreEqual(2, rep.Count()); Assert.AreEqual(true, rep.Remove(item2.Id)); }
public void GetTest2() { TodoItem item1 = new TodoItem("1"); TodoItem item2 = new TodoItem("2"); TodoItem item3 = new TodoItem("3"); TodoItem item4 = new TodoItem("4"); TodoRepository repository = new TodoRepository(); repository.Add(item1); repository.Add(item2); repository.Add(item3); Assert.IsNull(repository.Get(item4.Id)); }
public void TestRemove() { TodoRepository repo = new TodoRepository(); TodoItem item1 = new TodoItem("prvi"); TodoItem item2 = new TodoItem("drugi"); repo.Add(item1); repo.Add(item2); Assert.AreEqual(item1, repo.Get(item1.Id)); Assert.IsTrue(repo.Remove(item1.Id)); Assert.IsFalse(repo.Remove(item1.Id)); }
public void RemoveWillReturnFalseIfElementNotFound() { ITodoRepository repository = new TodoRepository(); var todoItem1 = new TodoItem(" Groceries "); repository.Add(todoItem1); var todoItem2 = new TodoItem(" Krumpir "); repository.Add(todoItem2); var todoItem3 = new TodoItem(" Kulen "); repository.Add(todoItem3); Assert.IsFalse(repository.Remove(new Guid())); }
public void GetAllTest() { TodoRepository repository = new TodoRepository(); TodoItem first = new TodoItem("Faks"); TodoItem second = new TodoItem("Skola"); TodoItem third = new TodoItem("Vrtic"); repository.Add(first); repository.Add(second); repository.Add(third); CollectionAssert.AreEqual(repository.GetAll().ToArray(), new TodoItem[] { first, second, third }); }
public void UpdatingWithNonexistingItemAddsItem() { ITodoRepository repository = new TodoRepository(); var FirstTodoItem = new TodoItem("Chore 1"); var SecondTodoItem = new TodoItem("Chore 2"); repository.Add(FirstTodoItem); repository.Add(SecondTodoItem); ITodoRepository secondRepository = new TodoRepository(); secondRepository.Add(FirstTodoItem); secondRepository.Update(SecondTodoItem); Assert.AreEqual(repository.GetAll().Count, secondRepository.GetAll().Count); }
public void GetTest() { TodoRepository repository = new TodoRepository(); TodoItem first = new TodoItem("Faks"); TodoItem second = new TodoItem("Skola"); TodoItem third = new TodoItem("Vrtic"); repository.Add(first); repository.Add(second); repository.Add(third); Assert.AreEqual(repository.Get(second.Id), second); }
public void GetCompletedTest() { ITodoRepository repository = new TodoRepository(); var todoItem = new TodoItem("Groceries"); todoItem.MarkAsCompleted(); var todoItem2 = new TodoItem("Beverages"); repository.Add(todoItem); repository.Add(todoItem2); List <TodoItem> list = repository.GetActive(); Assert.AreEqual(list.Count, 1); }
public void GetFilteredReturnsItemsMeetingTheCondition() { IToDoRepository repository = new TodoRepository(); ToDoItem item1 = new ToDoItem("test1"); ToDoItem item2 = new ToDoItem("test2"); ToDoItem item3 = new ToDoItem("test2"); repository.Add(item2); repository.Add(item1); repository.Add(item3); var testList = repository.GetFiltered(x => String.Compare(x.Text, "test2") == 0); Assert.IsTrue(testList.Count == 2 && testList.IndexOf(item2) != -1 && testList.IndexOf(item3) != 0); }
public void GetAllGetsAllItems() { IToDoRepository repository = new TodoRepository(); ToDoItem item1 = new ToDoItem("test1"); ToDoItem item2 = new ToDoItem("test2"); item2.DateCreated = DateTime.UtcNow; repository.Add(item2); repository.Add(item1); List <ToDoItem> list = repository.GetAll(); Assert.AreEqual(list.Count, 2); Assert.IsTrue(list.IndexOf(item1) == 0 && list.IndexOf(item2) == 1); }
public void GetAllTest() { ITodoRepository repository = new TodoRepository(); var todoItem = new TodoItem("Groceries"); Thread.Sleep(2000); var todoItem2 = new TodoItem("Beverages"); repository.Add(todoItem); repository.Add(todoItem2); List <TodoItem> list = repository.GetAll(); Assert.IsTrue(list[0].DateCreated > list[1].DateCreated); }
public void MultipleActions() { ITodoRepository _repository = new TodoRepository(LiteDbLocation); _repository.Drop(); // For testing only // Create data first for update for (int i = 0; i < 10; i++) { _repository.Add(new TodoModel { Description = "Todo # " + i.ToString(), AddedBy = UserEmail, DateAdded = DateTime.Now, TodoDate = DateTime.Now }); } _repository.Commit(); IList <TodoModel> _testData = _repository.GetAll(); // Test starts here Random _randomIndex = new Random(); IList <int> _indexes = Enumerable.Range(0, 9).OrderBy(x => _randomIndex.Next()).Take(2).ToList(); _repository.Add(new TodoModel { Description = "This has been added.", AddedBy = UserEmail, DateAdded = DateTime.Now, TodoDate = DateTime.Now }); _repository.Remove(_testData[_indexes.First()]._id); TodoModel _toUpdate = _testData[_indexes.Last()]; _toUpdate.Description = "I was updated"; _toUpdate.IsCompleted = true; _repository.Modify(_toUpdate); _repository.Commit(); TodoModel _updatedResult = _repository.Get(_toUpdate._id); Assert.Equal(_updatedResult.Description, _toUpdate.Description); Assert.Equal(_updatedResult.IsCompleted, _toUpdate.IsCompleted); Assert.Equal(10, _repository.GetAll().Count); }
public void RemoveTest() { TodoRepository repository = new TodoRepository(); TodoItem first = new TodoItem("Faks"); TodoItem second = new TodoItem("Skola"); TodoItem third = new TodoItem("Vrtic"); repository.Add(first); repository.Add(second); repository.Add(third); Assert.IsTrue(repository.Remove(first.Id)); Assert.IsFalse(repository.Remove(first.Id)); }
public void GetFilteredTest() { TodoItem a = new TodoItem("task a"); TodoItem b = new TodoItem("task b"); TodoRepository t = new TodoRepository(); t.Add(a); t.Add(b); List <TodoItem> l = t.GetFiltered(i => i.Text == "task b"); Assert.IsTrue(l.Count == 1); Assert.IsTrue(l.ElementAt(0).Text == "task b"); }
public void GetAllReturnsAllItems() { ITodoRepository repository = new TodoRepository(); var FirstTodoItem = new TodoItem("Chore 1"); var SecondTodoItem = new TodoItem("Chore 2"); repository.Add(FirstTodoItem); repository.Add(SecondTodoItem); ITodoRepository secondRepository = new TodoRepository(); secondRepository.Add(FirstTodoItem); secondRepository.Add(SecondTodoItem); Assert.AreEqual(2, secondRepository.GetAll().Count); //////////////////////////// }
public void CompletedTest() { var t1 = new TodoRepository(); TodoItem a = new TodoItem("a"), b = new TodoItem("b"), c = new TodoItem("c"); t1.Add(a); t1.Add(b); t1.MarkAsCompleted(b.Id); Assert.IsFalse(t1.Get(a.Id).IsCompleted); Assert.IsTrue(t1.Get(b.Id).IsCompleted); Assert.IsFalse(t1.MarkAsCompleted(c.Id)); }
public void GetAllItems() { ITodoRepository repository = new TodoRepository(); TodoItem item1 = new TodoItem("1"); TodoItem item2 = new TodoItem("2"); TodoItem item3 = new TodoItem("3"); TodoItem item4 = new TodoItem("4"); repository.Add(item1); repository.Add(item2); repository.Add(item3); Assert.IsTrue(repository.GetAll().Count() == 3); repository.Add(item4); Assert.IsTrue(repository.GetAll().Count() == 4); }
public void MarkAsCompletedTest() { ITodoRepository rep = new TodoRepository(); var todoItem1 = new TodoItem("Groceries"); var todoItem2 = new TodoItem("Books"); var todoItem3 = new TodoItem("House decorations"); todoItem1.MarkAsCompleted(); rep.Add(todoItem1); rep.Add(todoItem2); rep.Add(todoItem3); Assert.AreEqual(true, rep.MarkAsCompleted(todoItem1.Id)); }
public void GetFilteredTest() { TodoItem ti1 = new TodoItem("a"); TodoItem ti2 = new TodoItem("b"); TodoItem ti3 = new TodoItem("c"); TodoRepository tr = new TodoRepository(null); tr.Add(ti1); tr.Add(ti2); tr.Add(ti3); List <TodoItem> list = new List <TodoItem>(); list.Add(ti3); CollectionAssert.AreEqual(tr.GetFiltered(s => s.Text.Equals("c")), list); }
public void GetActive() { ITodoRepository testTodoRepository = new TodoRepository(); TodoItem firstItem = new TodoItem("Test item number 1."); TodoItem secondItem = new TodoItem("Test item number 2."); TodoItem thirdItem = new TodoItem("Test item number 3."); testTodoRepository.Add(firstItem); testTodoRepository.Add(secondItem); thirdItem.MarkAsCompleted(); testTodoRepository.Add(thirdItem); Assert.AreEqual(2, testTodoRepository.GetActive().Count); }
public void RemoveWillRemoveElementIfFoundAndReturnTrue() { ITodoRepository repository = new TodoRepository(); var todoItem1 = new TodoItem(" Groceries "); repository.Add(todoItem1); var todoItem2 = new TodoItem(" Krumpir "); repository.Add(todoItem2); var todoItem3 = new TodoItem(" Kulen "); repository.Add(todoItem3); Assert.IsTrue(repository.Remove(todoItem2.Id)); Assert.AreEqual(repository.Get(todoItem2.Id), null); }
public void GetTest() { ITodoRepository repository = new TodoRepository(); var todoItem = new TodoItem("Groceries"); var todoItem2 = new TodoItem("Football match"); var todoItem3 = new TodoItem("Empty trash"); repository.Add(todoItem); repository.Add(todoItem2); Assert.IsTrue(repository.Get(todoItem.Id) == todoItem && repository.Get(todoItem2.Id) == todoItem2 && repository.Get(todoItem3.Id) == default(TodoItem)); }
public void TestGetComplited() { IGenericList <TodoItem> g = new GenericList <TodoItem>(); ITodoRepository testt = new TodoRepository(); TodoItem ana = new TodoItem("Ana"); TodoItem luka = new TodoItem("Luka"); ana.MarkAsCompleted(); testt.Add(ana); testt.Add(luka); List <TodoItem> list = testt.GetCompleted(); Assert.AreEqual(true, list.Contains(ana)); Assert.AreEqual(false, list.Contains(luka)); }
public void Configure(IApplicationBuilder app, IAntiforgery antiforgery, IOptions<AntiforgeryOptions> options, TodoRepository repository) { app.Use(next => context => { if ( string.Equals(context.Request.Path.Value, "/", StringComparison.OrdinalIgnoreCase) || string.Equals(context.Request.Path.Value, "/index.html", StringComparison.OrdinalIgnoreCase)) { // We can send the request token as a JavaScript-readable cookie, and Angular will use it by default. var tokens = antiforgery.GetAndStoreTokens(context); context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, new CookieOptions() { HttpOnly = false }); } return next(context); }); app.UseDefaultFiles(); app.UseStaticFiles(); app.Map("/api/items", a => a.Run(async context => { if (string.Equals("GET", context.Request.Method, StringComparison.OrdinalIgnoreCase)) { var items = repository.GetItems(); await context.Response.WriteAsync(JsonConvert.SerializeObject(items)); } else if (string.Equals("POST", context.Request.Method, StringComparison.OrdinalIgnoreCase)) { // This will throw if the token is invalid. await antiforgery.ValidateRequestAsync(context); var serializer = new JsonSerializer(); using (var reader = new JsonTextReader(new StreamReader(context.Request.Body))) { var item = serializer.Deserialize<TodoItem>(reader); repository.Add(item); } context.Response.StatusCode = 204; } })); }