public void SetsHttpResponseTo404()
        {
            //Arrange
            var mockedView = new Mock <IEditView>();

            mockedView.Setup(v => v.Model).Returns(new EditViewModel());
            var mockedPageService = new Mock <IPageService>();
            var mockedContentSubmissionService = new Mock <IContentSubmissionService>();
            var editPresenterUnderTest         = new EditPresenter(mockedView.Object, mockedPageService.Object, mockedContentSubmissionService.Object);

            mockedPageService.Setup(x => x.GetPageByTitle(It.IsAny <string>())).Returns((SotnWiki.Models.Page)null);
            var mockedHttpContext      = new Mock <HttpContextBase>();
            var mockedHttpResponseBase = new Mock <HttpResponseBase>();

            editPresenterUnderTest.HttpContext = mockedHttpContext.Object;
            mockedHttpContext.Setup(x => x.Response).Returns(mockedHttpResponseBase.Object);
            mockedHttpResponseBase.SetupSet(x => x.StatusCode = 404).Verifiable();
            mockedHttpResponseBase.SetupSet(x => x.Status     = "404 not found").Verifiable();

            //Act
            mockedView.Raise(v => v.OnPageGetContent += null, new PageEventArgs(""));

            //Assert
            mockedHttpResponseBase.Verify();
        }
Example #2
0
        /// <summary>
        /// Отображение вьюхи редактирования
        /// </summary>
        /// <param name="person">экз.редактируемого</param>
        /// <returns>true если пользователь нажал OK</returns>
        public bool GetChangedPerson(Person person)
        {
            if (person == null)
            {
                throw new ArgumentNullException(nameof(person));
            }

            var editView = new EditView();

            if (person.FirstName.Equals("<?>"))
            {
                editView.Text = "Создание новой записи...";
            }
            else
            {
                editView.Text = $"Редактирование: {person.FirstName} {person.LastName}";
            }

            editView.Owner         = _mainView;
            editView.StartPosition = FormStartPosition.CenterParent;

            var editPresenter = new EditPresenter(editView, person);

            return(editView.ShowDialog() == DialogResult.OK);
        }
Example #3
0
        private void InitializePresenter()
        {
            UnityContainer unityContainer = new UnityContainer();

            unityContainer.RegisterInstance <IEditView>(this);
            unityContainer.RegisterType <IHostManager, HostManagerFileDal>();
            _presenter = unityContainer.Resolve <EditPresenter>();
        }
Example #4
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            EditForm      editView  = new EditForm();
            EditPresenter presenter = new EditPresenter(editView);

            this.Hide();
            editView.ShowDialog();
            this.Show();
            eRefreshMenu(this, EventArgs.Empty);
        }
Example #5
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            Dialog.Window.SetBackgroundDrawable(new Android.Graphics.Drawables.ColorDrawable(Color.DarkGray));

            var view = inflater.Inflate(Resource.Layout.edit_fragment, container, false);

            ConnectionViews(view);
            presenter = new EditPresenter(this);
            return(view);
        }
Example #6
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
        }
Example #8
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);
        }
Example #9
0
        public void Cancel_ShouldCloseView()
        {
            // 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.Cancel();

            // assert
            _viewMock.VerifySet(vm => vm.DialogResult = DialogResult.Cancel);
            _viewMock.Verify(vm => vm.Close());
        }
Example #10
0
        public void AddUser()
        {
            usersRepository.Initialize();

            var view     = Substitute.For <IEditView>();
            var userName = "******";

            view.UserId.Returns(0);
            view.UserName.Returns(userName);
            view.UserAge.Returns(123);

            var presenter = new EditPresenter(view, usersRepository);

            view.AddUser();
            Assert.IsTrue(usersRepository.GetUsers().Count(u => u.Name == userName) == 1);
        }
Example #11
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);
        }
Example #12
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);
        }
Example #13
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);
        }
