public void TestGetAsync_SurveyHasInvitationTemplates_ReturnsInvitationTemplates()
        {
            const string surveyId = "TestSurveyId";

            var expected1 = new InvitationTemplateModel()
            {
                Id             = 1,
                InvitationType = 1,
                Name           = "TestTemplate1",
                Subject        = "TestSubject1",
                Body           = "TestBody1"
            };

            var expected2 = new InvitationTemplateModel()
            {
                Id             = 2,
                InvitationType = 2,
                Name           = "TestTemplate2",
                Subject        = "TestSubject2",
                Body           = "TestBody2"
            };

            var target       = new NfieldSurveyInvitationTemplatesService();
            var returnObject = new[] { expected1, expected2 };
            var requestUri   = new Uri(ServiceAddress, "Surveys/" + surveyId + "/InvitationTemplates/");
            var mockClient   = InitMockClientGet <IEnumerable <InvitationTemplateModel> >(requestUri, returnObject);

            target.InitializeNfieldConnection(mockClient);
            var actualResults = target.GetAsync(surveyId).Result.ToArray();

            Assert.Equal(expected1, actualResults[0], new InvitationTemplateComparer());
            Assert.Equal(expected2, actualResults[1], new InvitationTemplateComparer());
        }
        public void TestRemoveAsync_InvitationTemplateIsRemoved_ReturnsTrue()
        {
            const string surveyId   = "TestSurveyId";
            const int    templateId = 42;

            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(new { IsSuccess = true }));

            mockedHttpClient
            .Setup(client => client.DeleteAsync(new Uri(ServiceAddress, "Surveys/" + surveyId + "/InvitationTemplates/" + templateId)))
            .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldSurveyInvitationTemplatesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.RemoveAsync(surveyId, templateId).Result;

            Assert.Equal(true, actual);
        }
        public void TestUpdateAsync_InvitationTemplateIsUpdated_ReturnsInvitationTemplate()
        {
            const string surveyId   = "TestSurveyId";
            const int    templateId = 42;

            var invitationTemplate = new InvitationTemplateModel
            {
                Id             = templateId,
                InvitationType = 1,
                Body           = "TestBody1"
            };
            var expected = new InvitationTemplateModel
            {
                Id             = templateId,
                InvitationType = invitationTemplate.InvitationType,
                Name           = "a Name",
                Subject        = "a Subject",
                Body           = invitationTemplate.Body
            };

            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(expected));

            mockedHttpClient
            .Setup(client => client.PutAsJsonAsync(new Uri(ServiceAddress, "Surveys/" + surveyId + "/InvitationTemplates/" + templateId), It.Is <InvitationTemplateModel>(t => VerifyInvitationTemplate(t, invitationTemplate))))
            .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldSurveyInvitationTemplatesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.UpdateAsync(surveyId, invitationTemplate).Result;

            Assert.Equal(expected, actual, new InvitationTemplateComparer());
        }
        public void TestAddAsync_InvitationTemplateIsAdded_ReturnsInvitationTemplate()
        {
            const string surveyId = "TestSurveyId";

            var invitationTemplate = new InvitationTemplateModel
            {
                InvitationType = 1,
                Name           = "TestTemplate1",
                Subject        = "TestSubject1",
                Body           = "TestBody1"
            };
            var expected = new InvitationTemplateModel
            {
                Id             = 999,
                InvitationType = invitationTemplate.InvitationType,
                Name           = invitationTemplate.Name,
                Subject        = invitationTemplate.Subject,
                Body           = invitationTemplate.Body
            };

            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(expected));

            mockedHttpClient
            .Setup(client => client.PostAsJsonAsync(new Uri(ServiceAddress, "Surveys/" + surveyId + "/InvitationTemplates/"), invitationTemplate))
            .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldSurveyInvitationTemplatesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.AddAsync(surveyId, invitationTemplate).Result;

            Assert.Equal(expected, actual, new InvitationTemplateComparer());
        }