/// <summary> /// Retrieve connectors for the client /// This method MUST be called on any HubClient instance prior to use /// </summary> /// <returns></returns> public async Task RetrieveConnectors() { HttpResponseMessage response = await connection.GetAsync("connectors"); if (response.IsSuccessStatusCode) { MemoryStream data = (MemoryStream)(await response.Content.ReadAsStreamAsync()); DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings(); settings.UseSimpleDictionaryFormat = true; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<Connector>), settings); connectors = (List<Connector>)serializer.ReadObject(data); foreach (Connector conn in connectors) { if (conn.type == "Connectors::DynamicsEmail") { dynamics = conn; } } } }
public void TestUpdateEmailStatuses() { Link link1 = new Link() { rel = "actions", href = "/connectors/123/actions" }; Event email_sent_event = new Event() { name = "email_sent", external_id = "23a4", message_id = 8080 }; Event email_status_event = new Event() { name = "email_status", message_id = 8081, status = "sent" }; Event invalid_email_status_event = new Event() { name = "email_status", external_id = "dyn54c07-3391-4bc0-a68e-911c2a38ed0e", status = "failed" }; Event invalid_event = new Event() { name = "blah_blah", external_id = "zzz", message_id = 8083 }; Event really_invalid_event = new Event() { name = "email_status", }; List<Event> events = new List<Event>(); events.Add(email_sent_event); events.Add(email_status_event); events.Add(invalid_email_status_event); events.Add(invalid_event); events.Add(really_invalid_event); var connector = new Connector(); connector.links = new List<Link>(); connector.links.Add(link1); var fakeResponseHandler = new FakeHttpMessageHandler(eventResponse(events, new List<Event>())); var fakeHttpClient = new HttpClient(fakeResponseHandler); fakeHttpClient.BaseAddress = new Uri("https://blah.test.com"); var mockClient = new Mock<IDynamicsClient>(); mockClient.Setup(dyn => dyn.AssociateGovdeliveryEmail(It.IsAny<string>(), It.IsAny<string>())); mockClient.Setup(dyn => dyn.UpdateStatus(It.IsAny<string>(), It.IsAny<string>())); mockClient.Setup(dyn => dyn.LookupEmailByGovdeliveryId(It.IsAny<string>())).Returns("5cd54c07-3391-4bc0-a68e-911c2a38ed0e"); var hubClient = new HubClient("https://blah.test.com", "blah", mockClient.Object); var hubConnection = hubClient.GetType().GetField("connection", BindingFlags.NonPublic | BindingFlags.Instance); hubConnection.SetValue(hubClient, fakeHttpClient); var hubDynamics = hubClient.GetType().GetField("dynamics", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); hubDynamics.SetValue(hubClient, connector); hubClient.UpdateEmailStatuses().Wait(); mockClient.Verify(dyn => dyn.AssociateGovdeliveryEmail("23a4", "8080")); mockClient.Verify(dyn => dyn.UpdateStatus("5cd54c07-3391-4bc0-a68e-911c2a38ed0e","Sent")); mockClient.Verify(dyn => dyn.UpdateStatus(invalid_email_status_event.external_id, "Failed")); }
public void TestSendEmailsSuccess() { List<Email> emails = new List<Email>() { new Email() { to = new List<string>() { "*****@*****.**" }, subject = "An email subject", body = "Body content of the email", id = "55a" } }; var connector = new Connector(); connector.links = new List<Link>() { new Link() { rel = "actions", href = "/connectors/123/actions" } }; var fakeResponseHandler = new FakeHttpMessageHandler(new List<HttpResponseMessage> () {new HttpResponseMessage(HttpStatusCode.OK)}); var fakeHttpClient = new HttpClient(fakeResponseHandler); fakeHttpClient.BaseAddress = new Uri("https://blah.test.com"); var mockClient = new Mock<IDynamicsClient>(); mockClient.Setup(dyn => dyn.UpdateStatus(It.IsAny<string>(), It.IsAny<string>())); var hubClient = new HubClient("https://prefix.domain.com", "blah", mockClient.Object); var hubConnection = hubClient.GetType().GetField("connection", BindingFlags.NonPublic | BindingFlags.Instance); hubConnection.SetValue(hubClient, fakeHttpClient); var hubDynamics = hubClient.GetType().GetField("dynamics", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); hubDynamics.SetValue(hubClient, connector); hubClient.SendEmails(emails).Wait(); mockClient.Verify(dyn => dyn.UpdateStatus("55a", "Sending")); }