Beispiel #1
0
        public async Task RestartUnfinishedBuild()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.CreateEngineService();
                Engine engine = await env.CreateEngineAsync();

                EngineRuntime runtime = env.GetRuntime(engine.Id);
                await runtime.InitNewAsync();

                env.BatchTrainer.Train(Arg.Any <IProgress <ProgressStatus> >(), Arg.Do <Action>(checkCanceled =>
                {
                    while (true)
                    {
                        checkCanceled();
                    }
                }));
                Build build = await runtime.StartBuildAsync();

                Assert.That(build, Is.Not.Null);
                await env.WaitForBuildToStartAsync(build.Id);

                env.DisposeEngineService();
                build = await env.BuildRepository.GetAsync(build.Id);

                Assert.That(build.State, Is.EqualTo(BuildStates.Pending));
                env.CreateEngineService();
                await env.WaitForBuildToFinishAsync(build.Id);

                build = await env.BuildRepository.GetAsync(build.Id);

                Assert.That(build.State, Is.EqualTo(BuildStates.Completed));
            }
        }
Beispiel #2
0
        public async Task AddProjectAsync_ProjectEngineExists()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                string engineId = (await env.CreateEngineAsync("es", "en", false)).Id;
                env.CreateEngineService();
                var project = new Project
                {
                    Id = "project2",
                    SourceLanguageTag = "es",
                    TargetLanguageTag = "en",
                    SourceSegmentType = "latin",
                    TargetSegmentType = "latin",
                    IsShared          = true
                };
                bool created = await env.Service.AddProjectAsync(project);

                Assert.That(created, Is.True);

                Engine engine = await env.EngineRepository.GetAsync(project.EngineRef);

                Assert.That(engine.Id, Is.Not.EqualTo(engineId));
                Assert.That(engine.Projects, Contains.Item("project2"));
            }
        }
Beispiel #3
0
 public async Task CancelBuildAsync_EngineExistsNotBuilding()
 {
     using (var env = new EngineServiceTestEnvironment())
     {
         string engineId = (await env.CreateEngineAsync("es", "en", true)).Id;
         env.CreateEngineService();
         await env.Service.CancelBuildAsync(engineId);
     }
 }
Beispiel #4
0
        public async Task TranslateAsync_EngineDoesNotExist()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.CreateEngineService();
                TranslationResult result = await env.Service.TranslateAsync("engine1", "Esto es una prueba .".Split());

                Assert.That(result, Is.Null);
            }
        }
Beispiel #5
0
        public async Task TrainSegmentAsync_EngineDoesNotExist()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.CreateEngineService();
                bool result = await env.Service.TrainSegmentAsync("engine1", "Esto es una prueba .".Split(),
                                                                  "This is a test .".Split());

                Assert.That(result, Is.False);
            }
        }
Beispiel #6
0
        public async Task StartBuildAsync_EngineExists()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                string engineId = (await env.CreateEngineAsync("es", "en", true)).Id;
                env.CreateEngineService();
                Build build = await env.Service.StartBuildAsync(engineId);

                Assert.That(build, Is.Not.Null);
            }
        }
Beispiel #7
0
        public async Task TranslateAsync_EngineExists()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                string engineId = (await env.CreateEngineAsync("es", "en", true)).Id;
                env.CreateEngineService();
                TranslationResult result = await env.Service.TranslateAsync(engineId, "Esto es una prueba .".Split());

                Assert.That(result.TargetSegment, Is.EqualTo("this is a test .".Split()));
            }
        }
Beispiel #8
0
        public async Task TrainSegmentAsync_EngineExists()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                string engineId = (await env.CreateEngineAsync("es", "en", true)).Id;
                env.CreateEngineService();
                bool result = await env.Service.TrainSegmentAsync(engineId, "Esto es una prueba .".Split(),
                                                                  "This is a test .".Split());

                Assert.That(result, Is.True);
            }
        }
Beispiel #9
0
        public async Task RemoveProjectAsync_ProjectDoesNotExist()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                await env.CreateEngineAsync("es", "en", false);

                env.CreateEngineService();
                bool result = await env.Service.RemoveProjectAsync("project3");

                Assert.That(result, Is.False);
            }
        }
