public void Test_將檔案轉成byte陣列_檔案不存在應丟exception()
        {
            // arrange
            Candidate candidateStub = CandidateFactory.Create(null, new DateTime(), null, null, 0);

            byte[] targetStub = null;

            // act
            // assert
            Assert.Throws <ArgumentNullException>(() => fileHandler.Perform(candidateStub, targetStub));
        }
Example #2
0
        /// <summary>
        /// 覆寫建立待處理檔案資訊
        /// </summary>
        /// <param name="fileName">檔案名稱</param>
        /// <returns>待處理檔案資訊</returns>
        protected override Candidate CreateCandidate(string fileName)
        {
            FileInfo  fileInfo;
            Candidate candidate = null;

            if (File.Exists(fileName))
            {
                fileInfo  = new FileInfo(fileName);
                candidate = CandidateFactory.Create(this.config, fileName, fileInfo.CreationTime, fileInfo.Length);
            }

            return(candidate);
        }
Example #3
0
        public void Test_傳入null有預設屬性()
        {
            // act
            Candidate candidate = CandidateFactory.Create(null, new DateTime(), null, null, 0);

            // assert
            // Candidate 有屬性
            Assert.Null(candidate.Config);
            Assert.IsType <DateTime>(candidate.FileDateTime);
            Assert.Null(candidate.Name);
            Assert.Null(candidate.ProcessName);
            Assert.Equal(0, candidate.Size);
        }
        /// <summary>
        /// 產生假 Candidate 物件
        /// </summary>
        /// <returns>Candidate 物件</returns>
        private Candidate CreateFakeCandidate()
        {
            JObject inputStub = JObject.Parse(@"{'configs':[{'connectionString':'','destination':'directory','dir':'D:\\Projects\\oop-homework\\storage\\app\\backup','ext':'txt','handlers':['zip', 'encode'],'location':'D:\\Projects\\oop-homework\\storage\\app','remove':false,'subDirectory':true,'unit':'file'}]}");

            Config    configStub    = new Config(inputStub["configs"][0]);
            Candidate candidateStub = CandidateFactory.Create(
                configStub,
                Convert.ToDateTime("2017-11-12 12:34:56"),
                "D:\\Projects\\oop-homework\\storage\\app\\test.txt",
                "xxx",
                123
                );

            return(candidateStub);
        }
Example #5
0
        public void Test_json檔config有設定有欄位_預設屬性正常()
        {
            // arrange
            JObject inputStub = JObject.Parse(@"{'configs':[{'connectionString':'xxx','destination':'directory','dir':'c:\\aaa','ext':'cs','handlers':['zip'],'location':'c:\\bbb','remove':false,'subDirectory':true,'unit':'file'}]}");

            // act
            Config    configStub = new Config(inputStub["configs"][0]);
            Candidate candidate  = CandidateFactory.Create(configStub, Convert.ToDateTime("2017-11-12 12:34:56"), "c:\\test.txt", "xxx", 123);

            // assert
            // Candidate 的屬性 config 型別應為 Config
            Assert.IsType <Config>(candidate.Config);
            // Candidate 屬性值是否正確
            Assert.IsType <DateTime>(candidate.FileDateTime);
            Assert.Equal("c:\\test.txt", candidate.Name);
            Assert.Equal("xxx", candidate.ProcessName);
            Assert.Equal(123, candidate.Size);
        }
Example #6
0
        /// <summary>
        /// 設定備份檔案
        /// </summary>
        /// <param name="fileName">檔案位置</param>
        /// <returns>檔案資訊</returns>
        protected override Candidate CreateCandidate(string fileName)
        {
            FileInfo info = new FileInfo(fileName);

            return(CandidateFactory.Create(this.config, info.CreationTime, fileName, info.Name, info.Length));
        }