Example #14
0
        public void Cancel_WhenNoIsSelected_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(true);
            _viewMock.Setup(vm => vm.ShowMessage(It.IsAny <MessageType>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(DialogResult.No);
            // act
            presenter.Cancel();

            // assert
            _viewMock.VerifySet(vm => vm.DialogResult = DialogResult.Cancel, Times.Never);
            _viewMock.Verify(vm => vm.Close(), Times.Never);
        }
Example #15
0
        public void ShowUser()
        {
            var user = new User()
            {
                Id   = 10,
                Name = "TestUser",
                Age  = 321
            };

            var view      = Substitute.For <IEditView>();
            var presenter = new EditPresenter(view, usersRepository);

            presenter.Edit(user);

            Assert.AreEqual(view.UserId, user.Id);
            Assert.AreEqual(view.UserName, user.Name);
            Assert.AreEqual(view.UserAge, user.Age);
        }
Example #16
0
        public void Cancel_WhenChangesAreMade_ShouldShowAConfirmationMessage()
        {
            // 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.Cancel();

            // assert
            _viewMock.Verify(
                vm => vm.ShowMessage(
                    MessageType.YesNo,
                    Language.Warning_Tittle,
                    Language.EditCancel_Confirmation));
        }
Example #17
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);
        }
Example #18
0
        public void EditUser()
        {
            usersRepository.Initialize();

            var view = Substitute.For <IEditView>();
            var id   = 1;

            view.UserId.Returns(id);
            view.UserName.Returns("TestUser");
            view.UserAge.Returns(123);

            var presenter = new EditPresenter(view, usersRepository);

            view.EditUser();

            var user = usersRepository.GetUserById(id);

            Assert.IsTrue(user.Name == view.UserName && user.Age == view.UserAge);
        }
Example #19
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);
        }
Example #20
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));
        }
Example #21
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)));
        }
Example #22
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());
        }
        public void ActivatesResponseRedirect()
        {
            //Arrange
            var mockedView = new Mock <IEditView>();

            mockedView.Setup(v => v.Model).Returns(new EditViewModel());
            var mockedPageService = new Mock <IPageService>();
            var mockedContentSubmissionService = new Mock <IContentSubmissionService>();
            var editPresenterUnderTest         = new EditPresenter(mockedView.Object, mockedPageService.Object, mockedContentSubmissionService.Object);
            var mockedHttpContext      = new Mock <HttpContextBase>();
            var mockedHttpResponseBase = new Mock <HttpResponseBase>();

            editPresenterUnderTest.HttpContext = mockedHttpContext.Object;
            mockedHttpContext.Setup(x => x.Response).Returns(mockedHttpResponseBase.Object);
            mockedHttpResponseBase.Setup(x => x.Redirect(It.IsAny <string>())).Verifiable();

            //Act
            mockedView.Raise(v => v.OnSubmitPageEdit += null, new EditPageEventArgs("title", "content", false));

            //Assert
            mockedHttpResponseBase.Verify(x => x.Redirect(It.IsAny <string>()), Times.Once);
        }
        public void SetViewModelTitleCorrectly()
        {
            //Arrange
            var mockedView = new Mock <IEditView>();

            mockedView.Setup(v => v.Model).Returns(new EditViewModel());
            var    mockedPageService = new Mock <IPageService>();
            var    mockedContentSubmissionService = new Mock <IContentSubmissionService>();
            var    pagePresenterUnderTest         = new EditPresenter(mockedView.Object, mockedPageService.Object, mockedContentSubmissionService.Object);
            string expectedTitle = "page title";
            var    page          = new SotnWiki.Models.Page()
            {
                Title = expectedTitle
            };

            mockedPageService.Setup(x => x.GetPageByTitle(It.IsAny <string>())).Returns(page);

            //Act
            mockedView.Raise(v => v.OnPageGetContent += null, new PageEventArgs(""));

            //Assert
            Assert.AreEqual(expectedTitle, mockedView.Object.Model.Title);
        }
Example #25
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);
        }