Exemple #1
0
        public void WhenExecute_WithMailServerAndRequiredFields_ShouldSetMailConfigFile()
        {
            // arrange
            var errorExiterMock = new Mock <IErrorExiter>();

            // act
            var clientSettingsManager = new ClientSettingsManager(new[]
            {
                $"--{Argument.ConfigFileFolder}=.",
                $"--{Argument.MailServer}=mailserver",
                $"--{Argument.UserName}=Adrie",
                $"--{Argument.Password}=geheim",
                $"--{Argument.Verbose}=verbose"
            }, errorExiterMock.Object);

            // assert
            errorExiterMock.Verify(x => x.Exit(It.IsAny <int>()), Times.Never);

            clientSettingsManager.MailServer.Should().Be("mailserver");
            clientSettingsManager.Server.Should().BeNullOrWhiteSpace();

            clientSettingsManager.UserName.Should().Be(@"Adrie");
            clientSettingsManager.Password.Should().Be(@"geheim");

            clientSettingsManager.ConfigFolder.Should().Be(@".");
            clientSettingsManager.ConfigFileName.Should().Be(@"MailClientSettings.json");
        }
Exemple #2
0
        public void WhenReadMailConfig_ShouldGetMailAccounts()
        {
            // arrange
            var errorExiterMock       = new Mock <IErrorExiter>();
            var clientSettingsManager = new ClientSettingsManager(new[] { $"--{Argument.ConfigFileFolder}=.", $"--{Argument.MailServer}=mail.konfidence.nl", $"--{Argument.UserName}=Adrie", $"--{Argument.Password}=geheim" }, errorExiterMock.Object);

            clientSettingsManager.Execute();

            clientSettingsManager = new ClientSettingsManager(new[] { $"--{Argument.ConfigFileFolder}=.", $"--{Argument.MailServer}=mail.konfidence.nl", $"--{Argument.UserName}=A3", $"--{Argument.Password}=geheim" }, errorExiterMock.Object);

            // act
            clientSettingsManager.Execute();
            var mailConfig = ReadMailConfig();

            // assert
            errorExiterMock.Verify(x => x.Exit(It.IsAny <int>()), Times.Never);

            mailConfig.Accounts.Should().HaveCountGreaterOrEqualTo(2);
            var account1 = mailConfig.Accounts.FirstOrDefault(x => x.UserName == "Adrie");
            var account2 = mailConfig.Accounts.FirstOrDefault(x => x.UserName == "A3");

            account1.Should().NotBeNull();
            account1?.Server.Should().Be("mail.konfidence.nl");
            account1?.UserName.Should().Be("Adrie");
            account1?.Password.Should().Be("geheim");

            account2.Should().NotBeNull();
            account2?.Server.Should().Be("mail.konfidence.nl");
            account2?.UserName.Should().Be("A3");
            account2?.Password.Should().Be("geheim");
        }
Exemple #3
0
        public void ReadTest()
        {
            var configurationManager = new ClientSettingsManager(GetPluginManager());

            configurationManager.Read("..\\..\\TestFiles\\LegacyTest.hfm", 2);
            Assert.AreEqual("..\\..\\TestFiles\\LegacyTest.hfm", configurationManager.FileName);
            Assert.AreEqual(2, configurationManager.FilterIndex);
            Assert.AreEqual(".hfm", configurationManager.FileExtension);
        }
Exemple #4
0
        public void DefaultsTest()
        {
            var configurationManager = new ClientSettingsManager(GetPluginManager());

            Assert.AreEqual(String.Empty, configurationManager.FileName);
            Assert.AreEqual(1, configurationManager.FilterIndex);
            Assert.AreEqual(2, configurationManager.PluginCount);
            Assert.AreEqual("hfmx", configurationManager.FileExtension);
            Assert.AreEqual("HFM Configuration Files|*.hfmx|HFM Legacy Configuration Files|*.hfm", configurationManager.FileTypeFilters);
        }
        public MainPresenter(MainModel model, ILogger logger, IServiceScopeFactory serviceScopeFactory, MessageBoxPresenter messageBox,
                             ClientConfiguration clientConfiguration, IProteinService proteinService, EocStatsScheduledTask eocStatsScheduledTask)
            : base(model)
        {
            Model  = model;
            Logger = logger ?? NullLogger.Instance;
            ServiceScopeFactory = serviceScopeFactory ?? NullServiceScopeFactory.Instance;
            MessageBox          = messageBox ?? NullMessageBoxPresenter.Instance;
            ClientConfiguration = clientConfiguration;
            ProteinService      = proteinService ?? NullProteinService.Instance;

            UserStatsDataModel = new UserStatsDataModel(Form, Model.Preferences, eocStatsScheduledTask);
            Preferences        = Model.Preferences;
            GridModel          = new MainGridModel(Form, Model.Preferences, clientConfiguration);
            GridModel.Load();

            GridModel.AfterResetBindings += (s, e) =>
            {
                // Create a local reference before handing off to BeginInvoke.
                // This ensures that the BeginInvoke action uses the state of GridModel properties available now,
                // not the state of GridModel properties when the BeginInvoke action is executed (at a later time).
                var selectedSlot = GridModel.SelectedSlot;
                var slotTotals   = GridModel.SlotTotals;
                // run asynchronously so binding operation can finish
                Form.BeginInvoke(new Action(() =>
                {
                    Model.GridModelSelectedSlotChanged(selectedSlot);
                    Model.GridModelSlotTotalsChanged(slotTotals);
                }), null);
            };
            GridModel.PropertyChanged += (s, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(MainGridModel.SelectedSlot):
                    // Create a local reference before handing off to BeginInvoke.
                    // This ensures that the BeginInvoke action uses the state of GridModel properties available now,
                    // not the state of GridModel properties when the BeginInvoke action is executed (at a later time).
                    var selectedSlot = GridModel.SelectedSlot;
                    // run asynchronously so binding operation can finish
                    Form.BeginInvoke(new Action(() => Model.GridModelSelectedSlotChanged(selectedSlot)), null);
                    break;
                }
            };

            _settingsManager = new ClientSettingsManager(Logger);

            ClientConfiguration.ClientConfigurationChanged += (s, e) => AutoSaveConfig();
        }
