Пример #1
0
 public MainView()
 {
     InitializeComponent();
     InitializePresenter();
     InitializeLanguaje();
     BindControls();
     _presenter.BackupConfig(false);
 }
Пример #2
0
        public void BackupConfig_WhenShowSuccessIsTrue_ShouldShowSuccessMessage()
        {
            // arrange
            var mainViewMock      = new Mock <IMainView>();
            var modelMock         = new Mock <IHostManager>();
            var factoryMock       = new Mock <IViewFactory>();
            var mainPresenter     = new MainPresenter(mainViewMock.Object, factoryMock.Object, modelMock.Object);
            var configurationMock = new Mock <EConfiguration>();
            var systemConfigPath  = Path.Combine(Environment.SystemDirectory, "drivers\\etc\\hosts");

            modelMock.Setup(mm => mm.ReadExternalConfig(systemConfigPath)).Returns(configurationMock.Object).Verifiable();
            modelMock.Setup(mm => mm.HostsFilePath).Returns(systemConfigPath);
            configurationMock.Setup(cm => cm.Name).Returns("test");
            configurationMock.Setup(cm => cm.Content).Returns("test");
            configurationMock.Setup(cm => cm.Id).Returns(0);

            // act
            mainPresenter.BackupConfig(true);

            // assert
            configurationMock.VerifySet(cm => cm.Name = "Current", Times.Once);
            modelMock.Verify(mm => mm.AddConfig(configurationMock.Object), Times.Once);
            mainViewMock.Verify(
                mv => mv.ShowMessage(
                    MessageType.Info,
                    Language.Success_Tittle,
                    Language.BackupSuccess_Text),
                Times.Once);
        }
Пример #3
0
        public void BackupConfig_WhenUnexpectedExceptionThrown_ShouldDisplayErrorMessage()
        {
            // arrange
            var mainViewMock  = new Mock <IMainView>();
            var modelMock     = new Mock <IHostManager>();
            var factoryMock   = new Mock <IViewFactory>();
            var mainPresenter = new MainPresenter(mainViewMock.Object, factoryMock.Object, modelMock.Object);
            var exception     = new Exception("Unknown error");

            modelMock.Setup(mm => mm.ReadExternalConfig(It.IsAny <string>())).Throws(exception);


            // act
            mainPresenter.BackupConfig(false);

            // assert
            mainViewMock.Verify(
                mv => mv.ShowMessage(
                    MessageType.Error,
                    Language.UnexpectedError_Text,
                    string.Format(Language.BackupError_Text, exception.Message)),
                Times.Once);
        }
Пример #4
0
        public void BackupConfig_ShouldBackupCurrentSystemConfig()
        {
            // arrange
            var mainViewMock      = new Mock <IMainView>();
            var modelMock         = new Mock <IHostManager>();
            var factoryMock       = new Mock <IViewFactory>();
            var mainPresenter     = new MainPresenter(mainViewMock.Object, factoryMock.Object, modelMock.Object);
            var configurationMock = new Mock <EConfiguration>();
            var systemConfigPath  = Path.Combine(Environment.SystemDirectory, "drivers\\etc\\hosts");

            modelMock.Setup(mm => mm.ReadExternalConfig(systemConfigPath)).Returns(configurationMock.Object).Verifiable();
            modelMock.Setup(mm => mm.HostsFilePath).Returns(systemConfigPath);
            configurationMock.Setup(cm => cm.Name).Returns("test");
            configurationMock.Setup(cm => cm.Content).Returns("test");
            configurationMock.Setup(cm => cm.Id).Returns(0);

            // act
            mainPresenter.BackupConfig(false);

            // assert
            configurationMock.VerifySet(cm => cm.Name = "Current", Times.Once);
            modelMock.Setup(mm => mm.AddConfig(configurationMock.Object));
        }