0

I am really new to C# and am trying to troubleshoot a test of some code that uses Amazon SES to send email.

    [TestMethod()]
    public void SendEmailTest()
    {
        SESEmailProvider target = new SESEmailProvider();

        string ToEmailAddresses = "[email protected]";
        string FromEmailAddress = "[email protected]";
        string Subject = "Test";
        string EmailBody = "Hello world.";
        string expected = string.Empty;
        string actual;
        actual = target.SendEmail(ToEmailAddresses, FromEmailAddress, Subject, EmailBody);
        Assert.AreEqual(expected, actual);
        Assert.Inconclusive("Verify the correctness of this test method.");
    }

The error message in Visual Studio is:

string SESEmailProvider.SendEmail(
 System.Collections.Generic.List<string> ToEmailAddresses,
 string FromEmailAddress, string Subject, string EmailBody)

Error:

 The best overloaded method match for 'MyServices.SESEmailProvider.SendEmail(
   System.Collections.Generic.List<string>, string, string, string)'
  has some invalid arguements.

I think the issue is that it's expecting ToEmailAddresses to be a list, not a single string, but I'm struggling to find a way to convert/handle this.

Thanks!

3 Answers 3

4

well you've defined the variable ToEmailAddresses as a string, but you want it to be a list.

there are many ways to define and fill a list, but the most compact is:

var toEmailAddresses = new List<string> { "[email protected]" }

the above creates a new list, and initializes it with a single string "[email protected]"

Sign up to request clarification or add additional context in comments.

2 Comments

note that you can initialize the list with multiple values by comma separating them e.g. .....{ "item1", "item2", "item3" }
Thanks - this worked perfectly. I'll accept the answer as soon as the wait time is up. Thanks again!
2

SendMail expects a List as it's first argument - not a string.

So, do:

List<String> toAddresses = new List<String>();
toAddresses.Add("[email protected]");

pass toAddresses as the first arg

The clue was in the error message. It expects List, string, string, string

The best overloaded method match for 'MyServices.SESEmailProvider.SendEmail(
System.Collections.Generic.List, string, string, string)'
has some invalid arguements.

Comments

1
[TestMethod()] 
public void SendEmailTest() 
{ 
    SESEmailProvider target = new SESEmailProvider(); 

    List<string> ToEmailAddresses = new List<string>() {"[email protected]"}; 
    string FromEmailAddress = "[email protected]"; 
    string Subject = "Test"; 
    string EmailBody = "Hello world."; 
    string expected = string.Empty; 
    string actual; 
    actual = target.SendEmail(ToEmailAddresses, FromEmailAddress, Subject, EmailBody); 
    Assert.AreEqual(expected, actual); 
    Assert.Inconclusive("Verify the correctness of this test method."); 
} 

Try that. I have changed your variable from a string to a List<string>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.