Example #1
0
        public void GivenMaxTargetNotCountTopped_WhenAddingAdditionalTarget_ThenItAppendsIt()
        {
            List <MonitoringTarget> updatedTargets        = null;
            MonitoringTarget        expectedFirstTarget   = _currentTargets.ElementAt(0);
            MonitoringTarget        notCurrentlyMonitored = _allTargets.Except(_currentTargets).FirstOrDefault();

            Mock <IEventAggregator>                eventManager = new Mock <IEventAggregator>();
            Mock <OnWatchdogTargetChangedEvent>    watchdogTargetChangedEvent = new Mock <OnWatchdogTargetChangedEvent>();
            Mock <OnMonitoringTargetsChangedEvent> monTargetChangedEvent      = new Mock <OnMonitoringTargetsChangedEvent>();

            monTargetChangedEvent.Setup(e => e.Publish(It.IsAny <List <MonitoringTarget> >())).Verifiable();
            monTargetChangedEvent.Setup(e => e.Publish(It.IsAny <List <MonitoringTarget> >())).Callback <List <MonitoringTarget> >(lru => updatedTargets = lru);
            ComputerMonitoringTestHelper.SetupEventAggMockBehaviour(eventManager, watchdogTargetChangedEvent.Object, monTargetChangedEvent.Object);
            Mock <IAppManager> appManagerMock = GivenAppManagerMock();

            HardwareSettingsViewModel hardwareSettingsVm = new HardwareSettingsViewModel(eventManager.Object, appManagerMock.Object, Mock.Of <IUiSettings>());

            hardwareSettingsVm.MaxAllowedMonTargets++;
            MonitoringTargetViewModel elementToAdd = hardwareSettingsVm.MonitoringOptionsCollection.SingleOrDefault(mo => mo.Type == notCurrentlyMonitored);

            elementToAdd.IsSelected = true;

            elementToAdd.PublishMonitoringOptionStatusCommand.Execute(new KeyValuePair <MonitoringTarget, bool>(elementToAdd.Type, elementToAdd.IsSelected));

            Assert.Equal(expectedFirstTarget, updatedTargets.FirstOrDefault());
            monTargetChangedEvent.Verify(e => e.Publish(It.IsAny <List <MonitoringTarget> >()), Times.Exactly(2));
        }
        public void GivenTargetRecipient_WhenSendingMessage_ThenItSendsToProperRecipient()
        {
            Mock <IMailClient> emailClient   = ComputerMonitoringTestHelper.ProvideSmtpClient();
            EmailSender        senderSubject = new EmailSender(emailClient.Object);

            senderSubject.SendEmailReport("TEST SUBJECT", "SOME MESSAGE");

            emailClient.Verify(e => e.Send(It.Is <MailMessage>(m => m.To.Any(t => t.Address.Equals("*****@*****.**")))), Times.Once);
        }
        private MainViewModel GivenMainViewModelTestSubject()
        {
            Mock <IAppManager>    appManager    = GivenAppManager();
            IEventAggregator      eventManager  = ComputerMonitoringTestHelper.GivenEventAggregator();
            IRepository           repository    = ComputerMonitoringTestHelper.GivenRepository();
            Mock <IDialogService> dialogService = ComputerMonitoringTestHelper.GivenDialogServiceMock();
            Mock <IUiSettings>    ui            = new Mock <IUiSettings>();
            MainViewModel         mainViewModel = new MainViewModel(dialogService.Object, appManager.Object, eventManager, repository);

            return(mainViewModel);
        }
Example #4
0
        public void GivenNonExistingDirectoryPath_WhenLogException_ThenItCreatesDirectory()
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            string directoryPath    = Path.Combine(currentDirectory, "Exception_Logs");

            ComputerMonitoringTestHelper.GivenDeletedDirectoryIfAlreadyExists(directoryPath);
            Reporter reporterSubject = new Reporter();

            reporterSubject.LogException(new Exception("ex"), "Exception_Logs");

            Assert.True(Directory.Exists(directoryPath));
        }
