public void Run_ShouldCorrectlyParseMailFromAndAddDisplayNameFromHeaders() { //arrange var expectedAddress = new MailAddress("*****@*****.**"); var commandStub = "not empty string"; var headers = new NameValueCollection(); var fromAddressesCollection = new List <MailAddress> { new MailAddress("*****@*****.**"), new MailAddress("*****@*****.**"), new MailAddress("*****@*****.**", "Valentin Display Name") }; _clientController.Read().Returns(commandStub, commandStub, commandStub, _mailDataSection, commandStub); _requestCommandsConverter.ToRequestCommandCode(Arg.Any <string>()) .Returns(RequestCommands.Hello, RequestCommands.MailFrom, RequestCommands.Data, RequestCommands.Quit); _emailParser.ParseEmailFromString(commandStub).Returns(expectedAddress); _emailParser.ParseHeadersFromDataSection(_mailDataSection).Returns(headers); _emailParser.ParseEmailsFromDataFrom(headers).Returns(fromAddressesCollection); //act var message = _clientProcessor.Run(); //assert message.From.Address.Should().Be("*****@*****.**"); message.From.DisplayName.Should().Be("Valentin Display Name"); }
public void ParseHeadersFromDataSection_ShouldParseHeadersOfEmail() { //arrange var dataSection = "\r\nMIME - Version: 1.0\r\n" + "From: \"From Name\" <*****@*****.**>\r\n" + "To: \"To Name\" <*****@*****.**>\r\n" + "Cc: \"To Name\" <*****@*****.**>,\r\n\"To Name\"<*****@*****.**>, \"To \r\nName\"<*****@*****.**>\r\n" + "Date: 19 Dec 2017 17:36:49 +0200\r\n" + "Subject: Subject of this letter\r\n" + "Content-Type: text/plain; charset=us-ascii\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n\r\n" + "\r\n.\r\n\r\n.\r\n" + "\r\n.\r\n"; //act var result = _emailParser.ParseHeadersFromDataSection(dataSection); //assert result.Count.Should().Be(8); result["MIME - Version"].Should().Be("1.0"); result["From"].Should().Be("\"From Name\" <*****@*****.**>"); result["To"].Should().Be("\"To Name\" <*****@*****.**>"); result["Cc"].Should().Be("\"To Name\" <*****@*****.**>,\r\n\"To Name\"<*****@*****.**>, \"To \r\nName\"<*****@*****.**>"); result["Date"].Should().Be("19 Dec 2017 17:36:49 +0200"); result["Subject"].Should().Be("Subject of this letter"); result["Content-Type"].Should().Be("text/plain; charset=us-ascii"); result["Content-Transfer-Encoding"].Should().Be("quoted-printable"); }