Nfield.Services.Implementation.NfieldRespondentDataEncryptService.InitializeNfieldConnection C# (CSharp) Method

InitializeNfieldConnection() public method

Initializes the nfield connection.
public InitializeNfieldConnection ( INfieldConnectionClient connection ) : void
connection INfieldConnectionClient The connection.
return void
        public void InitializeNfieldConnection(INfieldConnectionClient connection)
        {
            ConnectionClient = connection;
        }

Usage Example

        public void TestEncryption_SurveyId_DoesntExists_ReturnsResourceNotFoundException()
        {
            var dataModel = new DataCryptographyModel { Data = new Dictionary<string, string> { { "DataExample1", "ValueExample1" }, { "DataExample2", "ValueExample2" } }, IV = "VGhpc0lzQUJhc2U2NDY0Ng==" };

            _mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            _mockedHttpClient = CreateHttpClientMock(_mockedNfieldConnection);

            // API call response
            var expectedResult = @"IV=VGhpc0lzQUJhc2U2NDY0Ng==&DATA=kDdE+WOvPi45K6q1fC8iLIJ+M7j5xZmETPf24AS81jk=";
            _mockedHttpClient.Setup(client => client.PostAsJsonAsync($"{ServiceAddress}Surveys/{SurveyId}/RespondentDataEncrypt", dataModel))
               .Returns(CreateTask(HttpStatusCode.OK, new ObjectContent<string>(expectedResult, new JsonMediaTypeFormatter())));

            _target = new NfieldRespondentDataEncryptService();
            _target.InitializeNfieldConnection(_mockedNfieldConnection.Object);

            var sdkResult = _target.EncryptData(SurveyId, dataModel).Result;

            Assert.Equal(expectedResult, sdkResult);
        }