Esempio n. 1
0
        public void TestVlcJobGetsAddedToCollection()
        {
            var file = TestUtilities.GetTestFile("NeedinYou2SecWav.wav");
            var audioConfiguration = new AudioConfiguration
            {
                Format = AudioConfiguration.ConversionFormats.Mp3
            };

            var portAllocator = MockRepository.GenerateMock <IPortAllocator>();

            portAllocator.Expect(x => x.NewPort()).Return(42);

            var job = new VlcAudioJob(audioConfiguration, portAllocator, MockRepository.GenerateMock <IStatusParser>(), MockRepository.GenerateMock <IVlcStatusSource>(), new TimeSouce(), MockRepository.GenerateMock <ILogger>());

            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            job.InputFile = file;
            var expectedOutputFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output.mp3");

            job.OutputFile = new FileInfo(expectedOutputFile);

            var starter  = MockRepository.GenerateMock <IVlcStarter>();
            var instance = MockRepository.GenerateMock <IVlcInstance>();

            starter.Expect(x => x.Start(Arg <string> .Is.Anything, Arg <FileInfo> .Is.Anything)).Return(instance);
            var driver = new VlcDriver(starter);

            TestUtilities.SetVlcExeLocationOnNonStandardWindowsEnvironments(driver);
            Assert.AreEqual(0, driver.JobBag.Count);
            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            driver.StartJob(job);
            Assert.AreEqual(1, driver.JobBag.Count);
            Assert.AreEqual(VlcJob.JobState.Started, job.State);
            instance.Raise(x => x.OnExited += null, instance, new EventArgs());
            Assert.AreEqual(1, driver.JobBag.Count);
        }
Esempio n. 2
0
        public void EnsureExceptionHappensWhenTryingToConvertIfInputFileIsMissing()
        {
            var audioConfig = MockRepository.GenerateMock <IAudioConfiguration>();

            var portAllocator = MockRepository.GenerateMock <IPortAllocator>();

            portAllocator.Expect(x => x.NewPort()).Return(89);

            var statusSource = MockRepository.GenerateStub <IVlcStatusSource>();

            statusSource.Expect(x => x.GetXml()).Return("Foo");

            var statusParser = MockRepository.GenerateMock <IStatusParser>();

            statusParser.Expect(x => x.Position).Return(67);

            var job = new VlcAudioJob(audioConfig, portAllocator, statusParser, statusSource, new TimeSouce(), MockRepository.GenerateMock <ILogger>())
            {
                State      = VlcJob.JobState.Started,
                InputFile  = new FileInfo(@"C:\Foo.txt"),
                OutputFile = new FileInfo(@"C:\Foo2.txt")
            };

            job.GetVlcArguments();
        }
Esempio n. 3
0
        public void EnsureQuitAfterIsPassedToArguments()
        {
            var audioConfig = MockRepository.GenerateMock <IAudioConfiguration>();

            audioConfig.Expect(x => x.GetPartArguments()).Return("!!FOO!!");

            var portAllocator = MockRepository.GenerateMock <IPortAllocator>();

            portAllocator.Expect(x => x.NewPort()).Return(42);

            var job = new VlcAudioJob(audioConfig, portAllocator, MockRepository.GenerateMock <IStatusParser>(), MockRepository.GenerateMock <IVlcStatusSource>(), new TimeSouce(), MockRepository.GenerateMock <ILogger>())
            {
                QuitAfer = true
            };
            var inputfile = TestUtilities.GetTestFile("NeedinYou2SecWav.wav");

            job.InputFile = inputfile;
            var expectedOutputFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output.mp3");

            job.OutputFile = new FileInfo(expectedOutputFile);

            var expectedArguments = string.Format("-I http --http-password goose --http-port 42 \"{0}{2}NeedinYou2SecWav.wav\" \":sout=#transcode{{vcodec=none,!!FOO!!}}:std{{dst='{1}{2}output.mp3',access=file}}\" vlc://quit", TestUtilities.GetTestDir(), TestUtilities.GetTestOutputDir(), Path.DirectorySeparatorChar);
            var actualArguments   = job.GetVlcArguments();

            Assert.AreEqual(expectedArguments, actualArguments);
        }
