public void TestStartTLS() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); var args = new CancelEventArgs(); CancelEventArgs actualArgs = null; object actualSender = null; var called = false; transaction.OnStartTLS += (sender, eventArgs) => { called = true; actualSender = sender; actualArgs = eventArgs; }; transaction.StartTLS(args); Assert.True(called); Assert.Same(transaction, actualSender); Assert.Same(args, actualArgs); } }
public void TestGetListProperty(bool permanent) { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); var list = transaction.GetListProperty <string>("foo", permanent); Assert.NotNull(list); Assert.Empty(list); list.Add("fubar"); list = transaction.GetListProperty <string>("foo", permanent); Assert.NotNull(list); Assert.Contains("fubar", list); transaction.SetProperty("foo", null, permanent); list = transaction.GetListProperty <string>("foo", permanent); Assert.NotNull(list); Assert.Empty(list); } }
public void TestSetAndGetProperty(bool permanent) { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); const int value1 = 5; const string value2 = "foo"; const bool value3 = false; var value4 = new object(); transaction.SetProperty("foo", value1, permanent); var actualValue1 = transaction.GetProperty <int>("foo"); Assert.Equal(value1, actualValue1); transaction.SetProperty("foo", value2, permanent); var actualValue2 = transaction.GetProperty <string>("foo"); Assert.Equal(value2, actualValue2); transaction.SetProperty("foo", value3, permanent); var actualValue3 = transaction.GetProperty <bool>("foo"); Assert.Equal(value3, actualValue3); transaction.SetProperty("foo", value4, permanent); var actualValue4 = transaction.GetProperty <object>("foo"); Assert.Equal(value4, actualValue4); } }
public TestBase() { _context = ShimsContext.Create(); Transaction = new ShimSMTPTransaction(); Core = new ShimSMTPServer(); Transaction.ServerGet = () => Core; ShimSMTPTransaction.BehaveAsNotImplemented(); ShimSMTPServer.BehaveAsNotImplemented(); }
public void TestNonDataModeError() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); Assert.False(transaction.InDataMode); Assert.Throws <InvalidOperationException>(() => transaction.HandleData("")); Assert.Throws <InvalidOperationException>(() => transaction.HandleDataLine("", new StringBuilder())); } }
public void TestGetNonExistantProperty() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); Assert.Equal(default(int), transaction.GetProperty <int>("nonExistant")); Assert.Equal(default(bool), transaction.GetProperty <bool>("nonExistant")); Assert.Equal(default(string), transaction.GetProperty <string>("nonExistant")); } }
public void TestExecuteFail() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); server.GetHandlerString = s => null; var response = transaction.ExecuteCommand(new SMTPCommand("NonExistentCommand", "Params")); Assert.Equal(SMTPStatusCode.SyntaxError, response.Code); } }
public void TestConstructor() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); Assert.Same(server.Instance, transaction.Server); Assert.Same(settings, transaction.Settings); Assert.False(transaction.InDataMode); Assert.False(transaction.Initialized); } }
public void TestResetDataMode() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); Assert.False(transaction.InDataMode); transaction.StartDataMode((s, builder) => false, s => new SMTPResponse(SMTPStatusCode.Okay)); Assert.True(transaction.InDataMode); transaction.Reset(); Assert.False(transaction.InDataMode); } }
public void TestInitialize() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); const string clientId = "ClientID"; Assert.False(transaction.Initialized); transaction.Initialize(clientId); Assert.True(transaction.Initialized); Assert.Equal(clientId, transaction.ClientIdentifier); } }
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); } }
public void TestClose() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); var closed = false; transaction.OnClose += smtpTransaction => closed = true; Assert.False(transaction.Closed); transaction.Close(); Assert.True(transaction.Closed); Assert.True(closed); } }
public void TestDataHandling(bool expectedResult) { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); Assert.False(transaction.InDataMode); const string expectedData = "Some data"; string actualData = null; const string expectedLine = "Some line"; string actualLine = null; var expectedStringBuilder = new StringBuilder(); StringBuilder actualStringBuilder = null; var expectedResponse = new SMTPResponse(SMTPStatusCode.Okay); transaction.StartDataMode((line, builder) => { actualLine = line; actualStringBuilder = builder; return(expectedResult); }, data => { actualData = data; return(expectedResponse); }); var actualResult = transaction.HandleDataLine(expectedLine, expectedStringBuilder); var actualResponse = transaction.HandleData(expectedData); Assert.Equal(expectedResult, actualResult); Assert.Same(expectedResponse, actualResponse); Assert.Same(expectedStringBuilder, actualStringBuilder); Assert.Equal(expectedData, actualData); Assert.Equal(expectedLine, actualLine); } }
public void TestResetProperties() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); transaction.SetProperty("foo", "bar", false); transaction.SetProperty("foo2", "baz", true); Assert.True(transaction.HasProperty("foo")); Assert.Equal("bar", transaction.GetProperty <string>("foo")); Assert.True(transaction.HasProperty("foo2")); Assert.Equal("baz", transaction.GetProperty <string>("foo2")); transaction.Reset(); Assert.False(transaction.HasProperty("foo")); Assert.Equal(default(string), transaction.GetProperty <string>("foo")); Assert.True(transaction.HasProperty("foo2")); Assert.Equal("baz", transaction.GetProperty <string>("foo2")); } }
public void TestHasProperty() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); Assert.False(transaction.HasProperty("foo")); transaction.SetProperty("foo", 5, false); Assert.True(transaction.HasProperty("foo")); transaction.SetProperty("foo", null, false); Assert.False(transaction.HasProperty("foo")); transaction.SetProperty("foo", 5, true); Assert.True(transaction.HasProperty("foo")); transaction.SetProperty("foo", null, true); Assert.False(transaction.HasProperty("foo")); } }
public void TestOvershadowingProperties() { using (ShimsContext.Create()) { var server = new ShimSMTPServer(); var settings = new StubIReceiveSettings(); var transaction = new SMTPTransaction(server, settings); const string value1 = "bar"; const string value2 = "baz"; transaction.SetProperty("foo", value1, true); Assert.Equal(value1, transaction.GetProperty <string>("foo")); transaction.SetProperty("foo", value2, false); Assert.Equal(value2, transaction.GetProperty <string>("foo")); transaction.SetProperty("foo", null, false); Assert.Equal(value1, transaction.GetProperty <string>("foo")); transaction.SetProperty("foo", null, true); Assert.Equal(default(string), transaction.GetProperty <string>("foo")); } }