public ActionResult Index(AddCategoryViewModel categoryModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View());
            }

            AimCategory newCategory = this.mapper.Map <AimCategory>(categoryModel);

            newCategory.Aims = new List <Aim>();

            try
            {
                this.categoryService.AddAimCategory(newCategory);
            }
            catch (Exception)
            {
                this.TempData.Add("Unique", "Duplicate element");
                return(this.View());
            }

            this.TempData.Add("Category", "Successfully added the category");

            return(this.Redirect($"/explore"));
        }
        public void InitializeAims_WhenCreated()
        {
            // Arrange
            AimCategory category = new AimCategory();

            // Act & Assert
            Assert.IsNotNull(category.Aims);
        }
        public void HaveGetterAndSetter()
        {
            // Arrange
            AimCategory category = new AimCategory();

            // Act
            category.Id = 2;

            // Assert
            Assert.AreEqual(2, category.Id);
        }
Example #4
0
        public void BeVirtualProperty()
        {
            // Arrange
            AimCategory category = new AimCategory();

            // Act
            var isVirtual = category.GetType().GetProperty("Aims").GetAccessors()[0].IsVirtual;

            // Assert
            Assert.IsTrue(isVirtual);
        }
Example #5
0
        public void HaveGetterAndSetter()
        {
            // Arrange
            AimCategory category = new AimCategory();

            // Act
            category.Name = "Category name";

            // Assert
            StringAssert.AreEqualIgnoringCase("Category name", category.Name);
        }
Example #6
0
        public void HaveGetterAndSetter()
        {
            // Arrange
            AimCategory category = new AimCategory();
            var         aims     = new List <Aim>()
            {
                new Mock <Aim>().Object, new Mock <Aim>().Object
            };

            // Act
            category.Aims = aims;

            // Assert
            CollectionAssert.AreEqual(aims, category.Aims);
        }
Example #7
0
        public void AddMessageToTempdata_WhenAdditionIsSuccessful()
        {
            // Arrange
            var submitModel = new AddCategoryViewModel();

            submitModel.Name = "someName";

            var mockedAimCategory = new AimCategory();

            this.mockedMapper.Setup(x => x.Map <AimCategory>(submitModel)).Returns(mockedAimCategory);

            // Act
            this.controller.Index(submitModel);

            // Assert
            Assert.AreEqual("Successfully added the category", this.controller.TempData["Category"]);
        }
Example #8
0
 public void AddAimCategory(AimCategory category)
 {
     this.data.AimCategories.Add(category);
     this.data.SaveChanges();
 }