Esempio n. 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);
        }
        private TodoTask GetValidTestTask()
        {
            var dbContext = new TodoTasksDbContext();
            var ran       = new Random();

            var task = new TodoTask()
            {
                Content      = "Test task " + ran.Next(0, 100),
                CreationDate = DateTime.Now,
                Status       = StatusType.Incompleted,
                CategoryId   = dbContext.Categories.First().Id
            };

            return(task);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 6
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());
        }