public async Task Process_NoParameters_Accepted() { Mocks mocks = new Mocks(); ParameterProcessorMap map = new ParameterProcessorMap(); await map.ProcessAsync(mocks.Connection.Object, new string[] { }, true); }
protected override IMessageBuilder GetInstance() { FileInfo tempFile = new FileInfo(Path.GetTempFileName()); Mocks mocks = new Mocks(); return new FileMessage.Builder(tempFile, false); }
public void Session() { Mocks mocks = new Mocks(); SessionEventArgs s = new SessionEventArgs(mocks.Session.Object); Assert.Equal(s.Session, mocks.Session.Object); }
public async Task Process_BadCommand_500Response() { Mocks mocks = new Mocks(); mocks.ConnectionChannel.Setup(c => c.ReadLineAsync()).ReturnsAsync("BADCOMMAND").Callback(() => mocks.Connection.Object.CloseConnectionAsync().Wait()); Connection connection = new Connection(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object); await connection.ProcessAsync(); mocks.ConnectionChannel.Verify(cc => cc.WriteLineAsync(It.IsRegex("500 .*", RegexOptions.IgnoreCase))); }
public async Task Process_GreetingWritten() { Mocks mocks = new Mocks(); mocks.ConnectionChannel.Setup(c => c.WriteLineAsync(It.IsAny<string>())).Callback(() => mocks.Connection.Object.CloseConnectionAsync().Wait()); Connection connection = new Connection(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object); await connection.ProcessAsync(); mocks.ConnectionChannel.Verify(cc => cc.WriteLineAsync(It.IsRegex("220 .*", RegexOptions.IgnoreCase))); }
public async Task Process_EmptyCommand_NoResponse() { Mocks mocks = new Mocks(); mocks.ConnectionChannel.Setup(c => c.ReadLineAsync()).ReturnsAsync("").Callback(() => mocks.Connection.Object.CloseConnectionAsync().Wait()); Connection connection = new Connection(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object); await connection.ProcessAsync(); //Should only print service ready message mocks.ConnectionChannel.Verify(cc => cc.WriteLineAsync(It.Is<string>(s => !s.StartsWith("220 "))), Times.Never()); }
public async Task Process_UnknownParameter_Throws() { SmtpServerException e = await Assert.ThrowsAsync<SmtpServerException>(async () => { Mocks mocks = new Mocks(); ParameterProcessorMap map = new ParameterProcessorMap(); await map.ProcessAsync(mocks.Connection.Object, new string[] { "KEYA=VALUEA" }, true); }); Assert.Equal("Parameter KEYA is not recognised", e.Message); }
public async Task Process_TooManyBadCommands_Disconnected() { Mocks mocks = new Mocks(); mocks.ServerBehaviour.SetupGet(b => b.MaximumNumberOfSequentialBadCommands).Returns(2); mocks.ConnectionChannel.Setup(c => c.ReadLineAsync()).ReturnsAsync("BADCOMMAND"); Connection connection = new Connection(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object); await connection.ProcessAsync(); mocks.ConnectionChannel.Verify(c => c.ReadLineAsync(), Times.Exactly(2)); mocks.ConnectionChannel.Verify(cc => cc.WriteLineAsync(It.IsRegex("221 .*", RegexOptions.IgnoreCase))); }
public async Task Process_GoodCommand_Processed() { Mocks mocks = new Mocks(); Mock<IVerb> mockVerb = new Mock<IVerb>(); mocks.VerbMap.Setup(v => v.GetVerbProcessor(It.IsAny<string>())).Returns(mockVerb.Object).Callback(() => mocks.Connection.Object.CloseConnectionAsync().Wait()); mocks.ConnectionChannel.Setup(c => c.ReadLineAsync()).ReturnsAsync("GOODCOMMAND"); Connection connection = new Connection(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object); await connection.ProcessAsync(); mockVerb.Verify(v => v.ProcessAsync(It.IsAny<IConnection>(), It.IsAny<SmtpCommand>())); }
public async Task Process_SmtpServerExceptionThrow_ResponseWritten() { Mocks mocks = new Mocks(); Mock<IVerb> mockVerb = new Mock<IVerb>(); mocks.VerbMap.Setup(v => v.GetVerbProcessor(It.IsAny<string>())).Returns(mockVerb.Object); mockVerb.Setup(v => v.ProcessAsync(It.IsAny<IConnection>(), It.IsAny<SmtpCommand>())).Returns(Task.FromException(new SmtpServerException(new SmtpResponse(500, "error")))); mocks.ConnectionChannel.Setup(c => c.ReadLineAsync()).ReturnsAsync("GOODCOMMAND").Callback(() => mocks.Connection.Object.CloseConnectionAsync().Wait()); Connection connection = new Connection(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object); await connection.ProcessAsync(); mocks.ConnectionChannel.Verify(cc => cc.WriteLineAsync(It.IsRegex("500 error", RegexOptions.IgnoreCase))); }
public async Task Process_KnownParameters_Processed() { Mocks mocks = new Mocks(); Mock<IParameterProcessor> keyAProcessor = new Mock<IParameterProcessor>(); Mock<IParameterProcessor> keyBProcessor = new Mock<IParameterProcessor>(); ParameterProcessorMap map = new ParameterProcessorMap(); map.SetProcessor("keya", keyAProcessor.Object); map.SetProcessor("keyb", keyBProcessor.Object); await map.ProcessAsync(mocks.Connection.Object, new string[] { "KEYA=VALUEA", "KEYB=VALUEB" }, true); keyAProcessor.Verify(p => p.SetParameter(mocks.Connection.Object, "KEYA", "VALUEA")); keyBProcessor.Verify(p => p.SetParameter(mocks.Connection.Object, "KEYB", "VALUEB")); }
public void AbortMessage() { Mocks mocks = new Mocks(); Connection connection = new Connection(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object); connection.NewMessage(); connection.AbortMessage(); Assert.Null(connection.CurrentMessage); }
public void CommitMessage() { Mocks mocks = new Mocks(); Connection connection = new Connection(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object); IMessageBuilder messageBuilder = connection.NewMessage(); IMessage message = messageBuilder.ToMessage(); connection.CommitMessage(); mocks.Session.Verify(s => s.AddMessage(message)); mocks.ServerBehaviour.Verify(b => b.OnMessageReceived(connection, message)); Assert.Null(connection.CurrentMessage); }
protected override IMessageBuilder GetInstance() { Mocks mocks = new Mocks(); return new MemoryMessage.Builder(); }
protected override IMessageBuilder GetInstance() { Mocks mocks = new Mocks(); return(new MemoryMessage.Builder()); }