Пример #1
0
        public void Save_CreateNewItem_ItemAddedToRepository()
        {
            // Arrange
            var mockStore = _MockStores.ItemRepositoryFake();
            var mockView = ItemViewFake(0);
            var presenter = new EditPresenter(mockView.Object);

            // Act
            presenter.ItemRepository = mockStore.Object;
            presenter.SettingsRepository = _MockStores.ModuleSettingsFake().Object;
            presenter.Save(null, null);

            // Assert
            Assert.IsTrue(mockStore.Object.GetItems(0).Count() == 1); //New item is added to the repository
        }
        public void Save_CreateNewItem_ItemAddedToRepository()
        {
            // Arrange
            var mockStore = _MockStores.ItemRepositoryFake();
            var mockView  = ItemViewFake(0);
            var presenter = new EditPresenter(mockView.Object);

            // Act
            presenter.ItemRepository     = mockStore.Object;
            presenter.SettingsRepository = _MockStores.ModuleSettingsFake().Object;
            presenter.Save(null, null);

            // Assert
            Assert.IsTrue(mockStore.Object.GetItems(0).Count() == 1); //New item is added to the repository
        }
Пример #3
0
        public void Save_WhenNewConfigModeIsOn_ShouldCheckIfAnotherConfigurationWithTheSameNameExists()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, "test", "Test");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();
            _viewMock.Setup(vm => vm.IsDirty).Returns(true);
            _viewMock.Setup(vm => vm.EditMode).Returns(EditMode.New);

            // act
            presenter.Save();

            // assert
            _modelMock.Verify(mm => mm.Exists(editedConfiguration), Times.Once);
        }
Пример #4
0
        public void Save_WhenConfigurationIsNotChanged_ShouldDoNothing()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, "test", "Test");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();
            _viewMock.Setup(vm => vm.IsDirty).Returns(false);

            // act
            presenter.Save();

            // assert
            _viewMock.Verify(vm => vm.Close());
            _modelMock.Verify(mm => mm.AddConfig(editedConfiguration), Times.Never);
        }
Пример #5
0
        public void Save_WhenNewConfig_ShouldSaveConfiguration()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, "test", "Test");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();
            _viewMock.Setup(vm => vm.IsDirty).Returns(true);
            _viewMock.Setup(vm => vm.EditMode).Returns(EditMode.New);
            _modelMock.Setup(mm => mm.Exists(editedConfiguration)).Returns(false);

            // act
            presenter.Save();

            // assert
            _modelMock.Verify(mm => mm.AddConfig(editedConfiguration), Times.Once);
        }
Пример #6
0
        public void Save_WhenConfigurationIsCorrectAndChangesAreMaded_ShouldSaveConfiguration()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, "test", "Test");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();
            _viewMock.Setup(vm => vm.IsDirty).Returns(true);

            // act
            presenter.Save();

            // assert
            _viewMock.VerifySet(vm => vm.DialogResult = DialogResult.OK);
            _viewMock.Verify(vm => vm.Close());
            _modelMock.Verify(mm => mm.AddConfig(editedConfiguration), Times.Once);
        }
Пример #7
0
        public void Save_WhenNameContainsIlegalCharacters_ShoulDisplayErrorMessage()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, ">?te<st", "test");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();

            // act
            presenter.Save();

            // assert
            _viewMock.Verify(
                vm => vm.ShowMessage(
                    MessageType.Error,
                    Language.Error_Data_Tittle,
                    Language.Error_InvalidNameFormat_Text),
                Times.Once);
        }
Пример #8
0
        public void Save_WhenContentIsEmpty_ShoulDisplayErrorMessage()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, "test", "");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();

            // act
            presenter.Save();

            // assert
            _viewMock.Verify(
                vm => vm.ShowMessage(
                    MessageType.Error,
                    Language.Error_Data_Tittle,
                    Language.Error_EmptyContent_Text),
                Times.Once);
        }
Пример #9
0
        public void Save_WhenNewConfigAnotherConfigExists_ShouldDisplayConfirmationMessage()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, "test", "Test");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();
            _viewMock.Setup(vm => vm.IsDirty).Returns(true);
            _viewMock.Setup(vm => vm.EditMode).Returns(EditMode.New);
            _modelMock.Setup(mm => mm.Exists(editedConfiguration)).Returns(true);

            // act
            presenter.Save();

            // assert
            _viewMock.Verify(
                vm => vm.ShowMessage(
                    MessageType.YesNo,
                    Language.OverwriteMessage_Tittle,
                    Language.OverWriteMessage_Text));
        }
Пример #10
0
        public void Save_WhenUnexpectedExceptionIsThrown_ShouldDisplayError()
        {
            // arrange
            var presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var editedConfiguration = new EConfiguration(0, "test", "Test");
            var exceptionToThrow    = new Exception("Unknown Error");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();
            _viewMock.Setup(vm => vm.IsDirty).Returns(true);
            _modelMock.Setup(mm => mm.AddConfig(editedConfiguration)).Throws(exceptionToThrow);

            // act
            presenter.Save();

            // assert
            _viewMock.Verify(
                vm => vm.ShowMessage(
                    MessageType.Error,
                    Language.UnexpectedError_Tittle,
                    string.Format(Language.UnexpectedError_Text, exceptionToThrow.Message)));
        }
Пример #11
0
        public void Save_WhenConfigurationIsSaved_ShouldDisplaySuccessMessage()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, "test", "Test");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();
            _viewMock.Setup(vm => vm.IsDirty).Returns(true);

            // act
            presenter.Save();

            // assert
            _viewMock.Verify(
                vm => vm.ShowMessage(
                    MessageType.Info,
                    Language.Success_Tittle,
                    Language.SuccessEdit_Text), Times.Once);
            _viewMock.VerifySet(vm => vm.DialogResult = DialogResult.OK);
            _viewMock.Verify(vm => vm.Close());
        }
Пример #12
0
        public void Save_WhenNewConfigYesSelected_ShouldSaveConfig()
        {
            // arrange
            EditPresenter presenter           = new EditPresenter(_viewMock.Object, _modelMock.Object);
            var           editedConfiguration = new EConfiguration(0, "test", "Test");

            _viewMock.Setup(vm => vm.Configuration).Returns(editedConfiguration).Verifiable();
            _viewMock.Setup(vm => vm.IsDirty).Returns(true);
            _viewMock.Setup(vm => vm.EditMode).Returns(EditMode.New);
            _modelMock.Setup(mm => mm.Exists(editedConfiguration)).Returns(true);
            _viewMock.Setup(
                vm => vm.ShowMessage(
                    MessageType.YesNo,
                    Language.OverwriteMessage_Tittle,
                    Language.OverWriteMessage_Text))
            .Returns(DialogResult.Yes);
            // act
            presenter.Save();

            // assert
            _modelMock.Verify(
                mm => mm.AddConfig(editedConfiguration), Times.Once);
        }
Пример #13
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     _presenter.Save();
 }