public void InsertNewcategory_WhenCategoryModelInputIsCorrect_ReturnSuccess() { CategoryModel input = new CategoryModel() { CategoryName = "Furniture", IsActive = true }; Category mockInput = new Category() { CategoryName = "Furniture", IsActive = true }; Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); mockCategories.Setup(x => x.InsertNewCategory(mockInput)).Returns(new Category() { Id = 1, CategoryName = "Furniture", IsActive = true, CreateDttm = DateTime.UtcNow, CreateUserName = "******", UpdateDttm = DateTime.UtcNow, UpdateUserName = "******" }); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.InsertNewCategory(input); Assert.AreEqual("Success", output.Message); }
public ActionResult ManageFeed(string search, int?page, int?categoryId) { try { //CategoryBusinessLayer CatBussLayer = new CategoryBusinessLayer(); //ViewBag.Categories = new SelectList(CatBussLayer.Get_Category, "Category_Id", "Category_Name"); ViewBag.SelectedItem = categoryId; CategoryBusinessLayer CatBussLayer = new CategoryBusinessLayer(); ViewBag.Categories = new SelectList(CatBussLayer.Get_Category(), "Category_Id", "Category_Name", "2"); //FeedBusinessLayer feedBusLayer = new FeedBusinessLayer(); //List<Feed> _feeds = feedBusLayer.GetEditFeeds.ToList(); //return View(_feeds.ToList()); if (categoryId != null) { if (categoryId == 1) { FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer(); List <Feed> feeds = FeedBusLayer.GetEditFeeds.ToList(); return(View(feeds.ToList().ToPagedList(page ?? 1, 8))); } else { FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer(); List <Feed> feeds = FeedBusLayer.GetEditFeeds.ToList(); return(View(feeds.Where(x => x.CategoryID == categoryId).ToList().ToPagedList(page ?? 1, 15))); } } else if (search == null) { FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer(); List <Feed> feeds = FeedBusLayer.GetEditFeeds.ToList(); return(View(feeds.ToList().ToPagedList(page ?? 1, 8))); } else { FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer(); List <Feed> feeds = FeedBusLayer.GetEditFeeds.ToList(); //return View(feeds.Where(x => x.Title.StartsWith(search)).ToList().ToPagedList(page ??5,1)); return(View(feeds.Where(x => x.Title.ToLowerInvariant().Contains(search) || search == null).ToList().ToPagedList(page ?? 1, 15))); } } catch (Exception ex) { TempData["AlertMessage"] = "Error"; string Module_name = "ManageFeed"; string Action = "ManageFeed_GetAllFeeds_index"; ErrorExceptionHandler _handler = new ErrorExceptionHandler(); _handler.ReportError(Module_name, ex.Message, Action); return(RedirectToAction("index", "Exception")); } }
public void UpdateCategoryDetail_WhenCategoryModelInputIsNull_ReturnsInputIsNullError() { CategoryUpdateModel input = null; Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.UpdateCategoryDetail(input); Assert.AreEqual("Input is null.", output); }
public void InsertNewCategory_WhenCategoryModelInputIsNull_ReturnInputIsNullError() { CategoryModel input = null; Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.InsertNewCategory(input); Assert.AreEqual("Input is null.", output.Message); }
public void DeleteCategory_WhenCategoryIdIsCorrect_ReturnsSuccess() { Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); mockCategories.Setup(x => x.DeleteCategory(It.IsAny <int>())).Returns("Category deleted."); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.DeleteCategory(It.IsAny <int>()); Assert.AreEqual("Category deleted.", output); }
public void DeleteCategory_WhenCategoryIdDoesNotExist_ReturnsIdShouldNotBeZero() { Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); mockCategories.Setup(x => x.DeleteCategory(It.IsAny <int>())).Returns("No record found."); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.DeleteCategory(It.IsAny <int>()); Assert.AreEqual("No record found.", output); }
public ActionResult Index(string search, int?page, int?categoryId) { try { ViewBag.SelectedItem = categoryId; CategoryBusinessLayer CatBussLayer = new CategoryBusinessLayer(); ViewBag.Categories = new SelectList(CatBussLayer.Get_Category(), "Category_Id", "Category_Name", "2"); if (categoryId != null) { if (categoryId == 1) { FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer(); List <Feed> feeds = FeedBusLayer.Feeds.ToList(); return(View(feeds.ToList().ToPagedList(page ?? 1, 15))); } else { FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer(); List <Feed> feeds = FeedBusLayer.Feeds.ToList(); return(View(feeds.Where(x => x.CategoryID == categoryId).ToList().ToPagedList(page ?? 1, 15))); } } else if (search == null) { FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer(); List <Feed> feeds = FeedBusLayer.Feeds.ToList(); return(View(feeds.ToList().ToPagedList(page ?? 1, 15))); } else { FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer(); List <Feed> feeds = FeedBusLayer.Feeds.ToList(); //return View(feeds.Where(x => x.Title.StartsWith(search)).ToList().ToPagedList(page ??5,1)); return(View(feeds.Where(x => x.Title.ToLowerInvariant().Contains(search.ToLower()) || search == null).ToList().ToPagedList(page ?? 1, 15))); } } catch (Exception ex) { string Module_name = "Home_index"; string Action = "Read all post"; ErrorExceptionHandler _handler = new ErrorExceptionHandler(); _handler.ReportError(Module_name, ex.Message, Action); return(RedirectToAction("index", "Exception")); } }
public void DeleteCategory_WhenCategoryIdInputIsZero_ReturnsIdShouldNotBeZero() { int input = 0; Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); mockCategories.Setup(x => x.DeleteCategory(input)).Returns("No record found."); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.DeleteCategory(input); Assert.AreEqual("No record found.", output); }
public void UpdateCategoryDetail_WhenCategoryNameIsNullOrEmpty_ReturnsCategoryNameIsBlankError() { CategoryUpdateModel input = new CategoryUpdateModel() { CategoryName = string.Empty, IsActive = true }; Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.UpdateCategoryDetail(input); Assert.AreEqual("Category Name should not be blank.", output); }
public void InsertNewCategory_WhenCategoryNameIsBlank_ReturnFieldIsBlankError() { CategoryModel input = new CategoryModel() { CategoryName = string.Empty, IsActive = true }; Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.InsertNewCategory(input); Assert.AreEqual("Category Name should not be blank.", output.Message); }
public ActionResult Create() { try { CategoryBusinessLayer CatBussLayer = new CategoryBusinessLayer(); ViewBag.Categories = new SelectList(CatBussLayer.Get_Category(), "Category_Id", "Category_Name"); return(View()); } catch (Exception ex) { string Module_name = "Create"; string Action = "Create_Get Request"; ErrorExceptionHandler _handler = new ErrorExceptionHandler(); _handler.ReportError(Module_name, ex.Message, Action); return(RedirectToAction("index", "Exception")); } }
public void UpdateCategoryDetail_WhenCategoryModelInputIsCorrect_ReturnsSuccess() { CategoryUpdateModel input = new CategoryUpdateModel() { Id = 1, CategoryName = "Furniture", IsActive = true }; Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); mockCategories.Setup(x => x.UpdateCategoryDetails(It.IsAny <Category>())).Returns("Category updated."); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.UpdateCategoryDetail(input); Assert.AreEqual("Category updated.", output); }
public void UpdateCategoryDetail_WhenCategoryIdDoesNotExist_ReturnsErrorCategoryNotFound() { CategoryUpdateModel input = new CategoryUpdateModel() { Id = 0, CategoryName = "Furniture", IsActive = true }; Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>(); mockCategories.Setup(x => x.UpdateCategoryDetails(It.IsAny <Category>())).Returns("No record found."); ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object); var output = app.UpdateCategoryDetail(input); Assert.AreEqual("No record found.", output); }
public void GetAllCategories_ReturnsAllCategories() { Mock <ICategoryDataAccess> categories = new Mock <ICategoryDataAccess>(); ICategoryBusinessLayer app = new CategoryBusinessLayer(categories.Object); List <Category> mockCategories = new List <Category> { new Category { Id = 1, CategoryName = "Hardware", IsActive = true, }, new Category { Id = 1, CategoryName = "Electrical", IsActive = true, }, new Category { Id = 1, CategoryName = "Industrial Tools", IsActive = true, }, new Category { Id = 1, CategoryName = "Auto Parts", IsActive = true, } }; categories.Setup(x => x.GetCategories()).Returns(mockCategories); var output = app.GetAllCategories(); Assert.IsNotNull(output); }