0

How to test Json with Xunit, I currently have a method that will read and collect .json information, I would like to do tests simulating any return, null and valid returns. I wanted to test this code:

public class BLLParametros
    {
        public static INFOParametros CarregarParametros()
        {
            INFOParametros parametros = new INFOParametros();
            string startupPath = Environment.CurrentDirectory;

            if (System.IO.File.Exists(startupPath + @"\parametros.json"))
            {
                // deserialize JSON directly from a file
                using (StreamReader file = File.OpenText(startupPath + @"\parametros.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    parametros = (INFOParametros)serializer.Deserialize(file, typeof(INFOParametros));
                }
            }
            else
            {
                return null;
            }

            return parametros;
        }
    }

0 Answers0