Exemplo n.º 1
0
        public void GetListOfFilesAndProcessTest(string ip, int numRecords)
        {
            var targetdir = Path.Combine(Directory.GetCurrentDirectory(), "Record");

            var filesystem = new Mock <IFileSystemHelper>();

            var blackVueDownloader       = new PCL.BlackVueDownloader(filesystem.Object);
            var blackVueDownloaderNoMock = new PCL.BlackVueDownloader();

            blackVueDownloaderNoMock.CreateDirectories(targetdir, targetdir);

            var httpTest = new HttpTest();

            var list = blackVueDownloader.GetListOfFilesFromResponse(GenerateRecords(numRecords));

            Assert.Equal(numRecords * 2, list.Count);

            BlackvueOptions options = new BlackvueOptions
            {
                Timeout   = 0,
                IPAddress = ip
            };

            // Success test
            for (var i = 0; i < numRecords * 4; i++)
            {
                httpTest.RespondWith("OK");
            }
            blackVueDownloader.BlackVueDownloaderCopyStats.Clear();
            blackVueDownloader.ProcessList(list, targetdir, targetdir, options);
            Assert.Equal(numRecords * 4, blackVueDownloader.BlackVueDownloaderCopyStats.Copied);

            // Ignored from above test
            // What happens with the above tests, is that it writes actual files to
            // BlackVueDownloader.Tests\bin\Debug\Record directory,
            // so there should be numrecords * 4 files there
            // And if we loop through again, they should all exist, and therefore be "ignored"
            // We need to do this with an unmocked version of the file system helper
            blackVueDownloaderNoMock.BlackVueDownloaderCopyStats.Clear();
            blackVueDownloader.ProcessList(list, targetdir, targetdir, options);
            Assert.Equal(numRecords * 4, blackVueDownloaderNoMock.BlackVueDownloaderCopyStats.Ignored);

            // Fail test
            for (var i = 0; i < numRecords * 4; i++)
            {
                httpTest.RespondWith("FAILURE", 500);
            }
            blackVueDownloader.BlackVueDownloaderCopyStats.Clear();
            blackVueDownloader.ProcessList(list, targetdir, targetdir, options);
            Assert.Equal(numRecords * 4, blackVueDownloader.BlackVueDownloaderCopyStats.Errored);

            // Timeout Fail test
            for (var i = 0; i < numRecords * 4; i++)
            {
                httpTest.SimulateTimeout();
            }
            blackVueDownloader.BlackVueDownloaderCopyStats.Clear();
            blackVueDownloader.ProcessList(list, targetdir, targetdir, options);
            Assert.Equal(numRecords * 4, blackVueDownloader.BlackVueDownloaderCopyStats.Errored);
        }
Exemplo n.º 2
0
        public void DownloadFileIgnoreTest(string ip)
        {
            var targetdir = Path.Combine(Directory.GetCurrentDirectory(), "Record");

            var filesystem = new Mock <IFileSystemHelper>();

            var blackVueDownloader       = new PCL.BlackVueDownloader(filesystem.Object);
            var blackVueDownloaderNoMock = new PCL.BlackVueDownloader();

            blackVueDownloaderNoMock.CreateDirectories(targetdir, targetdir);

            filesystem.Setup(x => x.Exists(Path.Combine(targetdir, "ignorefile.mp4"))).Returns(true);
            blackVueDownloader.DownloadFile(ip, "ignorefile.mp4", "video", targetdir, targetdir);

            Assert.Equal(1, blackVueDownloader.BlackVueDownloaderCopyStats.Ignored);
        }