Example #5
0
        private HardwareSettingsViewModel GivenSettingsViewModelSubject()
        {
            Mock <IEventAggregator>                eventManager = new Mock <IEventAggregator>();
            Mock <OnWatchdogTargetChangedEvent>    watchdogTargetChangedEvent = new Mock <OnWatchdogTargetChangedEvent>();
            Mock <OnMonitoringTargetsChangedEvent> monTargetChangedEvent      = new Mock <OnMonitoringTargetsChangedEvent>();

            ComputerMonitoringTestHelper.SetupEventAggMockBehaviour(eventManager,
                                                                    watchdogTargetChangedEvent.Object,
                                                                    monTargetChangedEvent.Object);
            Mock <IAppManager> appManagerMock = GivenAppManagerMock();

            HardwareSettingsViewModel hardwareSettingsVm = new HardwareSettingsViewModel(eventManager.Object, appManagerMock.Object, Mock.Of <IUiSettings>());

            return(hardwareSettingsVm);
        }
        public void GivenOpenHardwareSettingsDialogCommand_WhenInvoked_ThenItInstantiateSettingsDialogProper()
        {
            Mock <IAppManager>    appManager    = GivenAppManager();
            IEventAggregator      eventManager  = ComputerMonitoringTestHelper.GivenEventAggregator();
            IRepository           repository    = ComputerMonitoringTestHelper.GivenRepository();
            Mock <IDialogService> dialogService = ComputerMonitoringTestHelper.GivenDialogServiceMock();

            dialogService.Setup(ds => ds.Instantiate(It.IsAny <HardwareSettingsViewModel>())).Verifiable();
            dialogService.Setup(ds => ds.ShowDialog(It.IsAny <HardwareSettingsViewModel>())).Verifiable();
            MainViewModel mainViewModel = new MainViewModel(dialogService.Object, appManager.Object, eventManager, repository);


            mainViewModel.OpenHardwareSettingsWindowCommand.Execute(null);

            dialogService.Verify(ds => ds.Instantiate(It.IsAny <HardwareSettingsViewModel>()), Times.Once);
            dialogService.Verify(ds => ds.ShowDialog(It.IsAny <HardwareSettingsViewModel>()), Times.Once);
        }
        public void GivenProcessVm_WhenInvokeChangeCommandWithNullProcess_ThenProperEventIsRaised()
        {
            const string     expectedNewProcessName = "NEW PROCESS";
            string           receivedNewProcessName = String.Empty;
            Reporter         reporter         = ComputerMonitoringTestHelper.GivenReporter();
            ProcessViewModel processVmSubject = new ProcessViewModel(true, "Test_Process");
            EventHandler     processNameChangedTestHandler = new EventHandler((s, a) => receivedNewProcessName = (s as ProcessViewModel).ProcessName);

            processVmSubject.OnProcessNameChangedEvent += processNameChangedTestHandler;
            processVmSubject.ProcessName = expectedNewProcessName;

            Assert.True(processVmSubject.ChangeWatchdogTargetCommand.CanExecute(null));
            processVmSubject.ChangeWatchdogTargetCommand.Execute(null);

            Assert.Equal(expectedNewProcessName, receivedNewProcessName);
            processVmSubject.OnProcessNameChangedEvent -= processNameChangedTestHandler;
        }
        public void GivenRunningApp_WhenKillAppCommand_ThenItKillsAppProper()
        {
            bool             appDisposed  = false;
            bool             windowClosed = false;
            Mock <IClosable> closable     = new Mock <IClosable>();

            closable.Setup(c => c.Close()).Callback(() => windowClosed = true);
            Mock <IAppManager> appManager = GivenAppManager();

            appManager.Setup(am => am.Dispose()).Callback(() => appDisposed = true);
            IEventAggregator      eventManager  = ComputerMonitoringTestHelper.GivenEventAggregator();
            IRepository           repository    = ComputerMonitoringTestHelper.GivenRepository();
            Mock <IDialogService> dialogService = ComputerMonitoringTestHelper.GivenDialogServiceMock();

            MainViewModel mainViewModel = new MainViewModel(dialogService.Object, appManager.Object, eventManager, repository);

            mainViewModel.KillAppCommand.Execute(closable.Object);

            Assert.True(windowClosed);
            Assert.True(appDisposed);
        }
        public void GivenOpenSettingsDialogCommand_WhenInvokedAndErrorOccurs_ThenItManageErrorProper()
        {
            Exception             managerError      = null;
            Exception             expectedException = new Exception("TEST");
            Mock <IAppManager>    appManager        = GivenAppManager();
            IEventAggregator      eventManager      = ComputerMonitoringTestHelper.GivenEventAggregator();
            IRepository           repository        = ComputerMonitoringTestHelper.GivenRepository();
            Mock <IDialogService> dialogService     = ComputerMonitoringTestHelper.GivenDialogServiceMock();

            dialogService.Setup(ds => ds.ShowException(It.IsAny <Exception>())).Callback <Exception>(e => managerError = e);
            dialogService.Setup(ds => ds.Instantiate(It.IsAny <HardwareSettingsViewModel>())).Verifiable();
            dialogService.Setup(ds => ds.ShowDialog(It.IsAny <HardwareSettingsViewModel>())).Throws(expectedException);

            MainViewModel mainViewModel = new MainViewModel(dialogService.Object, appManager.Object, eventManager, repository);

            mainViewModel.OpenHardwareSettingsWindowCommand.Execute(null);

            dialogService.Verify(ds => ds.Instantiate(It.IsAny <HardwareSettingsViewModel>()), Times.Once);
            dialogService.Verify(ds => ds.ShowDialog(It.IsAny <HardwareSettingsViewModel>()), Times.Once);
            Assert.Equal(expectedException.GetHashCode(), managerError.GetHashCode());
            Assert.Equal(expectedException.Message, managerError.Message);
        }
