public void TestAddAsync_ServerAcceptsLanguage_ReturnsLanguage() { var language = new Language { Name = "Language X" }; var mockedNfieldConnection = new Mock<INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); var content = new StringContent(JsonConvert.SerializeObject(language)); mockedHttpClient .Setup(client => client.PostAsJsonAsync(ServiceAddress + "Surveys/" + SurveyId + "/Languages", language)) .Returns(CreateTask(HttpStatusCode.OK, content)); var target = new NfieldLanguagesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.AddAsync(SurveyId, language).Result; Assert.Equal(language.Name, actual.Name); }
public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithLanguages() { var expectedLanguages = new Language[] { new Language{Id = 11, Name = "X"}, new Language{Id = 12, Name = "Y"} }; var mockedNfieldConnection = new Mock<INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(ServiceAddress + "Surveys/" + SurveyId + "/Languages")) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedLanguages)))); var target = new NfieldLanguagesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actualLanguages = target.QueryAsync(SurveyId).Result; Assert.Equal(expectedLanguages[0].Id, actualLanguages.ToArray()[0].Id); Assert.Equal(expectedLanguages[1].Id, actualLanguages.ToArray()[1].Id); Assert.Equal(2, actualLanguages.Count()); }
public void TestAddAsync_SurveyIdIsNull_Throws() { var target = new NfieldLanguagesService(); Assert.Throws<ArgumentNullException>(() => UnwrapAggregateException(target.AddAsync(null, new Language()))); }
public void TestUpdateAsync_SurveyIdIsEmpty_Throws() { var target = new NfieldLanguagesService(); Assert.Throws<ArgumentException>(() => UnwrapAggregateException(target.UpdateAsync("", new Language()))); }
public void TestUpdateAsync_LanguageIsNull_ThrowsArgumentNullException() { var target = new NfieldLanguagesService(); Assert.Throws<ArgumentNullException>(() => UnwrapAggregateException(target.UpdateAsync(SurveyId, null))); }
public void TestUpdateAsync_LanguageExists_DoesNotThrow() { const int LanguageId = 11; var language = new Language { Id = LanguageId, Name = "XXX" }; var mockedNfieldConnection = new Mock<INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.PutAsJsonAsync( ServiceAddress + "Surveys/" + SurveyId + "/Languages", language)) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldLanguagesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); Assert.DoesNotThrow(() => target.UpdateAsync(SurveyId, language).Wait()); }
public void TestRemoveAsync_ServerRemovedInterviewer_DoesNotThrow() { const int LanguageId = 11; var language = new Language { Id = LanguageId }; var mockedNfieldConnection = new Mock<INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.DeleteAsync(ServiceAddress + "Surveys/" + SurveyId + "/Languages/" + LanguageId.ToString())) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldLanguagesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); Assert.DoesNotThrow(() => target.RemoveAsync(SurveyId, language).Wait()); }