如何测试C#传真程序?

发布于 2024-11-19 10:13:39 字数 2274 浏览 6 评论 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;


        }
    }
}

How do i test my own C# program in order to send a fax?

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;


        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁对谁错谁最难过 2024-11-26 10:13:39

连接传真机(真实设备)并打开它。

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

  2. 与 (1) 相同的场景,但在传输过程中断开电缆(检查您的程序的容错能力)

  3. 与 (1) 相同的情况,但传真已关闭。 (检查连接超时和所有其他内容)

经过此测试,您已经处于良好状态。

问候。

Attach the fax (real device) and swithc on it.

  1. Run your program and send fax. (ensure you're able to get information about fax delivery)

  2. The same scenario like (1) but in the middle of transmition detach the cabble (check how your program is fault tollerant)

  3. The same scenario like (1) but with fax switched OFF. (check on connection timeout and all that stuff)

After this tests you're already at good point.

Regards.

晒暮凉 2024-11-26 10:13:39

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

If you are thinking of something like Unit Testing, I would suggest to declare an interface IFax (with a method called SendFax probably) and put SendFax into a module that implements this module. Your Fax-class can be tested without class 'Form1' then with the real device (If you want to test at another level, you might encapsulate the FAXCOMLIB behind an interface and the same applies then). To test the GUI behavior, you can implement IFax by a class 'ErrorThrowingTestFax' class that always throws an error or a DoNothingTestFax that never does anything or whatever you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文