Example #10
0
        public void GivenCurrentlyMonitoredTargets_WhenRemoveSingleTarget_ThenItDoesNotPublishNewCollection()
        {
            List <MonitoringTarget>                updatedTargets             = null;
            Mock <IEventAggregator>                eventManager               = new Mock <IEventAggregator>();
            Mock <OnWatchdogTargetChangedEvent>    watchdogTargetChangedEvent = new Mock <OnWatchdogTargetChangedEvent>();
            Mock <OnMonitoringTargetsChangedEvent> monTargetChangedEvent      = new Mock <OnMonitoringTargetsChangedEvent>();

            monTargetChangedEvent.Setup(e => e.Publish(It.IsAny <List <MonitoringTarget> >())).Verifiable();
            monTargetChangedEvent.Setup(e => e.Publish(It.IsAny <List <MonitoringTarget> >())).Callback <List <MonitoringTarget> >(lru => updatedTargets = lru);
            ComputerMonitoringTestHelper.SetupEventAggMockBehaviour(eventManager, watchdogTargetChangedEvent.Object, monTargetChangedEvent.Object);
            Mock <IAppManager> appManagerMock = GivenAppManagerMock();

            HardwareSettingsViewModel hardwareSettingsVm = new HardwareSettingsViewModel(eventManager.Object, appManagerMock.Object, Mock.Of <IUiSettings>());

            updatedTargets = null;
            MonitoringTargetViewModel elementToUpdate = hardwareSettingsVm.MonitoringOptionsCollection.SingleOrDefault(mo => mo.Type == _currentTargets.LastOrDefault());

            elementToUpdate.IsSelected = false;

            elementToUpdate.PublishMonitoringOptionStatusCommand.Execute(new KeyValuePair <MonitoringTarget, bool>(elementToUpdate.Type, elementToUpdate.IsSelected));

            Assert.Null(updatedTargets);
            monTargetChangedEvent.Verify(e => e.Publish(It.IsAny <List <MonitoringTarget> >()), Times.Once);
        }