Exemplo n.º 1
0
        public void Find_WhenObjectIsInDb_ShouldReturnObject()
        {
            //arrange
            var category = this.GetValidTestCategory();

            var dbContext = new TodoTasksDbContext();
            var repo      = new TodoTasksData();

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

            //act
            var categoryInDb = repo.Categories.Find(category.Id);

            //asesrt

            Assert.IsNotNull(categoryInDb);
            Assert.AreEqual(category.Name, categoryInDb.Name);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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 Find_WhenObjectIsInDb_ShouldReturnObject()
        {
            //arrange
            var task = this.GetValidTestTask();

            var dbContext = new TodoTasksDbContext();
            var repo      = new TodoTasksData();

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

            //act
            var taskInDb = repo.Tasks.Find(task.Id);

            //assert

            Assert.IsNotNull(taskInDb);
            Assert.AreEqual(task.Content, taskInDb.Content);
            Assert.AreEqual(task.CreationDate.ToShortDateString(), taskInDb.CreationDate.ToShortDateString());
        }
        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());
        }