///[TestMethod]
        /////This doesn't work now as settings are taken from web.config in web startup
        public void SendEmail()
        {
            bool success;

            try
            {
                EmailAlarm alarm = new EmailAlarm();
                alarm.emailAddress = "*****@*****.**";
                alarm.SendAlarmEmail();
                success = true;
            }
            catch (Exception ex)
            {
                success = false;
            }

            Assert.IsTrue(success);
        }
示例#2
0
文件: Alarms.cs 项目: Meowse/student1
    static void Main(string[] args)
    {
        RaiseAlarm notifier = null;
        EmailAlarm ea = null;
        PagerAlarm pa = null;
        PhoneAlarm ha = null;

        // Prompt the user for the type of alarm they will want to raise.
        Console.WriteLine ("Please choose a level of alarm notification for this evening.\n");
        Console.WriteLine ("   1. Not urgent (Email only)");
        Console.WriteLine ("   2. Semi-urgent (Email and Pager only)");
        Console.WriteLine ("   3. Extremely urgent (Email, Pager, and Phone)");
        Console.WriteLine ("   0. Abort notification setup.");
        Console.Write ("\nEnter your choice: ");
        string choice = Console.ReadLine();

        // Determine what choice the user made.
        switch (choice)
        {
            case "1":
                // Set up the delegate to just send an email.
                ea = new EmailAlarm();
                notifier = new RaiseAlarm(ea.SendEmail);
                break;

            case "2":
                // Set up the delegate to send email and page a number.
                ea = new EmailAlarm();
                pa = new PagerAlarm();
                notifier = new RaiseAlarm(pa.SignalPager);
                notifier += new RaiseAlarm(ea.SendEmail);
                break;

            case "3":
                // Set up the delegate to send email, send a page, and make a call.
                ea = new EmailAlarm();
                pa = new PagerAlarm();
                ha = new PhoneAlarm();
                notifier = new RaiseAlarm(ha.SignalPhone);
                notifier += new RaiseAlarm(pa.SignalPager);
                notifier += new RaiseAlarm(ea.SendEmail);
                break;

            case "0":
                // The user wishes to exit.
                Console.WriteLine ("\nAborting alarm initialization.");
                break;

            default:
                // The menu choice entered is not valid.
                Console.WriteLine ("\nYour choice of " + choice + " is not valid - ABORTING!");
                break;
        }

        // Check to see if the notifier delegate was created.
        if (notifier != null)
        {
            // Prompt for the text to send.
            Console.Write ("\nEnter the text you wish to send: ");
            string text = Console.ReadLine();

            // Notify the appropriate target.
            Console.Write("Please wait...");
            System.Threading.Thread.Sleep(5000);
            notifier(text);
        }

        Console.Write("\n\nPress <ENTER> to end: ");
        Console.ReadLine();
    }