public void EditVocabularyPresenter_Loads_SelectedTerm_When_Term_Is_Selected()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();

            var editModel = new EditVocabularyModel {Term = new Term {TermId = Constants.TERM_ValidTermId}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, true);

            // Act
            mockView.Raise(v => v.SelectTerm += null, new TermsEventArgs(editModel.Term));

            // Assert
            Mock.Get(presenter.View).Verify(v => v.BindTerm(editModel.Term, It.IsAny<IEnumerable<Term>>(), presenter.IsHeirarchical, false, false));
        }
        public void EditVocabularyPresenter_Correctly_Sets_TermEditor_Mode_When_Term_Is_Selected()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();

            var editModel = new EditVocabularyModel {Term = new Term {TermId = Constants.TERM_ValidTermId}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, true);

            // Act
            mockView.Raise(v => v.SelectTerm += null, new TermsEventArgs(editModel.Term));

            // Assert
            mockView.Verify(v => v.SetTermEditorMode(false, Constants.TERM_ValidTermId));
        }
        public void EditVocabularyPresenter_SaveVocabulary_Saves_If_Vocabulary_Valid()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();
            var editModel = new EditVocabularyModel {Vocabulary = new Vocabulary {VocabularyId = Constants.VOCABULARY_UpdateVocabularyId, ScopeTypeId = 1}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, Constants.VOCABULARY_UpdateVocabularyId, true);

            // Act
            mockView.Raise(v => v.Save += null, EventArgs.Empty);

            // Assert
            Mock.Get(presenter.VocabularyController).Verify(r => r.UpdateVocabulary(It.Is<Vocabulary>(v => v.VocabularyId == Constants.VOCABULARY_UpdateVocabularyId)));
        }
        public void EditVocabularyPresenter_SaveVocabulary_Redirects_To_Vocabulary_List_View_With_No_Errors()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();
            var editModel = new EditVocabularyModel {Vocabulary = new Vocabulary {VocabularyId = Constants.VOCABULARY_UpdateVocabularyId, ScopeTypeId = 1}};
            mockView.Setup(v => v.Model).Returns(editModel);
            var destinationUrl = Globals.NavigateURL(Constants.TAB_ValidId);
            var mockHttpResponse = new Mock<HttpResponseBase>();

            EditVocabularyPresenter presenter = CreatePresenter(mockView, mockHttpResponse, Constants.VOCABULARY_UpdateVocabularyId, false);
            presenter.TabId = Constants.TAB_ValidId;

            mockView.Raise(v => v.Initialize += null, EventArgs.Empty);
            mockView.Raise(v => v.Load += null, EventArgs.Empty);

            // Act
            mockView.Raise(v => v.Save += null, EventArgs.Empty);

            // Assert
            mockHttpResponse.Verify(r => r.Redirect(destinationUrl));
        }
        public void EditVocabularyPresenter_SaveVocabulary_Validates_Vocabulary()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();
            var editModel = new EditVocabularyModel {Vocabulary = new Vocabulary {VocabularyId = Constants.VOCABULARY_UpdateVocabularyId, ScopeTypeId = 1}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, Constants.VOCABULARY_UpdateVocabularyId, true);

            Mock<ObjectValidator> mockValidator = MockHelper.EnableValidMockValidator(presenter.Validator, editModel.Vocabulary);

            // Act
            mockView.Raise(v => v.Save += null, EventArgs.Empty);

            // Assert
            mockValidator.Verify(v => v.ValidateObject(editModel.Vocabulary));
        }
        public void EditVocabularyPresenter_SaveVocabulary_Does_Not_Save_If_Vocabulary_Invalid()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();
            var editModel = new EditVocabularyModel {Vocabulary = new Vocabulary {VocabularyId = Constants.VOCABULARY_UpdateVocabularyId, ScopeTypeId = 1}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, Constants.VOCABULARY_UpdateVocabularyId, true);

            Mock<ObjectValidator> mockValidator = MockHelper.EnableInvalidMockValidator(presenter.Validator, editModel.Vocabulary);

            // Act
            mockView.Raise(v => v.Save += null, EventArgs.Empty);

            // Assert
            Mock.Get(presenter.VocabularyController).Verify(r => r.UpdateVocabulary(editModel.Vocabulary), Times.Never());
        }
        public void EditVocabularyPresenter_SaveTerm_Refreshes_Terms_List()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();
            var editModel = new EditVocabularyModel {Term = new Term {TermId = Constants.TERM_UpdateTermId}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, true);

            // Act
            mockView.Raise(v => v.SaveTerm += null, EventArgs.Empty);

            // Assert
            mockView.Verify(v => v.BindTerms(It.IsAny<IEnumerable<Term>>(), presenter.IsHeirarchical, true));
        }
        public void EditVocabularyPresenter_SaveTerm_Hides_Term_Editor()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();
            var editModel = new EditVocabularyModel {Term = new Term {TermId = Constants.TERM_UpdateTermId}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, true);

            // Act
            mockView.Raise(v => v.SaveTerm += null, EventArgs.Empty);

            // Assert
            mockView.Verify(v => v.ShowTermEditor(false));
        }
        public void EditVocabularyPresenter_SaveTerm_Updates_Term_If_Term_Valid()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();

            var editModel = new EditVocabularyModel {Term = new Term {TermId = Constants.TERM_UpdateTermId}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, true);

            // Act
            mockView.Raise(v => v.SaveTerm += null, EventArgs.Empty);

            // Assert
            Mock.Get(presenter.TermController).Verify(r => r.UpdateTerm(It.Is<Term>(t => t.TermId == Constants.TERM_UpdateTermId)));
        }
        public void EditVocabularyPresenter_SaveTerm_Adds_New_Term_If_TermId_Negative_1()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();

            var editModel = new EditVocabularyModel {Term = new Term()};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, true);

            // Act
            mockView.Raise(v => v.SaveTerm += null, EventArgs.Empty);

            // Assert
            Mock.Get(presenter.TermController).Verify(r => r.AddTerm(It.Is<Term>(t => t.TermId == Null.NullInteger)));
        }
        public void EditVocabularyPresenter_SaveTerm_Does_Not_Save_If_Term_Invalid()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();

            var editModel = new EditVocabularyModel {Term = new Term {TermId = Constants.TERM_UpdateTermId}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, true);

            Mock<ObjectValidator> mockValidator = MockHelper.EnableInvalidMockValidator(presenter.Validator, editModel.Term);

            // Act
            mockView.Raise(v => v.SaveTerm += null, EventArgs.Empty);

            // Assert
            Mock.Get(presenter.TermController).Verify(r => r.UpdateTerm(It.IsAny<Term>()), Times.Never());
        }
        public void EditVocabularyPresenter_SaveTerm_Validates_Term()
        {
            // Arrange
            var mockView = new Mock<IEditVocabularyView>();

            var editModel = new EditVocabularyModel {Term = new Term {TermId = Constants.TERM_UpdateTermId}};
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, true);

            Mock<ObjectValidator> mockValidator = MockHelper.EnableValidMockValidator(presenter.Validator, editModel.Term);

            // Act
            mockView.Raise(v => v.SaveTerm += null, EventArgs.Empty);

            // Assert
            mockValidator.Verify(v => v.ValidateObject(It.IsAny<Term>()));
        }
        public void EditVocabularyPresenter_OnLoad_Calls_View_BindVocabulary(bool isSuperUser, bool isSystem)
        {
            // Arrange
            Mock<IEditVocabularyView> mockView = new Mock<IEditVocabularyView>();
            EditVocabularyModel editModel = new EditVocabularyModel
                                                {
                                                    Vocabulary = new Vocabulary
                                                                     {
                                                                         VocabularyId = Constants.VOCABULARY_UpdateVocabularyId,
                                                                         ScopeTypeId = 1,
                                                                         IsSystem = isSystem // Set the IsSytem property
                                                                     }
                                                };
            mockView.Setup(v => v.Model).Returns(editModel);

            EditVocabularyPresenter presenter = CreatePresenter(mockView, false);
            presenter.IsSuperUser = isSuperUser;
            mockView.Raise(v => v.Initialize += null, EventArgs.Empty);

            // Act (Raise the Load Event)
            mockView.Raise(v => v.Load += null, EventArgs.Empty);

            // Assert
            mockView.Verify(v => v.BindVocabulary(It.Is<Vocabulary>(vm => vm.VocabularyId == Constants.VOCABULARY_UpdateVocabularyId), presenter.IsEditEnabled, presenter.IsDeleteEnabled, isSuperUser));
        }