0

我如何测试我自己的 C# 程序以发送传真?

namespace FAX
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SendFax(textBox1.Text,openFileDialog1.FileName,textBox2.Text,textBox3.Text);


        }

        public void SendFax(string DocumentName, string FileName, string RecipientName, string FaxNumber)
        {
            if (FaxNumber != "")
            {
                int response = 0;
                FAXCOMLib.FaxServer faxServer = new FAXCOMLib.FaxServerClass();
                try
                {
                    faxServer.Connect("");
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
                FAXCOMLib.FaxDoc faxDoc = (FAXCOMLib.FaxDoc)faxServer.CreateDocument(FileName);
                try
                {
                    faxDoc.FaxNumber = FaxNumber;
                    faxDoc.RecipientName = RecipientName;
                    faxDoc.DisplayName = DocumentName;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
                try
                {
                    response = faxDoc.Send();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
                try
                {
                    faxServer.Disconnect();
                }
                catch (Exception Ex)
                {

                    MessageBox.Show(Ex.Message);
                }

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {   openFileDialog1.FileName = "";
            openFileDialog1.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog1.Filter = " doc file|*.doc";
            openFileDialog1.ShowDialog();
           string Filepath = "";
            Filepath = openFileDialog1.FileName;


        }
    }
}
4

2 回答 2

4

附加传真(真实设备)并在其上切换。

  1. 运行您的程序并发送传真。(确保您能够获得有关传真递送的信息)

  2. 与 (1) 相同的情况,但在传输过程中断开电缆(检查您的程序如何容错)

  3. 与 (1) 相同的场景,但传真已关闭。(检查连接超时和所有这些东西)

在此测试之后,您已经处于良好状态。

问候。

于 2011-07-10T06:52:27.543 回答
0

如果您正在考虑单元测试之类的东西,我建议您声明一个接口 IFax(可能使用名为 SendFax 的方法)并将 SendFax 放入实现该模块的模块中。您的传真类可以在没有类“Form1”的情况下使用真实设备进行测试(如果您想在另一个级别进行测试,您可以将 FAXCOMLIB 封装在接口后面,然后同样适用)。要测试 GUI 行为,您可以通过始终抛出错误的类 'ErrorThrowingTestFax' 类或从不做任何事情或您想要的任何事情的 DoNothingTestFax 类来实现 IFax。

于 2011-07-10T06:59:19.750 回答