示例#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);
        }
        public void GetListOfFilesAndProcessTest(string ip, int numRecords)
        {
            var filesystem = new Mock <IFileSystemHelper>();

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

            var httpTest = new HttpTest();

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

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

            var copyStats = new BlackVueDownloaderCopyStats();

            // Success test
            for (var i = 0; i < numRecords * 4; i++)
            {
                httpTest.RespondWith(200, "OK");
            }
            copyStats.Clear();
            blackVueDownloader.ProcessList(ip, list, ref copyStats);
            Assert.Equal(numRecords * 4, copyStats.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
            copyStats.Clear();
            blackVueDownloaderNoMock.ProcessList(ip, list, ref copyStats);
            Assert.Equal(numRecords * 4, copyStats.Ignored);

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

            // Timeout Fail test
            for (var i = 0; i < numRecords * 4; i++)
            {
                httpTest.SimulateTimeout();
            }
            copyStats.Clear();
            blackVueDownloader.ProcessList(ip, list, ref copyStats);
            Assert.Equal(numRecords * 4, copyStats.Errored);
        }