public void TestDefaultTextsAsync_ServerReturnsQuery_ReturnsListWithTranslations() { var expectedTranslations = new Translation[] { new Translation { Name = "X", Text = "Translation X" }, new Translation { Name = "Y", Text = "Translation Y" } }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(new Uri(ServiceAddress, "DefaultTexts"))) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedTranslations)))); var target = new NfieldTranslationsService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actualTranslations = target.DefaultTextsAsync.Result; Assert.Equal(expectedTranslations[0].Name, actualTranslations.ToArray()[0].Name); Assert.Equal(expectedTranslations[1].Name, actualTranslations.ToArray()[1].Name); Assert.Equal(2, actualTranslations.Count()); }
public void TestRemoveAsync_ServerRemovedTranslation_DoesNotThrow() { var translation = new Translation { Name = "X", Text = "Translation X" }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.DeleteAsync(ServiceAddress + "Surveys/" + SurveyId + "/Languages/10/Translations/X")) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldTranslationsService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); Assert.DoesNotThrow(() => target.RemoveAsync(SurveyId, LanguageId, translation).Wait()); }
public void TestAddAsync_ServerAcceptsTranslation_ReturnsTranslation() { var translation = new Translation { Name = "X", Text = "X Translated" }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); var content = new StringContent(JsonConvert.SerializeObject(translation)); mockedHttpClient .Setup(client => client.PostAsJsonAsync(new Uri(ServiceAddress, "Surveys/" + SurveyId + "/Languages/10/Translations"), translation)) .Returns(CreateTask(HttpStatusCode.OK, content)); var target = new NfieldTranslationsService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.AddAsync(SurveyId, LanguageId, translation).Result; Assert.Equal(translation.Name, actual.Name); }
public void TestUpdateAsync_TranslationExists_DoesNotThrow() { var translation = new Translation { Name = "X", Text = "Translation X" }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.PutAsJsonAsync( new Uri(ServiceAddress, "Surveys/" + SurveyId + "/Languages/10/Translations"), It.IsAny <Translation>())) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldTranslationsService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); // assert: no throw target.UpdateAsync(SurveyId, LanguageId, translation).Wait(); }
public void TestRemoveAsync_TranslationIsNull_ThrowsArgumentNullException() { var target = new NfieldTranslationsService(); Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.RemoveAsync(SurveyId, LanguageId, null))); }
public void TestRemoveAsync_SurveyIdIsEmpty_Throws() { var target = new NfieldTranslationsService(); Assert.Throws <ArgumentException>(() => UnwrapAggregateException(target.RemoveAsync("", 0, new Translation()))); }
public void TestAddAsync_SurveyIdIsNull_Throws() { var target = new NfieldTranslationsService(); Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.AddAsync(null, 0, new Translation()))); }