Skip to content

Commit

Permalink
Moved AddRoutePointingAtLocalhost from SMTPClientTests to TestSetup s…
Browse files Browse the repository at this point in the history
…ince it's shared by many tests (minor)
  • Loading branch information
martinknafve committed Oct 30, 2014
1 parent 2991d91 commit 8707a79
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 92 deletions.
2 changes: 1 addition & 1 deletion hmailserver/test/RegressionTests/POP3/Fetching/Basics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void TestDeliverToExternalMimeRecipientsEnabled()
smtpServer.StartListen();

// Add a route so we can connect to localhost.
Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false);
Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);
route.TreatSecurityAsLocalDomain = true;
route.Save();

Expand Down
4 changes: 2 additions & 2 deletions hmailserver/test/RegressionTests/Rules/Rules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public void ActionSendUsingRoute()
Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "[email protected]", "test");

// Add a route so we can conenct to localhost.
Route route = SMTPClientTests.AddRoutePointingAtLocalhost(5, smtpServerPort, false);
Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Add a global send-using-route rule
Rule oRule = _application.Rules.Add();
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public void TestDeliveryAttempts()
smtpServer.StartListen();

// Add a route so we can connect to localhost.
SMTPClientTests.AddRoutePointingAtLocalhost(2, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(2, smtpServerPort, false);

var oSMTP = new SmtpClientSimulator();

Expand Down
6 changes: 3 additions & 3 deletions hmailserver/test/RegressionTests/SMTP/Basics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void DomainAliasesShouldNotRewriteRecipientList()
server.StartListen();


Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone);
Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone);

// Now send a message from [email protected] to [email protected].
// Error scenario:
Expand Down Expand Up @@ -485,7 +485,7 @@ public void TestMultipleHostsLimitMXHosts()
server.StartListen();

// Add a route so we can connect to localhost.
Route route = SMTPClientTests.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);
Route route = TestSetup.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -689,7 +689,7 @@ public void TestSendExternalToExternalPermitted()
server.AddRecipientResult(deliveryResults);
server.StartListen();

Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);
Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);

var oSMTP = new SmtpClientSimulator();
oSMTP.Send("[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion hmailserver/test/RegressionTests/SMTP/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void ShouldBePossibleToSendToRouteWithTargetIPAddress()
server.AddRecipientResult(deliveryResults);
server.StartListen();

Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone);
Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone);
route.TargetSMTPHost = "127.0.0.1";
route.Save();

Expand Down
12 changes: 6 additions & 6 deletions hmailserver/test/RegressionTests/SMTP/SMTPClientStartTLSTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void UseStartTlsIfEnabledAndAvailable()
server.AddRecipientResult(deliveryResults);
server.StartListen();

Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional);
Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -63,7 +63,7 @@ public void DoNotUseStartTlsIfEnabledButNotAvailable()
server.AddRecipientResult(deliveryResults);
server.StartListen();

Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional);
Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -93,7 +93,7 @@ public void DoNotUseStartTlsIfNotEnabledButAvailable()
server.AddRecipientResult(deliveryResults);
server.StartListen();

Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);
Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -124,7 +124,7 @@ public void DoNotUseStartTlsIfNotEnabledAndNotAvailable()
server.AddRecipientResult(deliveryResults);
server.StartListen();

Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);
Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -161,7 +161,7 @@ public void TestDelivertoServerNotSupportingEHLOOptionalConnectionSecurity()
server.StartListen();

// Add a route so we can conenct to localhost.
SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional);
TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional);

// Send message to this route.

Expand Down Expand Up @@ -194,7 +194,7 @@ public void TestDeliverToServerNotSupportingEHLORequiredConnectionSecurity()
server.StartListen();

// Add a route so we can conenct to localhost.
SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSRequired);
TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSRequired);

// Send message to this route.

Expand Down
86 changes: 24 additions & 62 deletions hmailserver/test/RegressionTests/SMTP/SMTPClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,6 @@ public class SMTPClientTests : TestFixtureBase
private Status _status;
private Account _account;

internal static Route AddRoutePointingAtLocalhost(int numberOfTries, int port, bool treatSecurityAsLocal, eConnectionSecurity connectionSecurity)
{
// Add a route pointing at localhost
Settings oSettings = SingletonProvider<TestSetup>.Instance.GetApp().Settings;

Route route = oSettings.Routes.Add();
route.DomainName = "dummy-example.com";
route.TargetSMTPHost = "localhost";
route.TargetSMTPPort = port;
route.NumberOfTries = numberOfTries;
route.MinutesBetweenTry = 5;
route.TreatRecipientAsLocalDomain = treatSecurityAsLocal;
route.TreatSenderAsLocalDomain = treatSecurityAsLocal;
route.ConnectionSecurity = connectionSecurity;
route.Save();

return route;
}

internal static Route AddRoutePointingAtLocalhost(int numberOfTries, int port, bool treatSecurityAsLocal)
{
return AddRoutePointingAtLocalhost(numberOfTries, port, treatSecurityAsLocal, eConnectionSecurity.eCSNone);
}

