示例#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);
        }
示例#2
0
        public void GetListOfFilesFromResponseTest(string body, string firstval, int numelements)
        {
            var blackVueDownloader = new PCL.BlackVueDownloader();

            var list = blackVueDownloader.GetListOfFilesFromResponse(body);

            Assert.Equal(numelements, list.Count);
            Assert.Equal(firstval, list[0]);
        }
示例#3
0
        public void VerifyListIsParsedCorrectly(string body, string firstval, int numelements, BlackVueFile.Direction direction, BlackVueFile.VideoType videoType)
        {
            var blackVueDownloader = new PCL.BlackVueDownloader();
            var list = blackVueDownloader.GetListOfFilesFromResponse(body);

            Assert.Equal(numelements, list.Count);
            Assert.Equal(firstval, list[0].originalName);
            Assert.Equal(direction, list[0].direction);
            Assert.Equal(videoType, list[0].videoType);
        }
        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);
        }
        public void DownloadFileIgnoreTest(string ip)
        {
            var filesystem = new Mock <IFileSystemHelper>();

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

            var copyStats = new BlackVueDownloaderCopyStats();

            filesystem.Setup(x => x.Exists("Record/ignorefile.mp4")).Returns(true);
            blackVueDownloader.DownloadFile(ip, "ignorefile.mp4", "video", ref copyStats);

            Assert.Equal(1, copyStats.Ignored);
        }
示例#6
0
        public void EmptyResponseTest(string ip)
        {
            var blackVueDownloader = new PCL.BlackVueDownloader();

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith("");

                var body = blackVueDownloader.QueryCameraForFileList(ip);

                httpTest.ShouldHaveCalled($"http://{ip}/blackvue_vod.cgi");

                Assert.True(string.IsNullOrEmpty(body));
            }
        }
        public void QueryCameraForFileListTest(string ip)
        {
            var blackVueDownloader = new PCL.BlackVueDownloader(new FileSystemHelper());

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(200, "this is the body");

                var body = blackVueDownloader.QueryCameraForFileList(ip);

                httpTest.ShouldHaveCalled($"http://{ip}/blackvue_vod");

                Assert.True(!string.IsNullOrEmpty(body));
            }
        }
示例#8
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);
        }
示例#9
0
        public void CameraRespondValidTest(string ip, int numRecords)
        {
            var blackVueDownloader = new PCL.BlackVueDownloader();

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(GenerateRecords(numRecords));

                var body = blackVueDownloader.QueryCameraForFileList(ip);

                httpTest.ShouldHaveCalled($"http://{ip}/blackvue_vod.cgi");

                Assert.True(!string.IsNullOrEmpty(body));

                if (body != null)
                {
                    Assert.Equal(numRecords * 2, body.ParseBody().Length);
                }
            }
        }
示例#10
0
        public void CantFindCameraTest(string ip)
        {
            var blackVueDownloader = new PCL.BlackVueDownloader();

            using (var httpTest = new HttpTest())
            {
                httpTest.SimulateTimeout();

                try
                {
                    blackVueDownloader.QueryCameraForFileList(ip);
                }
                catch (Exception e)
                {
                    Assert.StartsWith("One or more errors occurred.", e.Message);
                }

                httpTest.ShouldHaveCalled($"http://{ip}/blackvue_vod.cgi");
            }
        }
        public void InvalidResponseTest(string ip)
        {
            var blackVueDownloader = new PCL.BlackVueDownloader(new FileSystemHelper());

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(500, "Simulated Error");

                try
                {
                    blackVueDownloader.QueryCameraForFileList(ip);
                }
                catch (Exception e)
                {
                    Assert.Equal("One or more errors occurred.", e.Message);
                }

                httpTest.ShouldHaveCalled($"http://{ip}/blackvue_vod");
            }
        }