Esempio n. 1
0
 public void GuessesTheImageTest_GuessesTheImages_getTasks_nullException()
 {
     try
     {
         rep.GetTasks(null);
     }
     catch (Exception e)
     {
         Assert.AreEqual("Value cannot be null.", e.Message, string.Format("result != expected"));
     }
 }
Esempio n. 2
0
        public GuessesTheImageToReturn GetTask(string category, string indexes)
        {
            List <GuessesTheImageToReturn> tasks;
            var ParsedIndexes = new List <int>();
            var rand          = new System.Random();

            if (!String.IsNullOrEmpty(indexes))
            {
                foreach (var ch in indexes.Split(','))
                {
                    if (int.TryParse(ch, out int i))
                    {
                        ParsedIndexes.Add(i);
                    }
                }
            }

            if (String.IsNullOrEmpty(category))
            {
                throw new Exception("Invalid model");
            }

            if (!ParsedIndexes.IsCorrect())
            {
                throw new Exception("End of tasks");
            }

            tasks = rep.GetTasks(category, ParsedIndexes).ToList();

            if (tasks == null || tasks.Count() < 1)
            {
                throw new Exception("Invalid model");
            }

            var index = rand.Next(0, tasks.Count());

            return(tasks.ElementAt(index));
        }