﻿using System.Windows.Input;
using FinancialExchangeConverter.Models;
using FinancialExchangeConverter.ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FinancialExchangeConverter.Tests
{
    /// <summary>
    /// Unit test class for the <see cref="MainViewModel"/> class.
    /// </summary>
    [TestClass]
    public class MainViewModelTests
    {
        /// <summary>
        /// Unit tests to check whether the ConvertCommand command is setting the status
        /// bar text to the desired strings when receiving improper input from the UI.
        /// </summary>
        [TestMethod]
        public void ConvertCommand_ShouldReturnStatusStrings_WhenImproperUIValues()
        {
            MainViewModel mvm = new MainViewModel(new ConvertingService(), new InputSettingsService("..\\..\\..\\FinancialExchangeConverter\\Input formats"));
            ICommand convertCommand = mvm.ConvertCommand;

            // Nothing has been selected in the GUI.
            mvm.SelectedInputFormat = null;
            mvm.SelectedOutputFormat = null;
            mvm.InputFileName = null;
            convertCommand.Execute(null);
            Assert.AreEqual("Wrong output format and input format. Choose a file.", mvm.StatusBarText, "Nothing selected test.");

            // Input format has been selected.
            mvm.SelectedInputFormat = "Gjensidige";
            mvm.SelectedOutputFormat = null;
            mvm.InputFileName = null;
            convertCommand.Execute(null);
            Assert.AreEqual("Wrong output format. Choose a file.", mvm.StatusBarText, "Input format selected test.");

            // Output format has been selected.
            mvm.SelectedInputFormat = null;
            mvm.SelectedOutputFormat = "csv";
            mvm.InputFileName = null;
            convertCommand.Execute(null);
            Assert.AreEqual("Wrong input format. Choose a file.", mvm.StatusBarText, "Output format selected test.");

            // File has been selected.
            mvm.SelectedInputFormat = null;
            mvm.SelectedOutputFormat = null;
            mvm.InputFileName = "test.csv";
            convertCommand.Execute(null);
            Assert.AreEqual("Wrong output format and input format.", mvm.StatusBarText, "File selected test.");

            // Input and output format has been selected.
            mvm.SelectedInputFormat = "Gjensidige";
            mvm.SelectedOutputFormat = "csv";
            mvm.InputFileName = null;
            convertCommand.Execute(null);
            Assert.AreEqual(" Choose a file.", mvm.StatusBarText, "Input format and output format selected test.");

            // Input format and file has been selected.
            mvm.SelectedInputFormat = "Gjensidige";
            mvm.SelectedOutputFormat = null;
            mvm.InputFileName = "test.csv";
            convertCommand.Execute(null);
            Assert.AreEqual("Wrong output format.", mvm.StatusBarText, "Input format and file selected test.");

            // Output format and file has been selected.
            mvm.SelectedInputFormat = null;
            mvm.SelectedOutputFormat = "csv";
            mvm.InputFileName = "test.csv";
            convertCommand.Execute(null);
            Assert.AreEqual("Wrong input format.", mvm.StatusBarText, "File selected test.");
        }
    }
}
