public void CreateModel_Success() { IClient client = this.CreateClient(); IRequest request = Substitute.For <IRequest>(); client.PostAsync(Arg.Any <string>()) .Returns(request); request.WithArgument(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithBodyContent(Arg.Any <HttpContent>()) .Returns(request); request.As <CustomModels>() .Returns(Task.FromResult(new CustomModels() { ModelId = "new_id" })); LanguageTranslatorService service = new LanguageTranslatorService(client); var customModel = service.CreateModel(CreateModelOptions.CreateOptions() .WithName("base_id") .WithBaseModelId("model_unit_test") .SetForcedGlossary(Substitute.For <FileStream>("any_file", FileMode.Create))); Assert.IsNotNull(customModel); client.Received().PostAsync(Arg.Any <string>()); Assert.IsFalse(string.IsNullOrEmpty(customModel.ModelId)); }
private void CreateModel() { using (FileStream fs = File.OpenRead(_glossaryPath)) { Console.WriteLine(string.Format("Calling CreateModel({0}, {1}, {2})...", _baseModel, _customModelName, _glossaryPath)); var result = _languageTranslator.CreateModel(CreateModelOptions.CreateOptions() .WithBaseModelId(_baseModel) .WithName(_customModelName) .SetForcedGlossary(fs)); if (result != null) { Console.WriteLine(string.Format("Model ID: {0}", result.ModelId)); _customModelID = result.ModelId; } else { Console.WriteLine("Failed to create custom model."); } } }
public void CreateModel_Catch_Exception() { IClient client = this.CreateClient(); IRequest request = Substitute.For <IRequest>(); client.PostAsync(Arg.Any <string>()) .Returns(request); request.WithArgument(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithBodyContent(Arg.Any <HttpContent>()) .Returns(x => { throw new AggregateException(new Exception()); }); LanguageTranslatorService service = new LanguageTranslatorService(client); var customModel = service.CreateModel(CreateModelOptions.CreateOptions() .WithName("base_id") .WithBaseModelId("model_unit_test") .SetForcedGlossary(Substitute.For <FileStream>("any_file", FileMode.Create))); }
public void CreateModel_File_Null() { IClient client = this.CreateClient(); IRequest request = Substitute.For <IRequest>(); client.PostAsync(Arg.Any <string>()) .Returns(request); request.WithArgument(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithBodyContent(Arg.Any <HttpContent>()) .Returns(request); LanguageTranslatorService service = new LanguageTranslatorService(client); var customModel = service.CreateModel(CreateModelOptions.CreateOptions() .WithName("base_id") .WithBaseModelId("model_unit_test") .SetForcedGlossary(null)); }
public void CreateModel_ModelName_WithSpaces() { IClient client = this.CreateClient(); IRequest request = Substitute.For <IRequest>(); client.PostAsync(Arg.Any <string>()) .Returns(request); request.WithArgument(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithBodyContent(Arg.Any <HttpContent>()) .Returns(request); LanguageTranslatorService service = new LanguageTranslatorService(client); var customModel = service.CreateModel(CreateModelOptions.CreateOptions() .WithName("model name") .WithBaseModelId("base_id") .SetForcedGlossary(Substitute.For <FileStream>("any_file_model_name_with_spaces", FileMode.Create))); }