本文整理汇总了C#中RegressionTests.Shared.TcpConnection.SendAndReceive方法的典型用法代码示例。如果您正苦于以下问题:C# TcpConnection.SendAndReceive方法的具体用法?C# TcpConnection.SendAndReceive怎么用?C# TcpConnection.SendAndReceive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RegressionTests.Shared.TcpConnection
的用法示例。
在下文中一共展示了TcpConnection.SendAndReceive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IfStlsOptionalButSslRequiredByIpRangeForAuthThenAuthShouldFail
public void IfStlsOptionalButSslRequiredByIpRangeForAuthThenAuthShouldFail()
{
var range = SingletonProvider<TestSetup>.Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");
range.RequireSSLTLSForAuth = true;
range.Save();
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25002);
var banner = smtpClientSimulator.Receive();
var capabilities1 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n");
Assert.IsTrue(capabilities1.Contains("STARTTLS"));
var loginResult = smtpClientSimulator.SendAndReceive("AUTH LOGIN\r\n");
Assert.IsTrue(loginResult.StartsWith("530 A SSL/TLS-connection is required for authentication.")); // must run starttls first.
}
示例2: IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse
public void IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse()
{
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25);
var data1 = smtpClientSimulator.Receive();
var data = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n");
Assert.IsFalse(data.Contains("STARTTLS"));
}
示例3: HandshakeCompletionShouldBeLoggedWithCipherDetails
public void HandshakeCompletionShouldBeLoggedWithCipherDetails()
{
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25002);
var banner = smtpClientSimulator.Receive();
var capabilities1 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n");
Assert.IsTrue(capabilities1.Contains("STARTTLS"));
smtpClientSimulator.SendAndReceive("STARTTLS\r\n");
smtpClientSimulator.HandshakeAsClient();
var capabilities2 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n");
var default_log = LogHandler.ReadCurrentDefaultLog();
Assert.IsTrue(default_log.Contains("Version: TLS"));
Assert.IsTrue(default_log.Contains("Cipher: "));
Assert.IsTrue(default_log.Contains("Bits: "));
}
示例4: TestTooManyInvalidCommandsHELO
public void TestTooManyInvalidCommandsHELO()
{
Settings settings = _settings;
settings.DisconnectInvalidClients = true;
settings.MaxNumberOfInvalidCommands = 3;
var sim = new TcpConnection();
sim.Connect(25);
sim.Receive(); // banner
sim.SendAndReceive("HELO\r\n");
sim.SendAndReceive("HELO\r\n");
sim.SendAndReceive("HELO\r\n");
sim.SendAndReceive("HELO\r\n");
var result = sim.SendAndReceive("HELO\r\n");
CustomAssert.IsTrue(result.Contains("Too many invalid commands"), result);
}
示例5: TestRcptToSyntax
public void TestRcptToSyntax()
{
Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test");
var oSMTP = new TcpConnection();
oSMTP.Connect(25);
CustomAssert.IsTrue(oSMTP.Receive().StartsWith("220"));
oSMTP.Send("HELO test\r\n");
CustomAssert.IsTrue(oSMTP.Receive().StartsWith("250"));
// A few tests of invalid syntax.
CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: <[email protected]>\r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("RCPT TO: [email protected]>\r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("RCPT TO: <[email protected]\r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("RCPT TO <[email protected]\r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("RCPT TO<[email protected]\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("RCPT TO: <[email protected]>\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("RCPT TO: [email protected]\r\n").StartsWith("250"));
oSMTP.Disconnect();
}
示例6: TestMailFromSyntaxValidation
public void TestMailFromSyntaxValidation()
{
Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test");
var oSMTP = new TcpConnection();
oSMTP.Connect(25);
CustomAssert.IsTrue(oSMTP.Receive().StartsWith("220"));
oSMTP.Send("HELO test\r\n");
CustomAssert.IsTrue(oSMTP.Receive().StartsWith("250"));
// A few tests of invalid syntax.
CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: <[email protected]\r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: [email protected]>\r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: < [email protected] \r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: < \r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: > \r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: <[email protected]\r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM <[email protected]>\r\n").StartsWith("250"));
CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM [email protected]\r\n").StartsWith("250"));
// Valid syntax, < and >
CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: <[email protected]>\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: [email protected]\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: [email protected] \r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM:[email protected]\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM:<[email protected]>\r\n").StartsWith("250"));
CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250"));
oSMTP.Disconnect();
}
示例7: AssertValidMailRcptToCommand
private void AssertValidMailRcptToCommand(string comamnd)
{
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25);
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("220"));
smtpClientSimulator.Send("HELO test\r\n");
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250"));
smtpClientSimulator.Send("MAIL FROM: <[email protected]>\r\n");
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250"));
string result = smtpClientSimulator.SendAndReceive(comamnd + "\r\n");
smtpClientSimulator.Disconnect();
Assert.AreEqual("250 OK\r\n", result);
}
示例8: IfStlsRequiredLogonShouldSucceedIfStls
public void IfStlsRequiredLogonShouldSucceedIfStls()
{
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25003);
var banner = smtpClientSimulator.Receive();
var capabilities1 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n");
Assert.IsTrue(capabilities1.Contains("STARTTLS"));
smtpClientSimulator.SendAndReceive("STARTTLS\r\n");
smtpClientSimulator.HandshakeAsClient();
var loginResult = smtpClientSimulator.SendAndReceive("AUTH LOGIN\r\n");
Assert.IsTrue(loginResult.StartsWith("334"));
}
示例9: IfStlsRequiredLogonShouldFailIfNoStls
public void IfStlsRequiredLogonShouldFailIfNoStls()
{
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25003);
var banner = smtpClientSimulator.Receive();
var capabilities1 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n");
Assert.IsTrue(capabilities1.Contains("STARTTLS"));
var loginResult = smtpClientSimulator.SendAndReceive("AUTH LOGIN\r\n");
Assert.IsTrue(loginResult.StartsWith("530 Must issue STARTTLS first."));
}
示例10: TestTooManyInvalidCommandsHELOSuccesfullCommandDoesNotResetCounter
public void TestTooManyInvalidCommandsHELOSuccesfullCommandDoesNotResetCounter()
{
Settings settings = _settings;
settings.DisconnectInvalidClients = true;
settings.MaxNumberOfInvalidCommands = 3;
var sim = new TcpConnection();
sim.Connect(25);
sim.Receive(); // banner
sim.SendAndReceive("HELO\r\n");
sim.SendAndReceive("HELO\r\n");
sim.SendAndReceive("HELO\r\n");
var result = sim.SendAndReceive("HELO test.com\r\n");
Assert.IsTrue(result.Contains("250 Hello."), result);
result = sim.SendAndReceive("HELO\r\n");
Assert.IsTrue(result.Contains("Too many invalid commands"), result);
}
示例11: StartTlsCommandShouldSwithToTls
public void StartTlsCommandShouldSwithToTls()
{
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25002);
var banner = smtpClientSimulator.Receive();
var capabilities1 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n");
Assert.IsTrue(capabilities1.Contains("STARTTLS"));
smtpClientSimulator.SendAndReceive("STARTTLS\r\n");
smtpClientSimulator.HandshakeAsClient();
// Send a command over TLS.
var capabilities2 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n");
Assert.IsFalse(capabilities2.Contains("STARTTLS"));
// We're now on SSL.
}
示例12: TestRcptToSyntax
public void TestRcptToSyntax()
{
SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test");
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25);
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("220"));
smtpClientSimulator.Send("HELO test\r\n");
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250"));
// A few tests of invalid syntax.
Assert.IsTrue(smtpClientSimulator.SendAndReceive("MAIL FROM: <[email protected]>\r\n").StartsWith("250"));
Assert.IsFalse(smtpClientSimulator.SendAndReceive("RCPT TO: [email protected]>\r\n").StartsWith("250"));
Assert.IsFalse(smtpClientSimulator.SendAndReceive("RCPT TO: <[email protected]\r\n").StartsWith("250"));
Assert.IsFalse(smtpClientSimulator.SendAndReceive("RCPT TO <[email protected]\r\n").StartsWith("250"));
Assert.IsFalse(smtpClientSimulator.SendAndReceive("RCPT TO<[email protected]\r\n").StartsWith("250"));
Assert.IsTrue(smtpClientSimulator.SendAndReceive("RCPT TO: <[email protected]>\r\n").StartsWith("250"));
Assert.IsTrue(smtpClientSimulator.SendAndReceive("RCPT TO: [email protected]\r\n").StartsWith("250"));
smtpClientSimulator.Disconnect();
}
示例13: MailFromWithAuthParameterShouldBeAccepted
public void MailFromWithAuthParameterShouldBeAccepted()
{
Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test");
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25);
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("220"));
smtpClientSimulator.Send("HELO test\r\n");
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250"));
// A few tests of invalid syntax.
Assert.IsTrue(smtpClientSimulator.SendAndReceive("MAIL FROM: <[email protected]> AUTH=<>\r\n").StartsWith("250"));
smtpClientSimulator.Disconnect();
}
示例14: TestTooManyInvalidCommandsUnknownRcptShouldBeCounted
public void TestTooManyInvalidCommandsUnknownRcptShouldBeCounted()
{
Settings settings = _settings;
settings.DisconnectInvalidClients = true;
settings.MaxNumberOfInvalidCommands = 3;
var sim = new TcpConnection();
sim.Connect(25);
sim.Receive(); // banner
sim.SendAndReceive("HELO example.com\r\n");
sim.SendAndReceive("MAIL FROM: [email protected]\r\n");
var result = sim.SendAndReceive("RCPT TO: [email protected]\r\n");
Assert.IsTrue(result.Contains("550 Unknown user"), result);
result = sim.SendAndReceive("RCPT TO: [email protected]\r\n");
Assert.IsTrue(result.Contains("550 Unknown user"), result);
result = sim.SendAndReceive("RCPT TO: [email protected]\r\n");
Assert.IsTrue(result.Contains("550 Unknown user"), result);
result = sim.SendAndReceive("RCPT TO: [email protected]\r\n");
Assert.IsTrue(result.Contains("Too many invalid commands"), result);
}
示例15: AssertInvalidMailFromCommand
private void AssertInvalidMailFromCommand(string command, string expectedResponse)
{
var smtpClientSimulator = new TcpConnection();
smtpClientSimulator.Connect(25);
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("220"));
smtpClientSimulator.Send("HELO test\r\n");
Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250"));
string result = smtpClientSimulator.SendAndReceive(command+ "\r\n");
smtpClientSimulator.Disconnect();
Assert.AreEqual(expectedResponse + "\r\n", result);
}