Пример #1
0
        public void AddThreeBugsToRepoAndCheckWhetherAllReturnsTheCorrectBugs()
        {
            //arrange
            var context = new BugLoggerDbContext();
            var repo    = new BugsRepository(context);

            var countInDbBeforeAddingThreeBugs = context.Bugs.Count();

            var bug1 = new Bug
            {
                Content = "test bug 1"
            };

            var bug2 = new Bug
            {
                Content = "test bug 2"
            };

            var bug3 = new Bug
            {
                Content = "test bug 3"
            };

            //act
            context.Bugs.Add(bug1);
            context.Bugs.Add(bug2);
            context.Bugs.Add(bug3);
            context.SaveChanges();

            //assert
            var countInDbAfterAddingThreeBugs = repo.All().ToList().Count;

            Assert.AreEqual(3, countInDbAfterAddingThreeBugs - countInDbBeforeAddingThreeBugs);
        }
        public void AddBug_WhenBugIsNotValid_ShouldThrowException()
        {
            var bug = GetInvalidTestBug();

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

            repo.Add(bug);
            repo.Save();
        }
        public void DeleteBug_WhenNotInDb_ShouldThrowExcetion()
        {
            var bug = GetValidTestBug();

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

            repo.Delete(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);
        }
Пример #5
0
        protected override void Seed(BugLoggerDbContext context)
        {
            if (context.Bugs.Any())
            {
                return;
            }

            context.Bugs.Add(new Bug
            {
                Status  = DataLayer.Status.Pending,
                LogDate = DateTime.Now,
                Text    = "Some bug 1"
            });

            context.Bugs.Add(new Bug
            {
                Status  = DataLayer.Status.Assigned,
                LogDate = DateTime.Now.AddDays(2),
                Text    = "Some bug 2"
            });

            context.Bugs.Add(new Bug
            {
                Status  = DataLayer.Status.Fixed,
                LogDate = DateTime.Now.AddDays(-5),
                Text    = "Some bug 3"
            });

            context.Bugs.Add(new Bug
            {
                Status  = DataLayer.Status.ForTesting,
                LogDate = DateTime.Now.AddDays(-1),
                Text    = "Some bug 4"
            });

            context.Bugs.Add(new Bug
            {
                Status  = DataLayer.Status.Pending,
                LogDate = DateTime.Now.AddDays(-1),
                Text    = "Some bug 5"
            });

            context.Bugs.Add(new Bug
            {
                Status  = DataLayer.Status.Fixed,
                LogDate = DateTime.Now.AddDays(-2),
                Text    = "Some bug 6"
            });
        }
        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);
        }
Пример #8
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);
        }
Пример #9
0
        public void AddBugToRepoAndTestWhetherFindReturnsTheCorrectBug()
        {
            //arrange
            var context = new BugLoggerDbContext();
            var repo    = new BugsRepository(context);

            var bug = new Bug
            {
                Content = "Please fix my blog"
            };

            //act
            context.Bugs.Add(bug);
            context.SaveChanges();

            //assert
            var bugFromDb = repo.Find(bug.BugId);

            Assert.AreEqual(bug.Content, bugFromDb.Content);
        }
Пример #10
0
        public void AddBugToRepoAndCheckWhetherTheStatusIsPending()
        {
            //arrange
            var context = new BugLoggerDbContext();
            var repo    = new BugsRepository(context);

            var bug = new Bug
            {
                Content = "Status should be pending"
            };

            //act
            repo.Add(bug);
            context.SaveChanges();

            //assert
            var bugFromDb = context.Bugs.Find(bug.BugId);

            Assert.AreEqual(BugStatus.Pending, bugFromDb.Status);
        }
        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);
        }
Пример #12
0
        public void AddBugToRepoWithNoDataShouldNotHaveADate()
        {
            //arrange
            var context = new BugLoggerDbContext();
            var repo    = new BugsRepository(context);

            var bug = new Bug
            {
                Content = "Status should be pending"
            };

            //act
            repo.Add(bug);
            context.SaveChanges();

            //assert
            var bugFromDb = context.Bugs.Find(bug.BugId);

            Assert.AreSame(null, bugFromDb.LogDate);
            Assert.AreEqual(bug.LogDate, bugFromDb.LogDate);
        }
Пример #13
0
        public void AddBugToRepoAndTestWhetherDeleteByEntityDeletesTheBug()
        {
            //arrange
            var context = new BugLoggerDbContext();
            var repo    = new BugsRepository(context);

            var bug = new Bug
            {
                Content = "Please fix my blog"
            };

            //act
            context.Bugs.Add(bug);
            context.SaveChanges();

            //assert
            repo.Delete(bug);
            context.SaveChanges();

            var bugInDb = context.Bugs.Find(bug.BugId);

            Assert.AreEqual(null, bugInDb);
        }
Пример #14
0
        public void AddBugAndUpdateItThenCheckWhetherTheUpdatesAreReflected()
        {
            //arrange
            var context = new BugLoggerDbContext();
            var repo    = new BugsRepository(context);

            var bug = new Bug
            {
                Content = "New bug"
            };

            //act
            repo.Add(bug);
            repo.SaveChanges();

            bug.Status = BugStatus.Assigned;
            repo.SaveChanges();

            //assert
            var bugFromDb = repo.Find(bug.BugId);

            Assert.AreEqual(BugStatus.Assigned, bugFromDb.Status);
        }
Пример #15
0
 public DbBugsRepository(BugLoggerDbContext context)
 {
     this.dbContext = context;
     this.set       = context.Set <Bug>();
 }