﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Basilisk.AI.DataContext;

namespace Basilisk.AI.Test.DataContext
{
    [TestClass]
    public class BasicDataContextTests
    {
        IDataContext dataContext;

        [TestMethod]
        public void Basic_data_context_stores_data_under_keys_accessed_by_indexer()
        {
            dataContext = new BasicDataContext();
            dataContext["some_key"] = 23;

            Assert.AreEqual(23, dataContext["some_key"]);

            dataContext["some_key"] = 45;

            Assert.AreNotEqual(23, dataContext["some_key"]);
        }

        [TestMethod]
        public void Basic_data_context_returns_null_if_no_key_found()
        {
            dataContext = new BasicDataContext();

            Assert.AreEqual(null, dataContext["some_key"]);
        }

        [TestMethod]
        public void Basic_data_context_clears_all_data_when_clear_called()
        {
            dataContext = new BasicDataContext();
            dataContext["key1"] = 2;
            dataContext["key2"] = 3;

            dataContext.Clear();

            Assert.AreEqual(null, dataContext["key1"]);
            Assert.AreEqual(null, dataContext["key2"]);
        }

        [TestMethod]
        public void Basic_data_context_clears_specified_keys()
        {
            dataContext = new BasicDataContext();
            dataContext["some_key"] = 45;

            dataContext.Remove("some_key");

            Assert.AreEqual(null, dataContext["some_key"]);
        }

        [TestMethod]
        public void Basic_data_context_clears_the_key_when_assigned_to_null()
        {
            dataContext = new BasicDataContext();
            dataContext["some_key"] = 45;

            dataContext["some_key"] = null;

            Assert.AreEqual(null, dataContext["some_key"]);
        }

        [TestMethod]
        public void Basic_data_context_doesnt_do_anything_when_setting_null_value_to_nonexistant_key()
        {
            dataContext = new BasicDataContext();
            dataContext["some_key"] = null;
        }
    }
}