Esempio n. 4
0
        public void EnsureTheLiveStatusIsNotUpdatedWhenStateIsNotStarted(VlcJob.JobState state)
        {
            var audioConfig = MockRepository.GenerateMock <IAudioConfiguration>();

            var portAllocator = MockRepository.GenerateMock <IPortAllocator>();

            portAllocator.Expect(x => x.NewPort()).Return(89);

            var statusSource = MockRepository.GenerateStub <IVlcStatusSource>();

            statusSource.Expect(x => x.GetXml()).Return("Foo");

            var statusParser = MockRepository.GenerateMock <IStatusParser>();

            statusParser.Expect(x => x.Position).Return(67);

            var job = new VlcAudioJob(audioConfig, portAllocator, statusParser, statusSource, new TimeSouce(), MockRepository.GenerateMock <ILogger>())
            {
                State = state,
            };

            job.UpdateProgress();
            statusSource.AssertWasNotCalled(x => x.GetXml());
            statusParser.AssertWasNotCalled(x => x.Parse());
        }
Esempio n. 5
0
        public void EnsurePortAllocatorIsCalledAndReleased()
        {
            //TODO. Ensure Port is always delallocated even in error
            var audioConfig = MockRepository.GenerateMock <IAudioConfiguration>();

            audioConfig.Expect(x => x.GetPartArguments()).Return("!!FOO!!");

            var portAllocator = MockRepository.GenerateMock <IPortAllocator>();

            portAllocator.Expect(x => x.NewPort()).Return(49);

            var job       = new VlcAudioJob(audioConfig, portAllocator, MockRepository.GenerateMock <IStatusParser>(), MockRepository.GenerateMock <IVlcStatusSource>(), new TimeSouce(), MockRepository.GenerateMock <ILogger>());
            var inputfile = TestUtilities.GetTestFile("NeedinYou2SecWav.wav");

            job.InputFile = inputfile;
            var expectedOutputFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output.mp3");

            job.OutputFile = new FileInfo(expectedOutputFile);

            portAllocator.AssertWasNotCalled(x => x.NewPort());
            job.GetVlcArguments();
            portAllocator.AssertWasCalled(x => x.NewPort());
            portAllocator.AssertWasNotCalled(x => x.ReleasePort(Arg <int> .Is.Anything));
            job.SetJobComplete();
            portAllocator.AssertWasCalled(x => x.ReleasePort(49));
        }
Esempio n. 6
0
        public void EnsureExpectedCompletionTimeIsEstimatedCorectly()
        {
            var audioConfig = MockRepository.GenerateMock <IAudioConfiguration>();

            var portAllocator = MockRepository.GenerateMock <IPortAllocator>();

            var statusSource = MockRepository.GenerateMock <IVlcStatusSource>();

            var statusParser = MockRepository.GenerateMock <IStatusParser>();

            statusParser.Expect(x => x.Position).Return(0).Repeat.Once();

            var timeSouce = MockRepository.GenerateMock <ITimeSouce>();
            var testTime  = new DateTime(1988, 3, 26, 18, 0, 0).ToUniversalTime();

            timeSouce.Expect(x => x.getDateTime).Return(testTime.AddSeconds(1)).Repeat.Once();

            var instance = MockRepository.GenerateMock <IVlcInstance>();

            instance.Expect(x => x.StartTime).Return(testTime);

            var testFile = TestUtilities.GetTestFile("NeedinYou2SecWavMp3128.mp3");

            var job = new VlcAudioJob(audioConfig, portAllocator, statusParser, statusSource, timeSouce, MockRepository.GenerateMock <ILogger>())
            {
                State      = VlcJob.JobState.Started,
                InputFile  = testFile,
                OutputFile = new FileInfo(@"C:\Foo2.txt"),
                Instance   = instance
            };

            job.GetVlcArguments();
            //To begin with ensure the estimated completion time is 0
            Assert.AreEqual(new TimeSpan(0, 0, 0), job.EstimatedTimeToCompletion);

            //Ensure the updating the progress calculates 0 as no progress has been made
            job.UpdateProgress();
            Assert.AreEqual(new TimeSpan(0, 0, 0), job.EstimatedTimeToCompletion);

            // If 30 seconds have elapsed and the job is 25% complete, the estimated finish time should be 1m 30s
            statusParser.Expect(x => x.Position).Return(0.25).Repeat.Once();
            timeSouce.Expect(x => x.getDateTime).Return(testTime.AddSeconds(30)).Repeat.Once();
            job.UpdateProgress();
            Assert.AreEqual(new TimeSpan(0, 1, 30), job.EstimatedTimeToCompletion);

            //If 1 minute has elapsed and the job is 50% complete, the estimated time should be 1 minute
            statusParser.Expect(x => x.Position).Return(0.5).Repeat.Once();
            timeSouce.Expect(x => x.getDateTime).Return(testTime.AddSeconds(60)).Repeat.Once();
            job.UpdateProgress();
            Assert.AreEqual(new TimeSpan(0, 1, 0), job.EstimatedTimeToCompletion);

            //If 2 minutes have elapsed and the job is 100% complete, the estimated time left is 0
            statusParser.Expect(x => x.Position).Return(1).Repeat.Once();
            timeSouce.Expect(x => x.getDateTime).Return(testTime.AddSeconds(120)).Repeat.Once();
            job.UpdateProgress();
            Assert.AreEqual(new TimeSpan(0, 0, 0), job.EstimatedTimeToCompletion);
        }
