public void ScopeTypeController_AddScopeType_Throws_On_Null_ScopeType()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var scopeTypeController = new ScopeTypeController(mockDataService.Object);

            //Act, Arrange
            Assert.Throws<ArgumentNullException>(() => scopeTypeController.AddScopeType(null));
        }
Exemple #2
0
		/// <summary>
		/// Gets the scope type controller.
		/// </summary>
		/// <returns>ScopeTypeController from ComponentFactory.</returns>
        public static IScopeTypeController GetScopeTypeController()
        {
            var ctl = ComponentFactory.GetComponent<IScopeTypeController>();

            if (ctl == null)
            {
                ctl = new ScopeTypeController();
                ComponentFactory.RegisterComponentInstance<IScopeTypeController>(ctl);
            }
            return ctl;
        }
        public void ScopeTypeController_AddScopeType_Calls_DataService_On_Valid_Arguments()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);

            ScopeType scopeType = ContentTestHelper.CreateValidScopeType();

            //Act
            int scopeTypeId = scopeTypeController.AddScopeType(scopeType);

            //Assert
            mockDataService.Verify(ds => ds.AddScopeType(scopeType));
        }
        public void ScopeTypeController_AddScopeType_Returns_ValidId_On_Valid_ScopeType()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.AddScopeType(It.IsAny<ScopeType>()))
                .Returns(Constants.SCOPETYPE_AddScopeTypeId);
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);
            ScopeType scopeType = ContentTestHelper.CreateValidScopeType();

            //Act
            int scopeTypeId = scopeTypeController.AddScopeType(scopeType);

            //Assert
            Assert.AreEqual(Constants.SCOPETYPE_AddScopeTypeId, scopeTypeId);
        }
        public void BindVocabulary(Vocabulary vocabulary, bool editEnabled, bool showScope)
        {
            if (IsPostBack)
            {
                vocabulary.Name = nameTextBox.Text;
                vocabulary.Description = descriptionTextBox.Text;

                var scopeTypeController = new ScopeTypeController();
                ScopeType scopeType;
                scopeType = scopeTypeController.GetScopeTypes().Where(s => s.ScopeType == scopeList.SelectedValue).SingleOrDefault();
                vocabulary.ScopeTypeId = scopeType.ScopeTypeId;

                vocabulary.Type = typeList.SelectedValue == "Simple" ? VocabularyType.Simple : VocabularyType.Hierarchy;
            }
            else
            {
                nameTextBox.Text = vocabulary.Name;
                nameLabel.Text = vocabulary.Name;
                descriptionTextBox.Text = vocabulary.Description;
                typeList.Items.FindByValue(vocabulary.Type.ToString()).Selected = true;
                if (vocabulary.ScopeType != null)
                {
					scopeLabel.Text = Localization.GetString(vocabulary.ScopeType.ScopeType, LocalResourceFile);
                    scopeList.Items.FindByValue(vocabulary.ScopeType.ScopeType).Selected = true;
                }
                typeLabel.Text = vocabulary.Type.ToString();
            }

            nameTextBox.Visible = IsAddMode;
            nameLabel.Visible = !IsAddMode;
            descriptionTextBox.Enabled = editEnabled;
            divScope.Visible = (IsAddMode && showScope);
            scopeLabel.Visible = !(IsAddMode && showScope);
            typeList.Visible = IsAddMode;
            typeLabel.Visible = !IsAddMode;
        }
        public void ScopeTypeController_UpdateScopeType_Throws_On_Null_ScopeType()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);

            //Act, Arrange
            AutoTester.ArgumentNull<ScopeType>(scopeType => scopeTypeController.UpdateScopeType(scopeType));
        }
        public void ScopeTypeController_UpdateScopeType_Throws_On_Negative_ScopeTypeId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);

            ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
            scopeType.ScopeType = Constants.SCOPETYPE_InValidScopeType;

            Assert.Throws<ArgumentException>(() => scopeTypeController.UpdateScopeType(scopeType));
        }
        public void ScopeTypeController_UpdateScopeType_Calls_DataService_On_Valid_ContentType()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);

            ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
            scopeType.ScopeTypeId = Constants.SCOPETYPE_UpdateScopeTypeId;
            scopeType.ScopeType = Constants.SCOPETYPE_UpdateScopeType;

            //Act
            scopeTypeController.UpdateScopeType(scopeType);

            //Assert
            mockDataService.Verify(ds => ds.UpdateScopeType(scopeType));
        }
        public void ScopeTypeController_GetScopeTypes_Returns_List_Of_ScopeTypes()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetScopeTypes())
                .Returns(MockHelper.CreateValidScopeTypesReader(Constants.SCOPETYPE_ValidScopeTypeCount));
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);

            //Act
            IQueryable<ScopeType> scopeTypes = scopeTypeController.GetScopeTypes();

            //Assert
            Assert.AreEqual(Constants.SCOPETYPE_ValidScopeTypeCount, scopeTypes.Count());
        }
        public void ScopeTypeController_GetScopeTypes_Returns_Empty_List_Of_ScopeTypes_If_No_ScopeTypes()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetScopeTypes())
                .Returns(MockHelper.CreateEmptyScopeTypeReader());
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);

            //Act
            IQueryable<ScopeType> scopeTypes = scopeTypeController.GetScopeTypes();

            //Assert
            Assert.IsNotNull(scopeTypes);
            Assert.AreEqual(0, scopeTypes.Count());
        }
        public void ScopeTypeController_GetScopeTypes_Calls_DataService()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetScopeTypes())
                .Returns(MockHelper.CreateValidScopeTypesReader(Constants.SCOPETYPE_ValidScopeTypeCount));
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);

            //Act
            IQueryable<ScopeType> scopeTypes = scopeTypeController.GetScopeTypes();

            //Assert
            mockDataService.Verify(ds => ds.GetScopeTypes());
        }
        public void ScopeTypeController_DeleteScopeType_Throws_On_Negative_ScopeTypeId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            ScopeTypeController scopeTypeController = new ScopeTypeController(mockDataService.Object);

            ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
            scopeType.ScopeTypeId = Null.NullInteger;

            Assert.Throws<ArgumentException>(() => scopeTypeController.DeleteScopeType(scopeType));
        }