コード例 #1
0
        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());
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        public void TestRemoveAsync_TranslationIsNull_ThrowsArgumentNullException()
        {
            var target = new NfieldTranslationsService();

            Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.RemoveAsync(SurveyId, LanguageId, null)));
        }
コード例 #6
0
        public void TestRemoveAsync_SurveyIdIsEmpty_Throws()
        {
            var target = new NfieldTranslationsService();

            Assert.Throws <ArgumentException>(() => UnwrapAggregateException(target.RemoveAsync("", 0, new Translation())));
        }
コード例 #7
0
        public void TestAddAsync_SurveyIdIsNull_Throws()
        {
            var target = new NfieldTranslationsService();

            Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.AddAsync(null, 0, new Translation())));
        }