public void AddBugWithoutBothDescriptionAndLogDateShouldThrowsValidationException() { // Arrange -> Prepare the objects var bug = new Bug(); // Act -> Test the objects var bugRepository = new BugRepository(new BugLoggerDbContext()); bugRepository.Add(bug); bugRepository.SaveChanges(); // Assert -> Validate the result var bugFromDb = bugRepository.Find(bug.BugId); Assert.IsNotNull(bugFromDb); Assert.AreEqual(bug.Description, bugFromDb.Description); }
public void GetAllBugsShouldReturnBugsCollection() { // Arrange -> Prepare the objects var bugs = this.GenerateBugsCollection(); // Act -> Test the objects var bugRepository = new BugRepository(new BugLoggerDbContext()); var bugsInDatabaseCountOld = bugRepository.All().Count(); foreach (var bug in bugs) { bugRepository.Add(bug); } bugRepository.SaveChanges(); // Assert -> Validate the result Assert.AreEqual(bugsInDatabaseCountOld + bugs.Count, bugRepository.All().Count()); CollectionAssert.AreEquivalent(bugs.ToList(), bugRepository.All().OrderBy(b => b.BugId).Skip(bugsInDatabaseCountOld).Take(bugs.Count).ToList()); }
public void AddBugShouldBeAddedToDatabaseAndShouldBeReturnedFromRepository() { // Arrange -> Prepare the objects var bug = new Bug() { Description = "bug-1", LogDate = DateTime.Now }; // Act -> Test the objects var bugRepository = new BugRepository(new BugLoggerDbContext()); bugRepository.Add(bug); bugRepository.SaveChanges(); // Assert -> Validate the result var bugFromDb = bugRepository.Find(bug.BugId); Assert.IsNotNull(bugFromDb); Assert.AreEqual(bug.Description, bugFromDb.Description); }
public void AddBugWithNullDescriptionShouldThrowsValidationException() { // Arrange -> Prepare the objects var bug = new Bug() { Description = null, LogDate = DateTime.Now }; // Act -> Test the objects var bugRepository = new BugRepository(new BugLoggerDbContext()); bugRepository.Add(bug); bugRepository.SaveChanges(); // Assert -> Validate the result var bugFromDb = bugRepository.Find(bug.BugId); Assert.IsNotNull(bugFromDb); Assert.AreEqual(bug.Description, bugFromDb.Description); }