Skip to content

Commit

Permalink
Correct GetMessage and GetMessage History.
Browse files Browse the repository at this point in the history
Tests now use local user vals when in debug, process when release (for
travis)
  • Loading branch information
AshleyMedway committed Jun 4, 2015
1 parent 317c2f1 commit 5afb7d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions MailJet.Client.Tests/GetMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ public class GetMessages
[SetUp]
public void Setup()
{
#if DEBUG
var publicKey = Environment.GetEnvironmentVariable("MailJetPub", EnvironmentVariableTarget.User);
var privateKey = Environment.GetEnvironmentVariable("MailJetPri", EnvironmentVariableTarget.User);
#else
var publicKey = Environment.GetEnvironmentVariable("MailJetPub");
var privateKey = Environment.GetEnvironmentVariable("MailJetPri");
#endif

if (String.IsNullOrWhiteSpace(publicKey))
throw new InvalidOperationException("Add your MailJet public API Key to the Environment Variable \"MailJetPub\".");
Expand Down Expand Up @@ -41,6 +46,16 @@ public void GetMessages_Test()
Assert.IsTrue(result.Data.Any());
Assert.AreEqual(result.Count, result.Data.Count);
}

[Test]
public void GetMessageHistory_Test()
{
var message = _client.GetMessages().Data.First();
var result = _client.GetMessage(message.ID);
Assert.IsNotNull(result);
Assert.IsTrue(result.Data.Any());
Assert.AreEqual(result.Count, result.Data.Count);
}
}
}

11 changes: 11 additions & 0 deletions MailJet.Client.Tests/SendMail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ public class SendMail
[SetUp]
public void Setup()
{
#if DEBUG
var publicKey = Environment.GetEnvironmentVariable("MailJetPub", EnvironmentVariableTarget.User);
var privateKey = Environment.GetEnvironmentVariable("MailJetPri", EnvironmentVariableTarget.User);
#else
var publicKey = Environment.GetEnvironmentVariable("MailJetPub");
var privateKey = Environment.GetEnvironmentVariable("MailJetPri");
#endif

if (String.IsNullOrWhiteSpace(publicKey))
throw new InvalidOperationException("Add your MailJet public API Key to the Environment Variable \"MailJetPub\".");
Expand Down Expand Up @@ -59,8 +64,14 @@ public void MailMessage_Html_NoAttachements()

private MailMessage BaseMessage()
{
#if DEBUG
var testFrom = Environment.GetEnvironmentVariable("MailJetTestFrom", EnvironmentVariableTarget.User);
var testTo = Environment.GetEnvironmentVariable("MailJetTestTo", EnvironmentVariableTarget.User);
#else
var testFrom = Environment.GetEnvironmentVariable("MailJetTestFrom");
var testTo = Environment.GetEnvironmentVariable("MailJetTestTo");
#endif


var message = new MailMessage()
{
Expand Down
11 changes: 10 additions & 1 deletion MailJetClient/MailJetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public SendResponse SendMessage(MailMessage Message)
return data;
}

public MessageHistoryResponse GetMessage(long MessageId)
public MessageHistoryResponse GetMessageHistory(long MessageId)
{
var request = new RestRequest("REST/messagehistory/{id}", Method.GET);
request.AddParameter("id", MessageId);
Expand All @@ -87,6 +87,15 @@ public MessageHistoryResponse GetMessage(long MessageId)
return data;
}

public MessageResponse GetMessage(long MessageId)
{
var request = new RestRequest("REST/message/{id}", Method.GET);
request.AddParameter("id", MessageId);
var result = WebClient.Execute(request);
var data = JsonConvert.DeserializeObject<MessageResponse>(result.Content);
return data;
}

public MessageResponse GetMessages(int? Limit = null)
{
var request = new RestRequest("REST/message", Method.GET);
Expand Down

0 comments on commit 5afb7d9

Please sign in to comment.