Exemplo n.º 1
0
        /// <summary>
        /// Test to make sure that we can add emails to the banned emails table
        /// </summary>
        private void TestAddingSampleDataToBannedEmails(string email, bool complaintBanned, bool signinBanned)
        {
            // Create the context for the object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            DnaMockery.SetDefaultDiagnostics(context);

            // Mock up the request params for the test
            Stub.On(context).Method("DoesParamExist").With("show", "Do we have the number of items to show?").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("skip", "Do we have the number of items to skip?").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("ViewAll", "Are we viewing all items?").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("ViewByLetter", "Are we wanting to search by letter?").Will(Return.Value(false));

            // Mock the action params
            Stub.On(context).Method("DoesParamExist").With("togglecomplaintban", "Are we toggling the complaint ban for an email").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("togglesigninban", "Are we toggling the signin ban for an email").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("remove", "Are we tring to remove an email").Will(Return.Value(false));

            // Mock the add params
            Stub.On(context).Method("DoesParamExist").With("AddEmail", "Are we tring to remove an email").Will(Return.Value(true));
            Stub.On(context).Method("GetParamStringOrEmpty").With("NewEmail", "Get the new email address to add").Will(Return.Value(email));
            Stub.On(context).Method("GetParamStringOrEmpty").With("NewComplaintBanned", "Get the complaint banned setting").Will(Return.Value(complaintBanned ? "on" : ""));
            Stub.On(context).Method("GetParamStringOrEmpty").With("NewSignInBanned", "Get the signin banned setting").Will(Return.Value(signinBanned ? "on" : ""));
            Stub.On(context).Method("UrlEscape").WithAnyArguments().Will(Return.Value("Escaped EMail"));

            // Create the editor
            IUser mockedUser = DnaMockery.CurrentMockery.NewMock<IUser>();
            Stub.On(mockedUser).GetProperty("UserID").Will(Return.Value(1090558353));
            Stub.On(mockedUser).GetProperty("UserName").Will(Return.Value("username"));
            Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(mockedUser));

            // Now create banned email object and process the request
            BannedEmailsPageBuilder testBannedEmails = new BannedEmailsPageBuilder(context);
            testBannedEmails.ProcessRequest();

            // Get the resultant XML from the object
            System.Xml.XmlNode testXML = testBannedEmails.RootElement;

            // Check the search params
            Assert.AreEqual("0", testXML.SelectSingleNode("//BANNEDEMAILS/SKIP").InnerText, "We should have a default value of 0 for the skip value");
            Assert.AreEqual("20", testXML.SelectSingleNode("//BANNEDEMAILS/SHOW").InnerText, "We should have a default value of 20 for the show value");
            Assert.AreEqual("", testXML.SelectSingleNode("//BANNEDEMAILS/SEARCHLETTER").InnerText, "We should have a default value of empty for the search letter value");
            Assert.AreEqual("0", testXML.SelectSingleNode("//BANNEDEMAILS/SEARCHTYPE").InnerText, "The search type value should be 0!");

            // Now check to make sure that the email was actually added
            Assert.IsNotNull(testXML.SelectSingleNode("//BANNEDEMAILS/BANNEDEMAILLIST/BANNEDEMAIL[EMAIL = '" + email + "']"), "Failed to find the email we just added");
        }
