Ejemplo n.º 1
0
        public void TestAddAsync_ServerAccepts_ReturnsSurvey()
        {
            var survey = new Survey(SurveyType.Basic)
            {
                SurveyName = "New Survey"
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(survey));

            mockedHttpClient
            .Setup(client => client.PostAsJsonAsync(ServiceAddress + "surveys/", survey))
            .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.AddAsync(survey).Result;

            Assert.Equal(survey.SurveyName, actual.SurveyName);
            Assert.Equal(survey.SurveyType, actual.SurveyType);
        }