Exemple #1
0
        public void Test_傳入candidate及target_應寫入資料庫MyBackup及MyLog()
        {
            // arrange
            // 產生假 Candidate 物件
            Candidate candidateStub = CreateFakeCandidate();

            byte[] targetStub = new byte[1];

            // act
            byte[] actual = adapter.Perform(candidateStub, targetStub);

            // assert
            using (MyDbContext db = new MyDbContext())
            {
                string testName = "D:\\Projects\\oop-homework\\storage\\app\\DBAdapterTest.txt";

                // 撈 MyBackup 應該有 1 筆符合的資料
                int myBackupNum = db.MyBackup.Where(b => b.Name == testName).Count();
                Assert.Equal(1, myBackupNum);

                // 刪除 MyBackup 測試資料
                var del = db.MyBackup.Where(b => b.Name == testName);
                db.MyBackup.RemoveRange(del);
                db.SaveChanges();

                // 撈 MyBackup 應該有 0 筆符合的資料
                int myBackupNum2 = db.MyBackup.Where(b => b.Name == testName).Count();
                Assert.Equal(0, myBackupNum2);

                // 撈 MyLog 應該有 1 筆符合的資料
                int myLogNum = db.MyLog.Where(b => b.Name == testName).Count();
                Assert.Equal(1, myLogNum);

                // 刪除 MyLog 測試資料
                var del2 = db.MyLog.Where(b => b.Name == testName);
                db.MyLog.RemoveRange(del2);
                db.SaveChanges();

                // 撈 MyLog 應該有 0 筆符合的資料
                int myLogNum2 = db.MyLog.Where(b => b.Name == testName).Count();
                Assert.Equal(0, myLogNum2);
            }
        }