Exemplo n.º 2
0
    /// <summary>
    /// Adds all the banned emails to the table for display
    /// </summary>
    private void DisplayBannedEmails()
    {
        // Check to see if we're a super user. If not, hide the UI
        if (!_basePage.ViewingUser.IsSuperUser)
        {
            // Remove the UI
            foreach (Control control in form1.Controls)
            {
                control.Visible = false;
            }

            // Show the super user only message
            DisplayUserMessage("This is a superuser only page!", false);
            return;
        }

        // Get the emails from the database
        BannedEmailsPageBuilder bannedEmails = new BannedEmailsPageBuilder(_basePage);

        // Get the emails based on the search term
        if (_letter.CompareTo("All") == 0)
        {
            _letter = "";
        }
        bool showSignInBannedOnly = rbFilterSignIn.Checked;
        bool showComplaintBannedOnly = rbFilterComplaint.Checked;
        bool showAll = rbFilterAll.Checked;
        ArrayList bannedEmailArray = bannedEmails.GetBannedEmails(_skip,_show,_searchType,_letter,showSignInBannedOnly,showComplaintBannedOnly,showAll);
        tblBannedEmails.Rows.Clear();

        // Create the table header
        TableHeaderRow headerRow = new TableHeaderRow();
        TableCell emailCell = new TableCell();
        string orderedBy = "by most recent";
        if (_searchType == 1)
        {
            if (_letter == "")
            {
                orderedBy = "alphabetically";
            }
            else
            {
                orderedBy = "by the letter " + _letter.ToUpper();
            }
        }
        emailCell.Text = "Email address ordered " + orderedBy;
        emailCell.Font.Bold = true;
        headerRow.Cells.Add(emailCell);

        TableCell signInBan = new TableCell();
        signInBan.Text = "Sign In Banned";
        signInBan.Font.Bold = true;
        headerRow.Controls.Add(signInBan);

        TableCell complaintBan = new TableCell();
        complaintBan.Text = "Complaint Banned";
        complaintBan.Font.Bold = true;
        headerRow.Controls.Add(complaintBan);

        TableCell dateCell = new TableCell();
        dateCell.Text = "Date Banned";
        dateCell.Font.Bold = true;
        headerRow.Cells.Add(dateCell);

        TableCell addedByCell = new TableCell();
        addedByCell.Text = "Added By";
        addedByCell.Font.Bold = true;
        headerRow.Cells.Add(addedByCell);
        tblBannedEmails.Rows.Add(headerRow);

        // Add a row to the table for each item
        int i = 0;
        foreach (BannedEmailDetails email in bannedEmailArray)
        {
            // Add the item
            CreateTableEntryForEmailItem(email,i++);
        }

        // Set the total matches for this search
        lbTotalResults.Text = bannedEmails.TotalEmails.ToString();

        // Update the paging controls
        int currentPage = ((_skip + 1) / _show) + 1;
        int totalPages = 1;
        if (bannedEmails.TotalEmails > 0)
        {
            totalPages = (int)Math.Ceiling((double)bannedEmails.TotalEmails / (double)_show);
        }

        btnFirst.Enabled = (_skip > 0);
        btnPrevious.Enabled = (_skip > 0);
        btnNext.Enabled = ((_skip + _show) < bannedEmails.TotalEmails);
        btnLast.Enabled = ((_skip + _show) < bannedEmails.TotalEmails);
        lbPage.Text = "Page " + currentPage + " of " + totalPages;

        btnFirst2.Enabled = (_skip > 0);
        btnPrevious2.Enabled = (_skip > 0);
        btnNext2.Enabled = ((_skip + _show) < bannedEmails.TotalEmails);
        btnLast2.Enabled = ((_skip + _show) < bannedEmails.TotalEmails);
        lbPage2.Text = "Page " + currentPage + " of " + totalPages;
    }
Exemplo n.º 3
0
        public void TestGetBannedEmailsWithSeachByLetter()
        {
            // Create the context for the object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            DnaMockery.SetDefaultDiagnostics(context);

            // Mock up the request params for the test
            Stub.On(context).Method("DoesParamExist").With("show", "Do we have the number of items to show?").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("skip", "Do we have the number of items to skip?").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("ViewAll", "Are we viewing all items?").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("ViewByLetter", "Are we wanting to search by letter?").Will(Return.Value(true));
            Stub.On(context).Method("GetParamStringOrEmpty").With("ViewByLetter", "Get the search letter").Will(Return.Value("g"));
            Stub.On(context).Method("UrlEscape").WithAnyArguments().Will(Return.Value("Escaped EMail"));

            // Mock the action params
            Stub.On(context).Method("DoesParamExist").With("togglecomplaintban", "Are we toggling the complaint ban for an email").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("togglesigninban", "Are we toggling the signin ban for an email").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("remove", "Are we tring to remove an email").Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With("AddEmail", "Are we tring to remove an email").Will(Return.Value(false));

            // Now create banned email object and process the request
            BannedEmailsPageBuilder testBannedEmails = new BannedEmailsPageBuilder(context);
            testBannedEmails.ProcessRequest();

            // Get the resultant XML from the object
            System.Xml.XmlNode testXML = testBannedEmails.RootElement;

            Assert.AreEqual("0", testXML.SelectSingleNode("//BANNEDEMAILS/SKIP").InnerText, "We should have a default value of 0 for the skip value");
            Assert.AreEqual("20", testXML.SelectSingleNode("//BANNEDEMAILS/SHOW").InnerText, "We should have a default value of 20 for the show value");
            Assert.AreEqual("g", testXML.SelectSingleNode("//BANNEDEMAILS/SEARCHLETTER").InnerText, "We should have the letter 'g' as the value");
            Assert.AreEqual("1", testXML.SelectSingleNode("//BANNEDEMAILS/SEARCHTYPE").InnerText, "The search type value should be 1!");
            Assert.AreEqual("1", testXML.SelectSingleNode("//BANNEDEMAILS/TOTALEMAILS").InnerText, "We should have only one in the totals field");
        }