Exemple #6
0
        public void WhenExecute_WithNoParameters_ShouldExitWith_4()
        {
            // arrange
            var errorExiterMock = new Mock <IErrorExiter>();

            // act
            var clientSettingsManager = new ClientSettingsManager(Array.Empty <string>(), errorExiterMock.Object);

            // assert
            errorExiterMock.Verify(x => x.Exit(4), Times.Once);

            clientSettingsManager.MailServer.Should().BeNullOrWhiteSpace();
            clientSettingsManager.Server.Should().BeNullOrWhiteSpace();

            clientSettingsManager.UserName.Should().BeNullOrWhiteSpace();
            clientSettingsManager.Password.Should().BeNullOrWhiteSpace();

            clientSettingsManager.ConfigFolder.Should().BeNullOrWhiteSpace();
            clientSettingsManager.ConfigFileName.Should().BeNullOrWhiteSpace();
        }
Exemple #7
0
        public void WhenExecute_WithConfigFolderAndMissingPassword_ShouldExitWith_3()
        {
            // arrange
            var errorExiterMock = new Mock <IErrorExiter>();

            // act
            var clientSettingsManager = new ClientSettingsManager(new[] { $"--{Argument.ConfigFileFolder}=.", $"--{Argument.UserName}=Adrie" }, errorExiterMock.Object);

            // assert
            errorExiterMock.Verify(x => x.Exit(3), Times.Once);

            clientSettingsManager.MailServer.Should().BeNullOrWhiteSpace();
            clientSettingsManager.Server.Should().BeNullOrWhiteSpace();

            clientSettingsManager.UserName.Should().Be(@"Adrie");
            clientSettingsManager.Password.Should().BeNullOrWhiteSpace();

            clientSettingsManager.ConfigFolder.Should().Be(@".");
            clientSettingsManager.ConfigFileName.Should().BeNullOrWhiteSpace();
        }
Exemple #8
0
        public void WhenExecute_WithCredentialsAndMissingConfigFolder_ShouldExitWith_1()
        {
            // arrange
            var errorExiterMock = new Mock <IErrorExiter>();

            // act
            var clientSettingsManager = new ClientSettingsManager(new[] { $"-{Argument.Server}=Server" }, errorExiterMock.Object);

            // assert
            errorExiterMock.Verify(x => x.Exit(1), Times.Once);

            clientSettingsManager.MailServer.Should().BeNullOrWhiteSpace();
            clientSettingsManager.Server.Should().BeNullOrWhiteSpace();

            clientSettingsManager.UserName.Should().BeNullOrWhiteSpace();
            clientSettingsManager.Password.Should().BeNullOrWhiteSpace();

            clientSettingsManager.ConfigFolder.Should().BeNullOrWhiteSpace();
            clientSettingsManager.ConfigFileName.Should().BeNullOrWhiteSpace();
        }
Exemple #9
0
        public void WriteTest()
        {
            var instance1 = new LegacyClient();

            instance1.Settings = new ClientSettings(ClientType.Legacy)
            {
                Name = "test"
            };

            const string testFile = "..\\..\\TestFiles\\new.ext";

            var configurationManager = new ClientSettingsManager(GetPluginManager());

            configurationManager.Write(new[] { instance1.Settings }, testFile, 1);
            Assert.AreEqual("..\\..\\TestFiles\\new.ext", configurationManager.FileName);
            Assert.AreEqual(1, configurationManager.FilterIndex);
            Assert.AreEqual(".ext", configurationManager.FileExtension);

            File.Delete(testFile);
        }