public void TestHandlers() { var initialized = false; SMTPServer actualCore = null; var handler = new StubICommandHandler { InitializeSMTPServer = c => { actualCore = c; initialized = true; } }; var loader = new StubICommandHandlerLoader { GetModules = () => new List <Tuple <string, ICommandHandler> > { new Tuple <string, ICommandHandler>("Test", handler) } }; var core = new SMTPServer(loader); Assert.Same(core, actualCore); Assert.True(initialized); var actualHandler = core.GetHandler("Test"); Assert.Same(handler, actualHandler); var nonExistant = core.GetHandler("NonExistant"); Assert.Null(nonExistant); }
public void TestExecuteSuccess() { const string command = "Test"; var expectedResponse = new SMTPResponse(SMTPStatusCode.NotAvailiable, "Fu", "bar"); const string expectedParams = "Fubar blubb"; using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); SMTPTransaction actualTransaction = null; string actualParams = null; var handler = new StubICommandHandler { ExecuteSMTPTransactionString = (smtpTransaction, s) => { actualTransaction = smtpTransaction; actualParams = s; return(expectedResponse); } }; server.GetHandlerString = s => { if (s.Equals(command, StringComparison.InvariantCultureIgnoreCase)) { return(handler); } throw new InvalidOperationException("Invalid name."); }; var response = transaction.ExecuteCommand(new SMTPCommand(command, expectedParams)); Assert.Same(expectedResponse, response); Assert.Equal(expectedParams, actualParams); Assert.Same(transaction, actualTransaction); } }