1. Christian Specht
  2. MissileSharp

Source

MissileSharp / src / MissileSharp.Tests / Launcher / MainWindowViewModelTests.cs

Christian Specht 467bed4 


Christian Specht 444d0a5 
Christian Specht 467bed4 
Christian Specht 8ba437a 






Christian Specht d160a51 
Christian Specht 092b6f8 
Christian Specht 467bed4 
Christian Specht 8ba437a 


Christian Specht 467bed4 
Christian Specht 092b6f8 
Christian Specht 6ed142c 
Christian Specht d160a51 
Christian Specht 467bed4 

Christian Specht d160a51 
Christian Specht 3c0829a 


Christian Specht 8b5c0e7 
Christian Specht 8ba437a 
Christian Specht 6ed142c 
Christian Specht 8b5c0e7 
Christian Specht 6ed142c 
Christian Specht 8b5c0e7 
Christian Specht 092b6f8 

Christian Specht 8b5c0e7 

Christian Specht 6ed142c 

Christian Specht 092b6f8 
Christian Specht 6ed142c 



Christian Specht 092b6f8 
Christian Specht 6ed142c 



Christian Specht d160a51 
Christian Specht 6ed142c 


Christian Specht 8ba437a 


Christian Specht 467bed4 



Christian Specht d160a51 
Christian Specht 467bed4 




Christian Specht 3c0829a 








Christian Specht 467bed4 
Christian Specht d160a51 
Christian Specht 467bed4 


Christian Specht 6ed142c 
Christian Specht 467bed4 
Christian Specht 6ed142c 

Christian Specht 444d0a5 
Christian Specht d160a51 
Christian Specht 444d0a5 
Christian Specht 8ba437a 
using System;
using System.Collections.Generic;
using MissileSharp.Launcher.Services;
using MissileSharp.Launcher.ViewModels;
using Moq;
using NUnit.Framework;

namespace MissileSharp.Tests.Launcher
{
    [TestFixture]
    public class MainWindowViewModelTests
    {
        private Mock<IShutdownService> shutdownservice;
        private Mock<ICommandCenterService> commandcenterservice;
        private Mock<ICommandCenter> commandcenter;
        
        [SetUp]
        public void Setup()
        {
            this.commandcenterservice = new Mock<ICommandCenterService>();            

            this.shutdownservice = new Mock<IShutdownService>();

            this.commandcenter = new Mock<ICommandCenter>();
            this.commandcenter.Setup(mock => mock.LoadCommandSets(It.IsAny<string[]>())).Returns(true);
            var list = new List<string>();
            list.Add("test");
            this.commandcenter.Setup(mock => mock.GetLoadedCommandSetNames()).Returns(list);
        }

        public MainWindowViewModel SetupViewModel(ICommandCenterService commandCenterService = null, IConfigService configService = null, IMessageService messageService = null, IShutdownService shutdownService = null)
        {
            if (commandCenterService == null)
            {
                this.commandcenterservice.Setup(stub => stub.GetCommandCenter()).Returns(this.commandcenter.Object);
                commandCenterService = this.commandcenterservice.Object;
            }

            if (configService == null)
            {
                configService = new Mock<IConfigService>().Object;
            }

            if (messageService == null)
            {
                messageService = new Mock<IMessageService>().Object;
            }

            if (shutdownService == null)
            {
                shutdownService = this.shutdownservice.Object;
            }

            return new MainWindowViewModel(commandCenterService, configService, messageService, shutdownService);
        }

        [Test]
        public void Initialize_IsExecuted_DoesntShutdown()
        {
            // test that the viewmodel initializes correctly with all the mocked/stubbed stuff, without throwing an exception or shutting down
            var viewmodel = SetupViewModel();
            this.shutdownservice.Verify(mock => mock.Shutdown(), Times.Never());
        }

        [Test]
        public void Initialize_LoadCommandSetsThrows_AppShutsDown()
        {
            this.commandcenter.Setup(stub => stub.LoadCommandSets(It.IsAny<string[]>())).Throws<NotImplementedException>();
            var viewmodel = SetupViewModel();
            this.shutdownservice.Verify(mock => mock.Shutdown());
        }

        [Test]
        public void Initialize_GetLoadedCommandSetsIsEmpty_AppShutsDown()
        {
            this.commandcenter.Setup(stub => stub.GetLoadedCommandSetNames()).Returns(new List<string>());
            var viewmodel = SetupViewModel();
            this.shutdownservice.Verify(mock => mock.Shutdown());
        }

        [Test]
        public void FireCommand_IsExecuted_RunCommandSetIsCalled()
        {           
            var viewmodel = SetupViewModel();
            viewmodel.FireCommand.Execute("test");

            this.commandcenter.Verify(mock => mock.RunCommandSet("test"));
        }
    }
}