public void Message_WithTo_WithCc_WithBcc_WithReplyToList_ShouldBeSingletons_ShouldDeleteUserSuppliedHeaders()
{
//all examples of headers that users may potentially try to set that we silently discard
string fromHeader = "[email protected]";
string toHeader = "[email protected]";
string ccHeader = "[email protected]";
string bccHeader = "[email protected]";
string replyToHeader = "[email protected]";
//values that will go to the properties- should replace headers with these
string validFrom = "[email protected]";
string validTo = "[email protected]";
string validCc = "[email protected]";
string validBcc = "[email protected]";
string validReplyTo = "[email protected]";
//add bad headers. these are all on singleton header values and therefore should be removed
//automatically by PrepareHeaders and replaced with correct values
_message.Headers.Add("From", fromHeader);
_message.Headers.Add("To", toHeader);
_message.Headers.Add("Cc", ccHeader);
_message.Headers.Add("Bcc", bccHeader);
_message.Headers.Add("Reply-To", replyToHeader);
//these values should overwrite all the headers above
_message.From = new MailAddress(validFrom);
_message.To.Add(new MailAddress(validTo));
_message.CC.Add(new MailAddress(validCc));
_message.Bcc.Add(new MailAddress(validBcc));
_message.ReplyToList.Add(new MailAddress(validReplyTo));
_message.PrepareHeaders(true, false);
string[] fromHeaders = _message.Headers.GetValues("From");
string[] toHeaders = _message.Headers.GetValues("To");
string[] ccHeaders = _message.Headers.GetValues("Cc");
string[] bccHeaders = _message.Headers.GetValues("Bcc");
string[] replyToHeaders = _message.Headers.GetValues("Reply-To");
//all headers supplied by the user should be gone
Assert.Equal(1, fromHeaders.Length);
Assert.Equal(1, toHeaders.Length);
Assert.Equal(1, ccHeaders.Length);
//there should be no bcc header
Assert.Null(bccHeaders);
Assert.Equal(1, replyToHeaders.Length);
//all headers that were set via properties should remain
Assert.True(fromHeaders[0].Contains(validFrom));
Assert.True(toHeaders[0].Contains(validTo));
Assert.True(ccHeaders[0].Contains(validCc));
Assert.True(replyToHeaders[0].Contains(validReplyTo));
}