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); }
public void BeVirtualProperty() { // Arrange AimCategory category = new AimCategory(); // Act var isVirtual = category.GetType().GetProperty("Aims").GetAccessors()[0].IsVirtual; // Assert Assert.IsTrue(isVirtual); }
public void HaveGetterAndSetter() { // Arrange AimCategory category = new AimCategory(); // Act category.Name = "Category name"; // Assert StringAssert.AreEqualIgnoringCase("Category name", category.Name); }
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); }
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"]); }
public void AddAimCategory(AimCategory category) { this.data.AimCategories.Add(category); this.data.SaveChanges(); }