How do I do a test in C#?

You need to do a Visual Studio test on C# WinForm or WPF. Using a database. How to use tables in a database for tests. How to make it a backend or directly?

Code:

public void show(int n)
{
    int next = n+1;
    label1.Text = "Тест " +next;

    switch (answers[n])
    {
        case 0:
            buttonright.Checked = true;
            falseone.Checked = false;
            falseagain.Checked = false;
            break;
        case 1:
            buttonright.Checked = false;
            falseone.Checked = true;
            falseagain.Checked = false;
            break;
        case 2:
            buttonright.Checked = false;
            falseone.Checked = false;
            falseagain.Checked = true;
            break;
    }
    switch (n)
    {
        case 0:
            questone.Text = "первый вопрос";

            break;
        case 1:
            questone.Text = "второй вопрос";
            break;
        case 2:
            questone.Text = "третий вопрос";
            break;
    }
}
Author: insolor, 2020-06-15

3 answers

To begin with, if you are working with the database, you need to install the connector and drop it in the project folder. Then set the connection string. https://habr.com/ru/post/169929/ - read here, everything is very clear. Working with tables from the database takes place through the procedures for passing requests and writes the result to the variable. mysql_result.getString(0) - has a string type and can be assigned to objects (if we are talking about WPF or Windows Forms). I hope it was useful.

 1
Author: Sergination, 2020-06-15 13:10:49

As you have already answered above, you need to meet some conditions:

  1. Determine the storage method for the database of Questions:

    1.1. It can be like any DBMS (e. g. MySQL, PostgreSQL, MS SQL & etc.);

    1.2. This can be a regular local database (e.g.SQLite for example);

    1.3. These can be files with questions (e. g.JSON, txt & etc.).

  2. Decide on the way to get it data from the database of Questions:

    2.1. If the test subject is connected to the network, it means that to simplify the method of updating questions, you will need to store a database of Questions using the methods 1.1 or 1.3, but then it is necessary to organize network placement (i.e. to organize access to DBMS or to issue JSON file).

    2.2. If the test subject is not connected to the network, then you need to choose one of the options 1.2. or 1.3. , but then you will need to either attach a complete (exhaustive) list of questions to the Questions database, or automate the updating of questions when connecting to the network.

  3. You need to decide on the display technology that will be used for testing:

    3.1. WinForm - the best solution for organizing testing without a network connection (no need to pull up additional software for normal operation)

    3.2. Web - the best solution for organizing testing on the network (there is no need in principle to download or install anything - you only need a browser and does not depend on the operating system used).

    3.3. WPF - progressive (dubious expression), but it is necessary to provide for the possibility of pulling up additional software for the normal functioning of testing. 3.4. UWP - the same as the previous one.


  • To use the methods 1.1. or 1.2. I recommend looking towards EntityFramework Core using Dependency Injection;
  • If you decide to use JSON (method 1.3. ), then in c# there are a lot of examples of serialization and deserialization of objects on the fly.
  • When developing the interface in the following ways 3.* there will be no difficulties, because all the libraries are included in the standard delivery Visual Studio 2019 Community edition
  • When developing the method 3.2. I recommend that you first master AspNetCore. The ideal solution when choosing from the options is 3.2. + 1.1 - and you will gain experience, and testing will be carried out from any device (with the condition of using adaptive site design) connected to the network.

From personal experience:

  • (Not obvious)

    1. You must also specify the maximum length of the question (string.Length) when designing the interface. start from this length, so that long questions do not climb out of the boundaries of the forms.
    2. Correct answers to questions should be marked with the bool property.
    3. When using the Web technology for testing, the property with the correct answer should never be passed to View, since it will be possible to track it . Validation of the response should be performed on the side of the controller by Submit.
  • (Obvious)

    1. You must provide the following fields Question category and The cost of the question for the subsequent possible scaling of the application.
    2. For flow testing (all questions are output one by one), provide for the output of questions in random order to improve the quality of testing.
    3. For the same reasons, it is necessary to provide for the output of answers to questions in random order.
  • (The easiest way) I did not recommended.

    Use a ready-made solution - there is a beautiful instance of Moodle. In Google, it is searched for by the first links.

 1
Author: Рустам Алиев, 2020-06-24 08:17:46

Fixed the test by changing the values of the checkbox, and the questions themselves, the code of the sample questions and answers

//Вопрос
switch (n)
{
    case 0:
        questone.Text = "Персональный компьютер состоит из:";

        break;
    case 1:
        questone.Text = "Разрядность микропроцессора — это:";
        break;
    case 2:
        questone.Text = "Постоянная память предназначена для";
        break;
}
//Первые ответы
switch (n)
{
    case 0:
        checkboxone.Text = "системного блока";
        break;
    case 1:
        checkboxtwo.Text = "телефона";
        break;
    case 2:
        checkboxtrihd.Text = "плеера";
        break;
}
//Второй ответ
if (n==1)
{
    checkboxone.Text = "наибольшая единица информации";
    checkboxtwo.Text = "количество битов, которое воспринимается микропроцессором как единое целое";
    checkboxtrihd.Text = "наименьшая единица информации";
}
 0
Author: Freshmathick, 2020-06-24 08:13:37