Beispiel #1
0
        public void All_ShouldReturnAllObjects()
        {
            //arrange
            var dbContext = new TodoTasksDbContext();
            var repo      = new TodoTasks.Data.TodoTasksData();

            //act
            var actual   = repo.Categories.All().Select(c => c.Name).ToList();
            var expected = dbContext.Categories.Select(c => c.Name).ToList();

            //assert
            CollectionAssert.AreEquivalent(expected, actual);
        }
Beispiel #2
0
        public void Delete_WhenObjectDeleted_ShouldNotReturnObject()
        {
            //arrange
            var dbContext = new TodoTasksDbContext();
            var repo      = new TodoTasks.Data.TodoTasksData();

            Category category = dbContext.Categories.FirstOrDefault();

            dbContext.Categories.Remove(category);
            dbContext.SaveChanges();
            repo.Categories.Delete(category);

            //act
            var actual   = repo.Categories.All().FirstOrDefault(c => c.Id == category.Id);
            var expected = dbContext.Categories.FirstOrDefault(c => c.Id == category.Id);

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void Delete_WhenObjectDeleted_ShouldNotReturnObject()
        {
            //arrange
            var dbContext = new TodoTasksDbContext();
            var repo      = new TodoTasks.Data.TodoTasksData();

            TodoTask task = dbContext.Tasks.FirstOrDefault();

            dbContext.Tasks.Remove(task);
            dbContext.SaveChanges();
            repo.Tasks.Delete(task);

            //act
            var actual   = repo.Tasks.All().FirstOrDefault(t => t.Id == task.Id);
            var expected = dbContext.Tasks.FirstOrDefault(t => t.Id == task.Id);

            //assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        public void Add_WhenObjectAdded_ShouldReturnAddedobjects()
        {
            //arrange
            var dbContext = new TodoTasksDbContext();
            var repo      = new TodoTasks.Data.TodoTasksData();

            Category category = this.GetValidTestCategory();

            dbContext.Categories.Add(category);
            dbContext.SaveChanges();
            repo.Categories.Add(category);

            //act
            var actual   = repo.Categories.All().FirstOrDefault(c => c.Id == category.Id);
            var expected = dbContext.Categories.FirstOrDefault(c => c.Id == category.Id);

            //assert
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Name, actual.Name);
        }
        public void Add_WhenObjectAdded_ShouldReturnAddedobjects()
        {
            //arrange
            var dbContext = new TodoTasksDbContext();
            var repo      = new TodoTasks.Data.TodoTasksData();

            TodoTask task = this.GetValidTestTask();

            dbContext.Tasks.Add(task);
            dbContext.SaveChanges();
            repo.Tasks.Add(task);

            //act
            var actual   = repo.Tasks.All().FirstOrDefault(t => t.Id == task.Id);
            var expected = dbContext.Tasks.FirstOrDefault(t => t.Id == task.Id);

            //assert
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Content, actual.Content);
            Assert.AreEqual(expected.CreationDate.ToShortDateString(), actual.CreationDate.ToShortDateString());
        }