Beispiel #10
0
        public async Task InteractiveTranslateAsync_EngineExists()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                string engineId = (await env.CreateEngineAsync("es", "en", true)).Id;
                env.CreateEngineService();
                HybridInteractiveTranslationResult result = await env.Service.InteractiveTranslateAsync(
                    engineId, "Esto es una prueba .".Split());

                Assert.That(result.RuleResult.TargetSegment, Is.EqualTo("this is a test .".Split()));
                Assert.That(result.SmtWordGraph.Arcs.SelectMany(a => a.Words), Is.EqualTo("this is a test .".Split()));
            }
        }
Beispiel #11
0
        public async Task RemoveProjectAsync_NonsharedProjectExists()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                string engineId = (await env.CreateEngineAsync("es", "en", false)).Id;
                env.CreateEngineService();
                bool result = await env.Service.RemoveProjectAsync("project1");

                Assert.That(result, Is.True);
                Engine engine = await env.EngineRepository.GetAsync(engineId);

                Assert.That(engine, Is.Null);
            }
        }
Beispiel #12
0
        public async Task TranslateAsync()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.EngineOptions.InactiveEngineTimeout = TimeSpan.FromHours(1);
                env.CreateEngineService();
                Engine engine = await env.CreateEngineAsync();

                EngineRuntime runtime = env.GetRuntime(engine.Id);
                await runtime.InitNewAsync();

                TranslationResult result = await runtime.TranslateAsync("esto es una prueba .".Split());

                Assert.That(result.TargetSegment, Is.EqualTo("this is a test .".Split()));
            }
        }
Beispiel #13
0
        public async Task CommitAsync_LoadedActive()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.EngineOptions.InactiveEngineTimeout = TimeSpan.FromHours(1);
                env.CreateEngineService();
                Engine engine = await env.CreateEngineAsync();

                EngineRuntime runtime = env.GetRuntime(engine.Id);
                await runtime.InitNewAsync();

                await runtime.TrainSegmentPairAsync("esto es una prueba .".Split(), "this is a test .".Split());

                await runtime.CommitAsync();

                env.SmtModel.Received().Save();
                Assert.That(runtime.IsLoaded, Is.True);
            }
        }
Beispiel #14
0
        public async Task AddProjectAsync_NonsharedProjectExists()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                await env.CreateEngineAsync("es", "en", false);

                env.CreateEngineService();
                var project = new Project
                {
                    Id = "project1",
                    SourceLanguageTag = "es",
                    TargetLanguageTag = "en",
                    SourceSegmentType = "latin",
                    TargetSegmentType = "latin",
                    IsShared          = false
                };
                bool created = await env.Service.AddProjectAsync(project);

                Assert.That(created, Is.False);
            }
        }
Beispiel #15
0
        public async Task StartBuildAsync_BatchTrainerCalled()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.CreateEngineService();
                Engine engine = await env.CreateEngineAsync();

                EngineRuntime runtime = env.GetRuntime(engine.Id);
                await runtime.InitNewAsync();

                Build build = await runtime.StartBuildAsync();

                Assert.That(build, Is.Not.Null);
                await env.WaitForBuildToFinishAsync(build.Id);

                env.BatchTrainer.Received().Train(Arg.Any <IProgress <ProgressStatus> >(), Arg.Any <Action>());
                env.BatchTrainer.Received().Save();
                build = await env.BuildRepository.GetAsync(build.Id);

                Assert.That(build.State, Is.EqualTo(BuildStates.Completed));
            }
        }
Beispiel #16
0
        public async Task AddProjectAsync_EngineDoesNotExist()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.CreateEngineService();
                var project = new Project
                {
                    Id = "project1",
                    SourceLanguageTag = "es",
                    TargetLanguageTag = "en",
                    SourceSegmentType = "latin",
                    TargetSegmentType = "latin",
                    IsShared          = true
                };
                bool created = await env.Service.AddProjectAsync(project);

                Assert.That(created, Is.True);

                Engine engine = await env.EngineRepository.GetAsync(project.EngineRef);

                Assert.That(engine.Projects, Contains.Item("project1"));
            }
        }