Esempio n. 7
0
        public void EnsureTheLiveStatusIsReadCorrectly()
        {
            var audioConfig = MockRepository.GenerateMock <IAudioConfiguration>();

            var portAllocator = MockRepository.GenerateMock <IPortAllocator>();

            portAllocator.Expect(x => x.NewPort()).Return(89);

            var statusSource = MockRepository.GenerateStub <IVlcStatusSource>();

            statusSource.Expect(x => x.GetXml()).Return("Foo");

            var statusParser = MockRepository.GenerateMock <IStatusParser>();

            statusParser.Expect(x => x.Position).Return(67);

            var timeSource = MockRepository.GenerateMock <ITimeSouce>();

            timeSource.Expect(x => x.getDateTime).Return(new DateTime(1988, 03, 26, 18, 0, 0));

            var testFile = TestUtilities.GetTestFile("NeedinYou2SecWavMp3128.mp3");

            var job = new VlcAudioJob(audioConfig, portAllocator, statusParser, statusSource, timeSource, MockRepository.GenerateMock <ILogger>())
            {
                State      = VlcJob.JobState.Started,
                InputFile  = testFile,
                OutputFile = new FileInfo(@"C:\Foo2.txt"),
                Instance   = MockRepository.GenerateMock <IVlcInstance>()
            };

            job.GetVlcArguments();
            job.UpdateProgress();

            Assert.AreEqual("http://localhost:89/requests/status.xml", statusSource.Url, "Correct Url was not generated");
            Assert.AreEqual(67, job.PercentComplete);
            statusSource.AssertWasCalled(x => x.GetXml());
            statusParser.AssertWasCalled(x => x.Parse());
        }
        public void TestVlcWav2Mp3JobActuallyGetsDone()
        {
            var file = TestUtilities.GetTestFile("NeedinYou2SecWav.wav");
            var audioConfiguration = new AudioConfiguration
            {
                Format = AudioConfiguration.ConversionFormats.Mp3
            };

            var portAllocator = MockRepository.GenerateMock <IPortAllocator>();

            portAllocator.Expect(x => x.NewPort()).Return(42);

            var job = new VlcAudioJob(audioConfiguration, portAllocator, MockRepository.GenerateMock <IStatusParser>(), MockRepository.GenerateMock <IVlcStatusSource>(), new TimeSouce(), MockRepository.GenerateMock <ILogger>());

            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            job.InputFile = file;
            var expectedOutputFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output.mp3");

            job.OutputFile = new FileInfo(expectedOutputFile);

            var driver = new VlcDriver(new VlcStarter(MockRepository.GenerateMock <ILogger>()));

            TestUtilities.SetVlcExeLocationOnNonStandardWindowsEnvironments(driver);
            Assert.IsFalse(job.OutputFile.Exists);
            driver.StartJob(job);
            Assert.AreEqual(1, driver.JobBag.Count);
            Assert.IsNotNull(job.Instance);
            Assert.IsNotNull(job.Instance.Process);
            Assert.AreEqual(VlcJob.JobState.Started, job.State);
            job.Instance.Process.WaitForExit();
            SleepToAllowEventHandler();
            Assert.AreEqual(VlcJob.JobState.Finished, job.State);
            var newFileInfo = new FileInfo(job.OutputFile.FullName);

            Assert.IsTrue(newFileInfo.Exists);
            Assert.That(newFileInfo.Length, Is.EqualTo(48901).Within(AllowedOutputFileComparePercentage).Percent);
        }