public static Route AddRoutePointingAtLocalhostMultipleHosts(int numberOfTries, int port)
{
// Add a route pointing at localhost
Route route = AddRoutePointingAtLocalhost(numberOfTries, port, false);
route.DomainName = "dummy-example.com";
route.TargetSMTPHost = "localhost|localhost";
route.TargetSMTPPort = port;
route.NumberOfTries = numberOfTries;
route.MinutesBetweenTry = 5;
route.Save();

return route;
}

[Test]
[Description("Make sure that the bounce message doesn't include a SMTP auth password")]
public void TestAuthFailurePasswordInBounce()
Expand All @@ -86,7 +48,7 @@ public void TestAuthFailurePasswordInBounce()
server.StartListen();

// Add a route so we can connect to localhost.
Route route = AddRoutePointingAtLocalhost(5, smtpServerPort, false);
Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);
route.RelayerRequiresAuth = true;
route.RelayerAuthUsername = "[email protected]";
route.SetRelayerAuthPassword("MySecretPassword");
Expand Down Expand Up @@ -118,7 +80,7 @@ public void TestDeliverToMyselfOnLocalPort()
Assert.AreEqual(0, _status.UndeliveredMessages.Length);

// Add a route so we can conenct to localhost.
AddRoutePointingAtLocalhost(1, 25, false);
TestSetup.AddRoutePointingAtLocalhost(1, 25, false);

// Send message to this route.
SmtpClientSimulator.StaticSend("[email protected]", "[email protected]", "subject", "body");
Expand Down Expand Up @@ -171,7 +133,7 @@ public void TestDeliverToMyselfOnLocalPortAfterChangedLocalPort()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var sim = new SmtpClientSimulator(false, 11000);
Expand Down Expand Up @@ -210,7 +172,7 @@ public void TestDeliverySuccess250Recipients()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -248,7 +210,7 @@ public void TestDeliverySuccess50Recipients()
server.StartListen();

// Add a route so we can conenct to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -289,7 +251,7 @@ public void TestDeliverySuccessDisconnectAfterMessageAccept()
server.SimulatedError = SimulatedErrorType.DisconnectAfterMessageAccept;

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -322,7 +284,7 @@ public void TestDeliverySuccessSingleRecipient()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -357,7 +319,7 @@ public void TestLargeMessageSuccess()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var messageBody = TestSetup.CreateLargeDummyMailBody();
Expand Down Expand Up @@ -396,7 +358,7 @@ public void TestDeliverySuccessSingleRecipientMissingQuitResponse()
server.SimulatedError = SimulatedErrorType.DisconnectWithoutReplyOnQuit;

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -431,7 +393,7 @@ public void TestErrorOnMailFrom()
server.StartListen();

// Add a route so we can conenct to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -471,7 +433,7 @@ public void TestFailureAfterConnect()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(1, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -514,7 +476,7 @@ public void TestFailureAfterDelivery()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -551,7 +513,7 @@ public void TestFailureAfterDeliveryStarted()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(1, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -593,7 +555,7 @@ public void TestFailureAfterReceivedHelloBanner()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(1, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -636,7 +598,7 @@ public void TestFatalDeliveryFailure()
server.StartListen();

// Add a route so we can conenct to localhost.
AddRoutePointingAtLocalhost(0, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(0, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -698,7 +660,7 @@ public void TestMultipleHostsHalfDeliveryOnFirstPermanentOnSecond()


// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhostMultipleHosts(1, smtpServerPort);
TestSetup.AddRoutePointingAtLocalhostMultipleHosts(1, smtpServerPort);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -744,7 +706,7 @@ public void TestMultipleHostsTemporaryFailure()
server.StartListen();

// Add a route so we can connect to localhost.
Route route = AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);
Route route = TestSetup.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -814,7 +776,7 @@ public void TestMultipleHostsTemporaryFailureDeliveryOnSecondServer()


// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);
TestSetup.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -856,7 +818,7 @@ public void TestPartialTemporaryErrorFailure()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(2, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(2, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -916,7 +878,7 @@ public void TestPermanentFailure()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(5, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -957,7 +919,7 @@ public void TestSMTPClientTimeout()
server.StartListen();

// Add a route so we can connect to localhost.
Route route = AddRoutePointingAtLocalhost(5, smtpServerPort, false);
Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);
route.RelayerRequiresAuth = true;
route.RelayerAuthUsername = "[email protected]";
route.SetRelayerAuthPassword("MySecretPassword");
Expand Down Expand Up @@ -990,7 +952,7 @@ public void TestTemporaryFailure()
server.StartListen();

// Add a route so we can connect to localhost.
AddRoutePointingAtLocalhost(2, smtpServerPort, false);
TestSetup.AddRoutePointingAtLocalhost(2, smtpServerPort, false);

// Send message to this route.
var smtp = new SmtpClientSimulator();
Expand Down Expand Up @@ -1043,7 +1005,7 @@ public void TestDeliverToServerNotSupportingEHLO()
server.StartListen();

// Add a route so we can conenct to localhost.
SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);
TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);


SmtpClientSimulator.StaticSend("[email protected]", "[email protected]", "Test", "Test message");
Expand Down Expand Up @@ -1075,7 +1037,7 @@ public void TestDeliverToServerNotSupportingHELO()
server.StartListen();

// Add a route so we can conenct to localhost.
SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);
TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);

// Send message to this route.

Expand Down
Loading

0 comments on commit 8707a79

Please sign in to comment.