public async Task<byte[]> WebAPICall(AudioJob auj)
 {
     //return Encoding.ASCII.GetBytes("test");
     byte[] byteRes = null;
     AudioJobRepository audioJobRepo = new AudioJobRepository();
     Guid jobID = await audioJobRepo.SubmitWorkItem(auj);
     while (audioJobRepo.GetWorkStatus(jobID) == 2)
     {
         //wait
         await Task.Delay(200);
     }
     if (audioJobRepo.GetWorkStatus(jobID) == 1)
     {
         //sucess
         FileResult result = audioJobRepo.GetResultContents(jobID);
         byteRes = result.getFileContents();
     }
     else
     {
         //fail
         throw new Exception("Task with job ID: " + jobID + " failed");
     }
     return byteRes;
 }
Ejemplo n.º 2
0
        public async Task TestPostAudioJob()
        {
            //init
            var mockJobs = new Mock<DbSet<Job>>();
            var mockServiceUsers = new Mock<DbSet<ServiceUser>>();
            var mockContext = new Mock<RoboBrailleDataContext>();
            var mockAuSender = new Mock<IAudioJobSender>();

            // arrange
            var users = new List<ServiceUser> { 
                new ServiceUser
                {
                EmailAddress = "*****@*****.**",
                UserId = Guid.Parse("d2b97532-e8c5-e411-8270-f0def103cfd0"),
                ApiKey = Encoding.UTF8.GetBytes("7b76ae41-def3-e411-8030-0c8bfd2336cd"),
                FromDate = new DateTime(2015, 1, 1),
                ToDate = new DateTime(2020, 1, 1),
                UserName = "******",
                Jobs = null
                }
            }.AsQueryable();

            AudioJob auj = new AudioJob()
            {
                Id = Guid.NewGuid(),
                FileContent = new byte[512],
                UserId = Guid.Parse("d2b97532-e8c5-e411-8270-f0def103cfd0"),
                FileExtension = ".pdf",
                FileName = "test",
                MimeType = "application/pdf",
                Status = JobStatus.Started,
                SubmitTime = DateTime.Now,
                DownloadCounter = 0,
                InputFileHash = new byte[64],
                AudioLanguage = Language.daDK,
                FormatOptions = AudioFormat.Mp3,
                SpeedOptions = AudioSpeed.Normal,
                VoicePropriety = new VoicePropriety[] { VoicePropriety.Anne }
            };
            AudioJob auj2 = new AudioJob()
            {
                Id = Guid.NewGuid(),
                FileContent = new byte[256],
                UserId = Guid.Parse("d2b87532-e8c5-e411-8270-f0def103cfd0"),
                FileExtension = ".txt",
                FileName = "test2",
                MimeType = "text/plain",
                Status = JobStatus.Done,
                SubmitTime = DateTime.Now,
                DownloadCounter = 2,
                InputFileHash = new byte[2]
            };
            var jobs = new List<AudioJob> { auj2 }.AsQueryable();

            mockJobs.As<IDbAsyncEnumerable<Job>>().Setup(m => m.GetAsyncEnumerator()).Returns(new TestDbAsyncEnumerator<Job>(jobs.GetEnumerator()));
            mockJobs.As<IQueryable<Job>>().Setup(m => m.Provider).Returns(new TestDbAsyncQueryProvider<Job>(jobs.Provider));

            mockJobs.As<IQueryable<Job>>().Setup(m => m.Expression).Returns(jobs.Expression);
            mockJobs.As<IQueryable<Job>>().Setup(m => m.ElementType).Returns(jobs.ElementType);
            mockJobs.As<IQueryable<Job>>().Setup(m => m.GetEnumerator()).Returns(jobs.GetEnumerator());

            mockServiceUsers.As<IDbAsyncEnumerable<ServiceUser>>().Setup(m => m.GetAsyncEnumerator()).Returns(new TestDbAsyncEnumerator<ServiceUser>(users.GetEnumerator()));
            mockServiceUsers.As<IQueryable<ServiceUser>>().Setup(m => m.Provider).Returns(new TestDbAsyncQueryProvider<ServiceUser>(users.Provider));
            mockServiceUsers.As<IQueryable<ServiceUser>>().Setup(m => m.Expression).Returns(users.Expression);
            mockServiceUsers.As<IQueryable<ServiceUser>>().Setup(m => m.ElementType).Returns(users.ElementType);
            mockServiceUsers.As<IQueryable<ServiceUser>>().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator());

            mockContext.Setup(m => m.Jobs).Returns(mockJobs.Object);
            mockContext.Setup(m => m.ServiceUsers).Returns(mockServiceUsers.Object);
            mockAuSender.Setup(m => m.SendAudioJobToQueue(auj)).Returns(new byte[512]);

            var repo = new AudioJobRepository(mockContext.Object, mockAuSender.Object);

            var request = new HttpRequestMessage();
            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Authorization", "Hawk id=\"d2b97532-e8c5-e411-8270-f0def103cfd0\", ts=\"1470657024\", nonce=\"VkcMGB\", mac=\"hXW+BLRoqwlUaQZQtpPToOWnVAh5KbAXGGT5f8dLMVk=\"");
            var serviceController = new AudioController(repo);
            serviceController.Request = request;
            //call
            await serviceController.Post(auj);

            //test
            mockJobs.Verify(m => m.Add(It.IsAny<Job>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
            mockAuSender.Verify(m => m.SendAudioJobToQueue(It.IsAny<AudioJob>()), Times.Once());
        }
Ejemplo n.º 3
0
        public async Task TestPostAudioJob()
        {
            //init
            var mockJobs         = new Mock <DbSet <Job> >();
            var mockServiceUsers = new Mock <DbSet <ServiceUser> >();
            var mockContext      = new Mock <RoboBrailleDataContext>();
            var mockAuSender     = new Mock <IAudioJobSender>();

            // arrange
            var users = new List <ServiceUser> {
                new ServiceUser
                {
                    EmailAddress = "*****@*****.**",
                    UserId       = Guid.Parse("d2b97532-e8c5-e411-8270-f0def103cfd0"),
                    ApiKey       = Encoding.UTF8.GetBytes("7b76ae41-def3-e411-8030-0c8bfd2336cd"),
                    FromDate     = new DateTime(2015, 1, 1),
                    ToDate       = new DateTime(2020, 1, 1),
                    UserName     = "******",
                    Jobs         = null
                }
            }.AsQueryable();

            AudioJob auj = new AudioJob()
            {
                Id              = Guid.NewGuid(),
                FileContent     = new byte[512],
                UserId          = Guid.Parse("d2b97532-e8c5-e411-8270-f0def103cfd0"),
                FileExtension   = ".pdf",
                FileName        = "test",
                MimeType        = "application/pdf",
                Status          = JobStatus.Started,
                SubmitTime      = DateTime.Now,
                DownloadCounter = 0,
                InputFileHash   = new byte[64],
                AudioLanguage   = Language.daDK,
                FormatOptions   = AudioFormat.Mp3,
                SpeedOptions    = AudioSpeed.Normal,
                VoicePropriety  = new VoicePropriety[] { VoicePropriety.Anne }
            };
            AudioJob auj2 = new AudioJob()
            {
                Id              = Guid.NewGuid(),
                FileContent     = new byte[256],
                UserId          = Guid.Parse("d2b87532-e8c5-e411-8270-f0def103cfd0"),
                FileExtension   = ".txt",
                FileName        = "test2",
                MimeType        = "text/plain",
                Status          = JobStatus.Done,
                SubmitTime      = DateTime.Now,
                DownloadCounter = 2,
                InputFileHash   = new byte[2]
            };
            var jobs = new List <AudioJob> {
                auj2
            }.AsQueryable();

            mockJobs.As <IDbAsyncEnumerable <Job> >().Setup(m => m.GetAsyncEnumerator()).Returns(new TestDbAsyncEnumerator <Job>(jobs.GetEnumerator()));
            mockJobs.As <IQueryable <Job> >().Setup(m => m.Provider).Returns(new TestDbAsyncQueryProvider <Job>(jobs.Provider));

            mockJobs.As <IQueryable <Job> >().Setup(m => m.Expression).Returns(jobs.Expression);
            mockJobs.As <IQueryable <Job> >().Setup(m => m.ElementType).Returns(jobs.ElementType);
            mockJobs.As <IQueryable <Job> >().Setup(m => m.GetEnumerator()).Returns(jobs.GetEnumerator());

            mockServiceUsers.As <IDbAsyncEnumerable <ServiceUser> >().Setup(m => m.GetAsyncEnumerator()).Returns(new TestDbAsyncEnumerator <ServiceUser>(users.GetEnumerator()));
            mockServiceUsers.As <IQueryable <ServiceUser> >().Setup(m => m.Provider).Returns(new TestDbAsyncQueryProvider <ServiceUser>(users.Provider));
            mockServiceUsers.As <IQueryable <ServiceUser> >().Setup(m => m.Expression).Returns(users.Expression);
            mockServiceUsers.As <IQueryable <ServiceUser> >().Setup(m => m.ElementType).Returns(users.ElementType);
            mockServiceUsers.As <IQueryable <ServiceUser> >().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator());

            mockContext.Setup(m => m.Jobs).Returns(mockJobs.Object);
            mockContext.Setup(m => m.ServiceUsers).Returns(mockServiceUsers.Object);
            mockAuSender.Setup(m => m.SendAudioJobToQueue(auj)).Returns(Encoding.UTF8.GetBytes(testFileResult));

            var repo = new AudioJobRepository(mockContext.Object, mockAuSender.Object);

            var request = new HttpRequestMessage();

            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Authorization", "Hawk id=\"d2b97532-e8c5-e411-8270-f0def103cfd0\", ts=\"1470657024\", nonce=\"VkcMGB\", mac=\"hXW+BLRoqwlUaQZQtpPToOWnVAh5KbAXGGT5f8dLMVk=\"");
            var serviceController = new AudioController(repo);

            serviceController.Request = request;
            //call
            await serviceController.Post(auj);

            //test
            mockJobs.Verify(m => m.Add(It.IsAny <Job>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Exactly(2));
            mockAuSender.Verify(m => m.SendAudioJobToQueue(It.IsAny <AudioJob>()), Times.Once());
            Assert.IsFalse(File.Exists(testFileResult));
        }
Ejemplo n.º 4
0
        public void GetNextJobShouldReturnNullIfMachineAlreadyHasAHardSubtitlesJobActive()
        {
            // Arrange
            const string machinename = "TESTMACHINENAME";

            Mock <IHelper>              helper                     = new Mock <IHelper>();
            IAudioJobRepository         audioJobRepository         = new AudioJobRepository(helper.Object);
            IHardSubtitlesJobRepository hardSubtitlesJobRepository = new HardSubtitlesJobRepository(helper.Object, _fixture.ConnectionString);
            IJobRepository              sut = new JobRepository(helper.Object);

            helper.Setup(m => m.GetConnection())
            .Returns(() => new SqlConnection(_fixture.ConnectionString));

            hardSubtitlesJobRepository.Add(new HardSubtitlesJobRequest
            {
                DestinationFilename = "testoutputfilename",
                Needed              = DateTimeOffset.Now,
                OutputFolder        = "testoutputfolder",
                SubtitlesFilename   = "testsubtitlefilename",
                VideoSourceFilename = "testvideofilename"
            }, new List <FFmpegJob>
            {
                new HardSubtitlesJob
                {
                    Needed           = DateTimeOffset.Now,
                    Arguments        = "testarguments",
                    JobCorrelationId = Guid.NewGuid(),
                    SourceFilename   = "testsourcefilename"
                }
            });

            audioJobRepository.Add(new AudioJobRequest
            {
                DestinationFilename = "testoutputfilename",
                Needed          = DateTimeOffset.Now,
                OutputFolder    = "testoutputfolder",
                SourceFilenames = new List <string>
                {
                    "input.wav"
                },
                Targets = new[]
                {
                    new AudioDestinationFormat
                    {
                        AudioCodec = Codec.MP3,
                        Bitrate    = 192,
                        Channels   = Channels.Stereo,
                        Format     = ContainerFormat.MP4
                    }
                }
            }, new List <AudioTranscodingJob>
            {
                new AudioTranscodingJob
                {
                    Needed           = DateTimeOffset.Now,
                    Arguments        = "testarguments",
                    JobCorrelationId = Guid.NewGuid(),
                    SourceFilename   = "testsourcefilename"
                }
            });

            // Act
            var job = sut.GetNextJob(machinename);

            Assert.That(job, Is.Not.Null);

            sut.SaveProgress(job.Id, false, false, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30), machinename);

            var result = sut.GetNextJob(machinename);

            // Assert
            Assert.That(result, Is.Null);
        }