samedi 30 janvier 2016

How to write unit test for a method without input and output?

My project is a bot telegram.I have a class called Mainclass.I want to test a method of it(SubmitNewsGetNews).This method has no input and output.This method check message received from user and send suitable response.This is my defenition of class and method.

 public class MainClass
{
    enum state : int { _firstState = 0, _submitNewsGetType = 1, _submitNewsGetNews = 11, _reservationGym = 2, _reservationGymGetSans = 22, _pollingForFood = 3, _appointment = 4, _cancelingReservation = 5, _cancelingAppointment = 6, Registeration = 7 };
    public TelegramBot bot;
    private  int stateBot;
    public Message sendMessage;
    private  string tempString;
    public  Message message;
    private  MessageTarget target;
    public void SubmitNewsGetType()
    {

        if (message.Text.Contains("/submitnews"))
        {
           sendMessage = bot.SendMessage(target, "Please select a type news: \n/Elmi\n/Farhangi\n/Honari\n/Amoozeshi\n/Varzeshi\n\n/Return");
        }
        else if (message.Text.Contains("/Elmi") || message.Text.Contains("/Farhangi") || message.Text.Contains("/Honari") || message.Text.Contains("/Amoozeshi")
            || message.Text.Contains("/Varzeshi"))
        {
           sendMessage = bot.SendMessage(target, "Please enter your news: \n\n/Return");

            stateBot = (int)state._submitNewsGetNews;

            tempString = message.Text;

        }
        else
        {
            bot.SendMessage(target, "Non definded! Please select a type news: \n/Elmi\n/Farhangi\n/Honari\n/Amoozeshi\n/Varzeshi\n\n/Return");
        }

    }

And this is my unit test.My problem is I can't initialized Message type.

[TestMethod]
    public void SubmitNewsGetNews_Test()
    {
        MainClass instance = new MainClass();
        Message mess_output;
        //How to set value for a Message type??
        //This line get error
        Message mess_input="/submitnews"
        string expected="Please select a type news: \n/Elmi\n/Farhangi\n/Honari\n/Amoozeshi\n/Varzeshi\n\n/Return";
        if (mess_input is "/submitnews")
        {
            a.SubmitNewsGetNews();
            mess_output= a.sendMessage;
            Assert.AreEqual(mess_output.Text,expected);
        } 
        else if (mess_input is "/elmi" or "/farhangi" or ...)
    else if ....
    }

Aucun commentaire:

Enregistrer un commentaire