public void TestAwstatsLog() { Settings settings = SingletonProvider <TestSetup> .Instance.GetApp().Settings; Logging logging = settings.Logging; logging.AWStatsEnabled = true; logging.Enabled = true; if (File.Exists(logging.CurrentAwstatsLog)) { File.Delete(logging.CurrentAwstatsLog); } Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); IPAddress localAddress = TestSetup.GetLocalIpAddress(); var oSMTP = new SMTPClientSimulator(false, 25, localAddress); // Delivery from external to local. CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1); string contents = TestSetup.ReadExistingTextFile(logging.CurrentAwstatsLog); TestSetup.AssertDeleteFile(logging.CurrentAwstatsLog); string expectedString = string.Format("\[email protected]\[email protected]\t{0}\t127.0.0.1\tSMTP\t?\t250\t", localAddress); CustomAssert.IsTrue(contents.Contains(expectedString), contents); // Failed delivery from local to local. CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); contents = TestSetup.ReadExistingTextFile(logging.CurrentAwstatsLog); TestSetup.AssertDeleteFile(logging.CurrentAwstatsLog); expectedString = string.Format("\[email protected]\[email protected]\t{0}\t127.0.0.1\tSMTP\t?\t530\t", localAddress); CustomAssert.IsTrue(contents.Contains(expectedString), contents); }
public void ReferenceSourceWithCodeFool() { CustomAssert.IsTrue( EmailAddressValidator.ReferenceSource, Examples.Valid, // False negatives: new[] { @"much.“more\ unusual”@example.com", @"very.unusual.“@”[email protected]", @"very.“(),:;<>[]”.VERY.“very@\ ""very”[email protected]", } ); CustomAssert.IsFalse( EmailAddressValidator.ReferenceSource, Examples.Invalid, // False positives: new[] { @"*****@*****.**", @"Joe Smith <*****@*****.**>", @"*****@*****.**", @"*****@*****.**", @"*****@*****.**", @"[email protected]", @"email@example", @"*****@*****.**", @"[email protected] (Joe Smith)", @"*****@*****.**", @"あいうえお@example.com", } ); }
public static void AssertSpamAssassinIsRunning() { Process[] processlist = Process.GetProcesses(); foreach (Process theprocess in processlist) { if (theprocess.ProcessName == "spamd") { return; } } // Check if we can launch it... try { var serviceController = new ServiceController("SpamAssassinJAM"); serviceController.Start(); } catch (Exception) { CustomAssert.Inconclusive("Unable to start SpamAssassin process. Is SpamAssassin installed?"); } }
public void Set() { var xml = Xml("<Foo/>"); var foo = Create <IFoo>(xml); foo.Value = "value"; CustomAssert.AreXmlEquivalent(string.Concat ( "<Foo>", "<A>", "<C H='value'>", "<D E=''>", "<F>f</F>", "</D>", "<G/>", "</C>", "<B>b</B>", "</A>", "</Foo>" ), xml); Assert.AreEqual("value", foo.Value); }
public void TestImportDuplicateMessage() { string @messageText = "From: [email protected]\r\n" + "\r\n" + "Test\r\n"; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string domainPath = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com"); string accountPath = Path.Combine(domainPath, "test"); Directory.CreateDirectory(accountPath); string fileName = Path.Combine(accountPath, "something.eml"); File.WriteAllText(fileName, messageText); CustomAssert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); CustomAssert.IsFalse(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1); }
public void AsVirtual_WhenParentIsVirtualNode() { var xml = Xml("<X/>"); IXmlCursor cursor; cursor = xml.SelectChildren( KnownTypes, NamespaceSource.Instance, CursorFlags.Elements | CursorFlags.Mutable ); cursor.MoveNext(); cursor = cursor.SelectChildren( KnownTypes, NamespaceSource.Instance, CursorFlags.Elements | CursorFlags.Mutable ); cursor.MoveNext(); var node = (IXmlNode)cursor; node.Value = "1"; CustomAssert.AreXmlEquivalent("<X> <Item><Item>1</Item></Item> </X>", xml.GetNode()); }
public void TestTOPSpecificPartial() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); for (int i = 1; i <= 10; i++) { SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n"); } POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); var sim = new POP3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.TOP(4, 2); CustomAssert.IsTrue(result.Contains("Received")); CustomAssert.IsTrue(result.Contains("Line1")); CustomAssert.IsTrue(result.Contains("Line2")); CustomAssert.IsFalse(result.Contains("Line3")); CustomAssert.IsFalse(result.Contains("Line4")); }
public void GetCacheTime_WithAllHeadersToSMaxAge_RespectsCorrectHeaders() { // arrange var cacheHeaders = BuildHeaders( immutable: true, sharedCache: true, eTag: new EntityTagHeaderValue("\"an etag\"", false), maxAge: TimeSpan.FromDays(1), sMaxAge: TimeSpan.FromDays(2), exipiresUtc: DateTime.UtcNow.AddDays(3)); // act var result = ((ExpirySettings.Soft)build(cacheHeaders).Value.ExpirySettings).Item; // assert var both = ((Validator.Both)result.Validator).Item; CustomAssert.Roughly(DateTime.UtcNow.AddDays(3), both.Item2); var etag = ((EntityTag.Strong)both.Item1).Item; Assert.AreEqual("\"an etag\"", etag); }
public void TestMostlyLatinCharacters() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var message = new hMailServer.Message(); message.AddRecipient("Test Recipient: Тест", account.Address); message.Subject = "Test Subject: Тест"; message.Charset = "utf-8"; message.Body = "Test body."; message.Save(); string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); // Important: // RFC 2047: http://www.faqs.org/rfcs/rfc2047.html // The notation of RFC 822 is used, with the exception that white space // characters MUST NOT appear between components of an 'encoded-word'. // // Also, there should be a space separating the encoded word with the following // non-encoded word. CustomAssert.IsTrue(messageText.Contains("To: \"=?utf-8?B?VGVzdCBSZWNpcGllbnQ6INCi0LXRgdGC?=\" <*****@*****.**>")); }
public void TestDomainMaxSizeLimit() { _domain.MaxSize = 30; _domain.Save(); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1", 10); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1", 10); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1", 10); try { SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1", 10); } catch (Exception) { return; } CustomAssert.Fail("Max domain size limit exceeded."); }
public void TestDomainMaxMessageSizeLimit() { _domain.MaxMessageSize = 0; _domain.Save(); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1", 0); var message = new StringBuilder(); for (int i = 0; i < 10000; i++) { message.Append("ABCDEFGH"); } CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "TestSubject", message.ToString())); POP3ClientSimulator.AssertMessageCount("*****@*****.**", "secret1", 1); _domain.MaxMessageSize = 50; _domain.Save(); CustomAssert.IsFalse(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "TestSubject", message.ToString())); }
public void TestDomainLimitNumberOfDistributionLists() { _domain.MaxNumberOfDistributionListsEnabled = true; _domain.MaxNumberOfDistributionLists = 2; _domain.Save(); var recipients = new List <string>(); SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients); SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients); try { SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients); } catch (Exception) { return; } CustomAssert.Fail("Number of aliases exceeded max no of accounts"); }
public void TestDomainLimitNumberOfAccounts() { _domain.MaxNumberOfAccountsEnabled = true; _domain.MaxNumberOfAccounts = 3; _domain.Save(); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1"); try { SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1"); } catch (Exception) { return; } CustomAssert.Fail("Number of accounts exceeded max no of accounts"); }
public void CountCompareSkip_NegativeOverflow() { // arrange // set A to -2 with negative overflow Memory[0x000] = ((~2) & 0xBFFF).ToOnesCompliment(); // insert instructions Memory.LoadFixedRom(new ushort[] { Instruction(0x01, 0x000) // CCS A }); // act CPU.Execute(); // assert // ensure result has positove overflow and is decremented CustomAssert.AreEqual((0x4000 | 0x0001), Memory[0x0]); // check that program counter advanced 3 CustomAssert.AreEqual(0x803, Memory[0x05]); }
public void CountCompareSkip_PositiveOverflowAnd0() { // arrange // set A to 0 with positive overflow Memory[0x000] = new OnesCompliment(0x4000 | 0); // insert instructions Memory.LoadFixedRom(new ushort[] { Instruction(0x01, 0x000) // CCS A }); // act CPU.Execute(); // assert // check that A contains value without overflow CustomAssert.AreEqual(0x3FFF, Memory[0x0]); // check that program counter advanced 1 CustomAssert.AreEqual(0x801, Memory[0x05]); }
public void TestMessageScoreNotMerged() { // Send a messages to this account. var smtpClientSimulator = new SMTPClientSimulator(); smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int scoreStart = sMessageContents.IndexOf("X-hMailServer-Reason-Score"); CustomAssert.AreNotEqual(0, scoreStart); scoreStart = sMessageContents.IndexOf(":", scoreStart) + 2; int scoreEnd = sMessageContents.IndexOf("\r\n", scoreStart); int scoreLength = scoreEnd - scoreStart; string score = sMessageContents.Substring(scoreStart, scoreLength); double scoreValue = Convert.ToDouble(score); CustomAssert.Less(scoreValue, 10); }
public void HaackedWithWikipedia() { CustomAssert.IsTrue( EmailAddressValidator.Haacked, Examples.Valid, // False negatives: new[] { @"""()<>[]:,;@\\""!#$%&'*+-/=?^_`{}| ~.a""@example.org", @"""very.(),:;<>[]\"".VERY.\""very@\ \""very\"".unusual""@strange.example.com", @"admin@mailserver1", @"üñîçøðé@example.com", @"üñîçøðé@üñîçøðé.com", } ); CustomAssert.IsFalse( EmailAddressValidator.Haacked, Examples.Invalid ); }
public int GetMessageCount(string sFolder) { string sData = SendSingleCommand("A33 SELECT " + sFolder); if (!sData.Contains("A33 OK")) { CustomAssert.Fail("The folder " + sFolder + " was not selectable. Result: " + sData); return(0); } int iStartPos = 2; int iEndPos = sData.IndexOf(" ", iStartPos); int iLength = iEndPos - iStartPos; if (iLength == 0) { CustomAssert.Fail("Unparseable SELECT response"); } string sValue = sData.Substring(iStartPos, iLength); return(Convert.ToInt32(sValue)); }
public void ListItemReference_Set() { var xml = Xml( "<Foo $x>", "<One> <Value>One</Value> </One>", "<List>", "<Foo> <Value>Two</Value> </Foo>", "</List>", "</Foo>" ); var foo = Create <IFoo>(xml); foo.List[0] = foo.One; CustomAssert.AreXmlEquivalent(Xml( "<Foo $x>", "<One x:id='1'> <Value>One</Value> </One>", "<List>", "<Foo x:ref='1'/>", "</List>", "</Foo>" ), xml); }
public void TestHierarchyDelimiterListResponse() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); Settings settings = _settings; settings.IMAPHierarchyDelimiter = "\\"; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string folderName = "Test\\Test"; var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); CustomAssert.IsTrue(oSimulator.CreateFolder(folderName)); string listResponse = oSimulator.List(); CustomAssert.IsTrue(listResponse.Contains("\"Test\\Test\"")); CustomAssert.IsTrue(listResponse.Contains("\"Test\"")); oSimulator.Disconnect(); }
public void whole_table_is_aligned_to_Right_without_explicit_columns() { DataGrid dataGrid = new DataGrid("This is a cell alignment test"); dataGrid.DisplayColumnHeaders = false; dataGrid.CellHorizontalAlignment = HorizontalAlignment.Right; dataGrid.Rows.Add("0,0", "0,1", "0,2"); dataGrid.Rows.Add("1,0", "1,1", "1,2"); dataGrid.Rows.Add("2,0", "2,1", "2,2"); string expected = @"+-------------------------------+ | This is a cell alignment test | +----------+----------+---------+ | 0,0 | 0,1 | 0,2 | | 1,0 | 1,1 | 1,2 | | 2,0 | 2,1 | 2,2 | +----------+----------+---------+ "; CustomAssert.TableRender(dataGrid, expected); }
public void TestSaveMessageInPublicIMAPFolder() { Settings settings = SingletonProvider <TestSetup> .Instance.GetApp().Settings; IMAPFolders publicFolders = settings.PublicFolders; IMAPFolder testFolder = publicFolders.Add("TestFolder"); testFolder.Save(); // Send a message to the account. hMailServer.Message oMessage = testFolder.Messages.Add(); CustomAssert.AreEqual(0, oMessage.State); oMessage.Body = "Välkommen till verkligheten"; oMessage.Subject = "Hej"; oMessage.Save(); CustomAssert.AreEqual(2, oMessage.State); CustomAssert.IsTrue(oMessage.Filename.Contains(settings.PublicFolderDiskName)); CustomAssert.IsFalse(oMessage.Filename.Contains(_domain.Name)); }
public void Create() { var xml = Xml("<X/>"); var cursor = Cursor(xml, "A[B='b']/C[D[E][F='f'] and G]/@H", CursorFlags.Multiple); Assert.False(cursor.MoveNext()); cursor.Create(TypeA.ClrType); cursor.Value = "h"; CustomAssert.AreXmlEquivalent(string.Concat ( "<X>", "<A>", "<C H='h'>", "<D> <E/> <F>f</F> </D>", "<G/>", "</C>", "<B>b</B>", "</A>", "</X>" ), xml); }
public void TestGlobalMaxMessageSizeLimitEnabled() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test", 0); var message = new StringBuilder(); // ~2 kb string for (int i = 0; i < 25; i++) { message.AppendLine( "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); } _settings.MaxMessageSize = 1; var imapSim = new IMAPClientSimulator("*****@*****.**", "test", "INBOX"); string result = imapSim.SendSingleCommandWithLiteral("A01 APPEND INBOX {" + message.Length + "}", message.ToString()); imapSim.Logout(); CustomAssert.IsTrue(result.StartsWith("A01 NO Message size exceeds fixed maximum message size.")); }
public void Delete_Partial() { var xml = Xml ( "<Foo>", "<A>", "<B Id='1'> <C>value1</C> </B>", "<B Id='2'> <C>value2</C> </B>", "</A>", "</Foo>" ); Create <IFoo>(xml).A = null; CustomAssert.AreXmlEquivalent(string.Concat ( "<Foo>", "<A>", "<B Id='1'> <C>value1</C> </B>", "</A>", "</Foo>" ), xml); }
public void ReadShimWithoutExports() { var config = ReadJson(new TestFileReader()); var shim = new ShimEntry { For = "jquery-validate-unobtrusive", Dependencies = new List <RequireDependency> { new RequireDependency { Dependency = "jquery" }, new RequireDependency { Dependency = "jquery-validate" } }, }; var expected = ConfigurationCreators.CreateCollectionWithShims(shim); CustomAssert.JsonEquals(expected, config); }
public static IMAPFolder AssertFolderExists(IMAPFolders folders, string folderName) { int timeout = 100; while (timeout > 0) { try { return(folders.get_ItemByName(folderName)); } catch (Exception) { } timeout--; Thread.Sleep(100); } string error = "Folder could not be found " + folderName; CustomAssert.Fail(error); return(null); }
public void RetrieveSeason() { var chartKey = CreateTestChart(); var season = Client.Seasons.Create(chartKey); var partialSeason1 = Client.Seasons.CreatePartialSeason(season.Key); var partialSeason2 = Client.Seasons.CreatePartialSeason(season.Key); var retrievedSeason = Client.Events.Retrieve(season.Key); Assert.NotNull(retrievedSeason.Key); Assert.NotEqual(0, retrievedSeason.Id); Assert.True(retrievedSeason.IsTopLevelSeason); Assert.Null(retrievedSeason.TopLevelSeasonKey); Assert.Equal(new[] { partialSeason1.Key, partialSeason2.Key }, retrievedSeason.PartialSeasonKeys); Assert.Empty(retrievedSeason.Events); Assert.Equal(chartKey, season.ChartKey); Assert.Equal("INHERIT", season.TableBookingConfig.Mode); Assert.True(season.SupportsBestAvailable); Assert.Null(season.ForSaleConfig); CustomAssert.CloseTo(DateTimeOffset.Now, season.CreatedOn.Value); Assert.Null(season.UpdatedOn); }
public void TestSMTPAuthExternalToExternal() { SecurityRange range = SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthExternalToExternal = true; range.Save(); var oSMTP = new SMTPClientSimulator(); string result; CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); CustomAssert.IsTrue(result.Contains("SMTP authentication is required.")); range.RequireSMTPAuthExternalToExternal = false; range.AllowDeliveryFromRemoteToRemote = false; range.Save(); CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); CustomAssert.IsTrue(result.Contains("550 Delivery is not allowed to this address.")); }
public async Task Prune_Removes_Closed_Entries_Only() { // arrange const string staleKey = "foo"; var(staleHandle, staleWriter) = CreateAndRegisterWebSocketWriterMock(staleKey); staleWriter.SetupGet(w => w.IsClosed).Returns(true); const string activeKey = "bar"; var(activeHandle, activeWriter) = CreateAndRegisterWebSocketWriterMock(activeKey); activeWriter.SetupGet(w => w.IsClosed).Returns(false); // act var result = this.sut.Prune(); // assert var prunedKey = Assert.Single(result); Assert.Equal(staleKey, prunedKey); await CustomAssert.WriterIsNotRegistered(staleHandle); await CustomAssert.WriterIsRegistered(activeHandle, activeWriter); }