﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyCLI.Core.Exceptions;

namespace MyCLI.Core.Test
{
    [TestClass]
    public class CLIManagerTest
    {
        [TestMethod]
        public void LoadArguments_InvalidArgTest()
        {
            string[] args = new string[] { "/l", "Test02" };

            ICLIManager mgr = new CLIManager();
            mgr.SetupArg(() => new CLIArgument("f", "firstname", "", true, true));

            MyAssert.Throws<InvalidArgumentException>(() => mgr.LoadArguments(args));
        }

        [TestMethod]
        public void LoadArguments_UnsuppliedRequiredArgTest()
        {
            string[] args = new string[] { "/l", "Test02" };

            ICLIManager mgr = new CLIManager();
            mgr.SetupArg(() => new CLIArgument("f", "firstname", "", true, true));
            mgr.SetupArg(() => new CLIArgument("l", "lastname", "", false, true));

            MyAssert.Throws<RequiredArgumentNotSuppliedException>(() => mgr.LoadArguments(args));
        }

        [TestMethod]
        public void LoadArguments_UnsuppliedArgValueTest()
        {
            string[] args = new string[] { "/f", "/l", "Test02" };

            ICLIManager mgr = new CLIManager();
            mgr.SetupArg(() => new CLIArgument("f", "firstname", "", true, true));
            mgr.SetupArg(() => new CLIArgument("l", "lastname", "", false, true));

            MyAssert.Throws<ArgumentValueNotSuppliedException>(() => mgr.LoadArguments(args));
        }

        [TestMethod]
        public void LoadArguments_DuplicateArgsTest()
        {
            string[] args = new string[] { "/f", "Test", "/f", "Test02" };

            ICLIManager mgr = new CLIManager();
            mgr.SetupArg(() => new CLIArgument("f", "firstname", "", true, true));
            mgr.SetupArg(() => new CLIArgument("l", "lastname", "", false, true));

            MyAssert.Throws<DuplicateArgumentsException>(() => mgr.LoadArguments(args));
        }
    }
}
