コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }