コード例 #1
0
        public void TestModelLanguageToLanguage()
        {
            TranslationJob trj = new TranslationJob()
            {
                Id              = Guid.NewGuid(),
                FileContent     = Encoding.UTF8.GetBytes("This is the first translation job."),
                UserId          = Guid.Parse("d2b97532-e8c5-e411-8270-f0def103cfd0"),
                FileExtension   = "txt",
                FileName        = "test",
                MimeType        = "text/plain",
                Status          = JobStatus.Started,
                SubmitTime      = DateTime.Now,
                DownloadCounter = 0,
                InputFileHash   = new byte[8],
                SourceLanguage  = Language.enGB.ToString(),
                TargetLanguage  = Language.daDK.ToString()
            };
            var repo = new TranslationRepository();

            var jobID = repo.SubmitWorkItem(trj).Result;

            while (repo.GetWorkStatus(jobID) == 2)
            {
                //wait
                Task.Delay(200);
            }
            byte[] res = null;
            if (repo.GetWorkStatus(jobID) == 1)
            {
                //sucess
                FileResult result = repo.GetResultContents(jobID);
                res = result.getFileContents();
            }
            else
            {
                //fail
                throw new Exception("Task with job ID: " + jobID + " failed");
            }

            NUnit.Framework.Assert.AreEqual("This is the first translation job.", Encoding.UTF8.GetString(res));
        }