public async Task Translate_LessReturnDataSecond() { using (var session = new KeySession()) { var fixture = new TranslateFixture(); fixture.SetupTranslateLessResultSecond(); var respository = new TranslatorRepository(fixture.TranslatorContext); // In the setup callback, I write Assert. var result = await respository.TranslateAsync(fixture.InputText, fixture.InputLanguage); Assert.Equal("", result); } }
public async Task Translate_Normal() { using (var session = new KeySession()) { var fixture = new TranslateFixture(); var ExpectedURL = $"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to={fixture.InputLanguage}"; fixture.SetupTranslate(session.InputKey, ExpectedURL); var respository = new TranslatorRepository(fixture.TranslatorContext); // In the setup callback, I write Assert. var result = await respository.TranslateAsync(fixture.InputText, fixture.InputLanguage); Assert.Equal(fixture.ExpectedTranslatedText, result); } }
public async Task Translate_Exception() { using (var session = new KeySession()) { var fixture = new TranslateFixture(); var ExpectedURL = $"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to={fixture.InputLanguage}"; fixture.SetupTranslateFailure(ExpectedURL); var respository = new TranslatorRepository(fixture.TranslatorContext); // In the setup callback, I write Assert. var ex = await Assert.ThrowsAsync <RestAPICallException>(async() => await respository.TranslateAsync(fixture.InputText, fixture.InputLanguage) ); Assert.Equal("InternalServerError", ex.StatusCode); Assert.Equal("Internal Server Error", ex.Message); Assert.Equal(ExpectedURL, ex.RequestMessage.RequestUri.ToString()); } }