public void DeleteBug_WhenNotInDb_ShouldThrowExcetion()
        {
            var bug = GetValidTestBug();

            var dbContext = new BugLoggerDbContext();
            var repo      = new DbBugsRepository(dbContext);

            repo.Delete(bug);
            repo.Save();
        }
        public void AddBug_WhenBugIsNotValid_ShouldThrowException()
        {
            var bug = GetInvalidTestBug();

            var dbContext = new BugLoggerDbContext();
            var repo      = new DbBugsRepository(dbContext);

            repo.Add(bug);
            repo.Save();
        }
        public void Find_WhenObjectIsInDb_ShouldReturnObject()
        {
            var bug       = this.GetValidTestBug();
            var dbContext = new BugLoggerDbContext();
            var repo      = new DbBugsRepository(dbContext);

            dbContext.Bugs.Add(bug);
            dbContext.SaveChanges();

            var bugInDb = repo.Find(bug.Id);

            Assert.IsNotNull(bugInDb);
            Assert.AreEqual(bug.Text, bugInDb.Text);
        }
        public void AddBug_WhenBugIsValid_ShouldAddToDb()
        {
            var bug = GetValidTestBug();

            var dbContext = new BugLoggerDbContext();
            var repo      = new DbBugsRepository(dbContext);

            repo.Add(bug);
            repo.Save();

            var bugInDb = dbContext.Bugs.Find(bug.Id);

            Assert.IsNotNull(bugInDb);
            Assert.AreEqual(bug.Text, bugInDb.Text);
        }
        public void Find_WhenObjectIsNotInDb_ShouldReturnNull()
        {
            var dbContext = new BugLoggerDbContext();
            var repo      = new DbBugsRepository(dbContext);

            var bug = dbContext.Bugs.FirstOrDefault();
            int id  = bug != null ? bug.Id : 1;

            if (bug != null)
            {
                var bugEntry = dbContext.Entry(bug);
                bugEntry.State = EntityState.Deleted;
                dbContext.SaveChanges();
            }

            var bugInDb = repo.Find(id);

            Assert.IsNull(bugInDb);
        }
Exemple #6
0
        public void AddBug_WhenBugIsValid_ShouldAddToDb()
        {
            //// arrange -> prapare the objects
            var bug = this.GetValidTestBug();

            var dbContext = new BugLoggerDbContext();
            var repo      = new DbBugsRepository(dbContext);

            //// act -> test the objects

            repo.Add(bug);
            repo.Save();

            //// assert -> validate the result
            var bugInDb = dbContext.Bugs.Find(bug.Id);

            Assert.IsNotNull(bugInDb);
            Assert.AreEqual(bug.Text, bugInDb.Text);
        }
        public void DeleteBug_WhenInDb_ShouldRemoveBug()
        {
            var bug = GetValidTestBug();

            var dbContext = new BugLoggerDbContext();
            var repo      = new DbBugsRepository(dbContext);

            repo.Add(bug);
            repo.Save();

            var bugInDb = dbContext.Bugs.Find(bug.Id);

            Assert.IsNotNull(bugInDb);
            Assert.AreEqual(bug.Text, bugInDb.Text);

            repo.Delete(bug);
            repo.Save();

            bugInDb = dbContext.Bugs.Find(bug.Id);
            Assert.IsNull(bugInDb);
        }