public void OnTranmission(BatchEmailResponse response) { MessageTransmissionHandler handler = Transmitted; if (handler != null) { var e = new TransmissionEvent(response); handler(e); } }
public TransmissionEvent(BatchEmailResponse response) { Count = response.successCount + response.failureCount; SuccessCount = response.successCount; FailureCount = response.failureCount; StatusMessage = response.statusMessage; Statuses = new List<IMessageBusMessageStatus>(Count); foreach (var result in response.results) { Statuses.Add(new MessageStatus(result)); } }
public void MakesAValidApiRequest() { SetupDefaultExpectations(); var testRequest = new BatchEmailSendRequest { }; testRequest.messages.Add(new BatchEmailMessage { fromEmail = "*****@*****.**", fromName = "Test Sender", tags = new[] { "test", "test2" }, toEmail = "*****@*****.**", subject = "Test Subject", plaintextBody = "Plain Text", htmlBody = "<html><body>HTML</body></html>" }); testRequest.messages[0].customHeaders.Add("Test", "Header"); var testResponse = new BatchEmailResponse { statusMessage = "OK", successCount = 1, failureCount = 0, results = new[] { new BatchEmailResult { messageStatus = 0, messageId = "1234ABCD1234ABCD", toEmail = "*****@*****.**"} } }; ResponseString = new JavaScriptSerializer().Serialize(testResponse); var response = Client.SendEmails(testRequest); Assert.AreEqual("https://api.messagebus.com/api/v3/emails/send", Client.GetArgumentsForCallsMadeOn(x => x.CreateRequest(Arg<String>.Is.Anything, Arg<SimpleHttpClient.HttpMethod>.Is.Anything))[0][0]); var expectedJson = @"{""messages"":[{""toEmail"":""*****@*****.**"",""fromEmail"":""*****@*****.**"",""toName"":null,""fromName"":""Test Sender"",""subject"":""Test Subject"",""plaintextBody"":""Plain Text"",""htmlBody"":""\u003chtml\u003e\u003cbody\u003eHTML\u003c/body\u003e\u003c/html\u003e"",""customHeaders"":{""Test"":""Header""},""tags"":[""test"",""test2""]}]}"; Assert.AreEqual(expectedJson, HttpUtility.UrlDecode(RequestString)); Assert.AreEqual(testResponse.statusMessage, response.statusMessage); Assert.AreEqual(testResponse.successCount, response.successCount); Assert.AreEqual(testResponse.results[0].messageId, response.results[0].messageId); }