using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;

namespace DataImport.Tests
{
    [TestClass]
    public class Tests
    {
        private string _jsonData;

        [TestInitialize]
        public void Setup()
        {
            _jsonData = "{\t\"activityTypes\": {\t\t\"featsOfStrength\": 0,\t\t\"avb\": 1,\t\t\"break\": 2,\t\t\"trivia\": 3,\t\t\"basicMath\": 4\t},\t\"activities\": [\t\t{\t\t\t\"activityType\": 1,\t\t\t\"text\": \"Gif\",\t\t\t\"text2\": \"Jif\",\t\t\t\"followup\": \"Sorry, you're all wrong!\"\t\t},\t\t{\t\t\t\"activityType\": 3,\t\t\t\"text\": \"Who is the author of the Game of Thrones series?\",\t\t\t\"text2\": \"\",\t\t\t\"followup\": \"George R. R. Martin\"\t\t},\t\t{\t\t\t\"activityType\": 0,\t\t\t\"text\": \"Lick your elbow\"\t\t\t\"text2\": \"\",\t\t\t\"followup\": \"\"\t\t},\t\t{\t\t\t\"activityType\": 2,\t\t\t\"text\": \"Have a nice stretch\"\t\t\t\"text2\": \"\",\t\t\t\"followup\": \"\"\t\t},\t\t{\t\t\t\"activityType\": 4,\t\t\t\"text\": \"What is 42 - 3?\",\t\t\t\"text2\": \"\",\t\t\t\"followup\": \"39\"\t\t},\t]}";
        }

        [TestMethod]
        public void CanLoadFile()
        {
            var file = JsonImport.Import<ContentFile>(_jsonData);     

            Assert.IsNotNull(file);
            Assert.AreEqual(5, file.activities.Count);
        }

        [TestMethod]
        public void GetsRandomNextActivity()
        {           
            // run this test a crap ton of times to mitigate the fact that results are random/inconsistent
            for (int j = 0; j < 100; j++)
            {
                var file = JsonImport.Import<ContentFile>(_jsonData);
                var activities = new HashSet<Activity>();

                for (int i = 0; i < file.activities.Count; i++)
                {
                    var a = file.GetNextActivity();
                    if (activities.Contains(a))
                        Assert.Fail("Got the same activity more than once");
                    activities.Add(a);
                }
            }
        }

        [TestMethod]
        public void GetsRandomNextActivity_AndRefreshesAfterUsingEverything()
        {
            var file = JsonImport.Import<ContentFile>(_jsonData);           

            // get way more activities than there actually are in the file to verify it doesn't bomb when it runs out
            for (int i = 0; i < 10 * file.activities.Count; i++)
            {
                var a = file.GetNextActivity();

                Assert.IsNotNull(a);
            }
        }
    }
}
