InitializeNfieldConnection() public method

public InitializeNfieldConnection ( INfieldConnectionClient connection ) : void
connection INfieldConnectionClient
return void
        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(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 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(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 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(
                    ServiceAddress + "Surveys/" + SurveyId + "/Languages/10/Translations", It.IsAny<Translation>()))
                .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldTranslationsService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            Assert.DoesNotThrow(() => target.UpdateAsync(SurveyId, LanguageId, translation).Wait());
        }