public void TestGetInvitationStatusAsync_ProvideBatchName_ReturnsData() { const string batchName = "TestBatch"; const string respondentKey = "TestRespondent"; const string expectedStatus = "Test"; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); var target = new NfieldSurveyInviteRespondentsService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var expectedResult = new { RespondentKey = respondentKey, Status = expectedStatus }; var url = new Uri(ServiceAddress, $"Surveys/{SurveyId}/InviteRespondents/InvitationStatus/{batchName}"); mockedHttpClient.Setup(client => client.GetAsync(url)) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(new[] { expectedResult })))); var result = target.GetInvitationStatusAsync(SurveyId, batchName).Result.ToArray(); Assert.Equal(1, result.Length); Assert.Equal(respondentKey, result[0].RespondentKey); Assert.Equal(expectedStatus, result[0].Status); }
public void TestGetSurveyBatchesStatusAsync_ProvideBatchName_ReturnsData() { var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); var target = new NfieldSurveyInviteRespondentsService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var expectedResult = new { SurveyId = SurveyId, BatchName = "BatchName", Status = "Status", ScheduledFor = DateTime.UtcNow, TotalCount = 1, ScheduledCount = 2, PendingCount = 3, NotSentCount = 4, ErrorCount = 5, SentCount = 6, OpenedCount = 7, ClickedCount = 8, UnsubscribedCount = 9, AbuseReportCount = 10, UnknownCount = 11 }; var url = new Uri(ServiceAddress, $"Surveys/{SurveyId}/InviteRespondents/SurveyBatchesStatus/"); mockedHttpClient.Setup(client => client.GetAsync(url)) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(new[] { expectedResult })))); var result = target.GetSurveyBatchesStatusAsync(SurveyId).Result.ToArray(); Assert.Equal(1, result.Length); Assert.Equal(expectedResult.SurveyId, result[0].SurveyId); Assert.Equal(expectedResult.BatchName, result[0].BatchName); Assert.Equal(expectedResult.Status, result[0].Status); Assert.Equal(expectedResult.ScheduledFor, result[0].ScheduledFor); Assert.Equal(expectedResult.TotalCount, result[0].TotalCount); Assert.Equal(expectedResult.ScheduledCount, result[0].ScheduledCount); Assert.Equal(expectedResult.PendingCount, result[0].PendingCount); Assert.Equal(expectedResult.NotSentCount, result[0].NotSentCount); Assert.Equal(expectedResult.ErrorCount, result[0].ErrorCount); Assert.Equal(expectedResult.SentCount, result[0].SentCount); Assert.Equal(expectedResult.OpenedCount, result[0].OpenedCount); Assert.Equal(expectedResult.ClickedCount, result[0].ClickedCount); Assert.Equal(expectedResult.UnsubscribedCount, result[0].UnsubscribedCount); Assert.Equal(expectedResult.AbuseReportCount, result[0].AbuseReportCount); Assert.Equal(expectedResult.UnknownCount, result[0].UnknownCount); }
public void TestSendInvitationsAsync_ServerAccepts_ReturnsCorrectInviteRespondentsStatus() { var scheduledFor = DateTime.Now.AddDays(2); var batch = new InvitationBatch { RespondentKeys = new List <string> { "r1", "r2" }, EmailColumnName = "email", InvitationTemplateId = 2, Name = "FirstBatch", ScheduledFor = scheduledFor }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); var expectedResult = new InviteRespondentsStatus { Count = 2, Status = "Completed", ErrorMessage = "" }; var url = new Uri(ServiceAddress, $"Surveys/{SurveyId}/InviteRespondents/"); mockedHttpClient.Setup(client => client .PostAsJsonAsync(url, It.Is <InvitationBatchWithFilter>(b => b.Name == batch.Name && b.ScheduledFor == batch.ScheduledFor && b.EmailColumnName == batch.EmailColumnName && b.InvitationTemplateId == batch.InvitationTemplateId ))) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedResult)))); var target = new NfieldSurveyInviteRespondentsService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var result = target.SendInvitationsAsync(SurveyId, batch).Result; // Verify the filter send mockedHttpClient.Verify(s => s.PostAsJsonAsync( url, It.Is <InvitationBatchWithFilter>(b => b.Filters.Count() == 1 && FilterEquals(b.Filters.First(), "RespondentKey", "in", string.Join(",", batch.RespondentKeys)))), Times.Once()); Assert.Equal(expectedResult.Count, result.Count); Assert.Equal(expectedResult.Status, result.Status); Assert.Equal(expectedResult.ErrorMessage, result.ErrorMessage); }