public void InventoryTransaction_OnPost_WithSessionNotNull_ExpectOk() { //Arrange String expectedView = "InventoryTransaction"; _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(string.Format("{0} {1}", "FName", "LName")); _transactionController.ControllerContext = _controllerContext.Object; TransactionSearchModel transactionSearchMl = new TransactionSearchModel { StartDateFrom = "2015-08-04 11:01:17", StartDateTo = "2016-02-02 11:01:17" }; SortingPagingInfo info = new SortingPagingInfo { SortField = Enums.TransactionSortField.LogicalDeviceId.ToString(), SortDirection = Constants.Ascending, }; //Act var actionResult = _transactionController.InventoryTransaction(transactionSearchMl, info, "Search") as ViewResult; //Assert Assert.IsNotNull(actionResult, "Temperature action result should not be null"); Assert.AreEqual(actionResult.ViewName, expectedView, "View name should be TemperatureHistory"); }
public ActionResult InventoryTransaction(TransactionSearchModel transactionSearchMl, SortingPagingInfo info, string command) { StringBuilder objStringBuilderError = new StringBuilder(); try { if (Session["UserName"] != null) { if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && !CheckDate(transactionSearchMl.StartDateFrom)) { transactionSearchMl.TransactionModels = null; Warning(JetstreamResource.FromDateValidation, true); ViewBag.SortingPagingInfo = info; return View("InventoryTransaction", transactionSearchMl); } if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && !CheckDate(transactionSearchMl.StartDateTo)) { transactionSearchMl.TransactionModels = null; Warning(JetstreamResource.ToDateValidation, true); ViewBag.SortingPagingInfo = info; return View("InventoryTransaction", transactionSearchMl); } DateTime? StartDateFrom = !string.IsNullOrEmpty(transactionSearchMl.StartDateFrom) ? Convert.ToDateTime(transactionSearchMl.StartDateFrom) : (DateTime?)null; DateTime? StartDateTo = !string.IsNullOrEmpty(transactionSearchMl.StartDateTo) ? Convert.ToDateTime(transactionSearchMl.StartDateTo) : (DateTime?)null; if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && StartDateFrom > StartDateTo) { transactionSearchMl.TransactionModels = null; Warning(JetstreamResource.DateValidation, true); ViewBag.SortingPagingInfo = info; return View("InventoryTransaction", transactionSearchMl); } using (JetstreamClient objMainServiceClient = new JetstreamClient()) { IEnumerable<TransactionModel> lstTransactionModel; lstTransactionModel = objMainServiceClient.GetInventoryTransaction(transactionSearchMl.SearchString, transactionSearchMl.StartDateFrom, transactionSearchMl.StartDateTo); lstTransactionModel.ToList().ForEach(x => { x.Location = x.Latitude + (x.Longitude != null ? string.Format(":{0}", x.Longitude) : x.Longitude) + (x.Range != null ? string.Format(":{0}", x.Range) : x.Range); }); if (lstTransactionModel.Any()) { transactionSearchMl.TransactionModels = ApplySorting(lstTransactionModel.ToList(), info).Take(Constants.PagingPageSize).ToList(); } } ViewBag.SortingPagingInfo = info; return View("InventoryTransaction", transactionSearchMl); } else { return RedirectToAction("UserLogin", "Login"); } } catch (FaultException<ServiceData> fex) { objStringBuilderError.AppendLine("In method : InventoryTransaction(TransactionSearchModel transactionSearchMl, SortingPagingInfo info, string command) :: TransactionController"); objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine); objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails); SaveLogger.SaveLoggerError(objStringBuilderError.ToString()); return View("Error"); } catch (Exception ex) { objStringBuilderError.AppendLine("In method : InventoryTransaction(TransactionSearchModel transactionSearchMl, SortingPagingInfo info, string command) :: TransactionController"); objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine); objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString()); SaveLogger.SaveLoggerError(objStringBuilderError.ToString()); return View("Error"); } }
/// <summary> /// Displays the view /// </summary> /// <returns></returns> public ActionResult InventoryTransaction() { StringBuilder objStringBuilderError = new StringBuilder(); TransactionSearchModel transactionSearchMl = new TransactionSearchModel(); try { if (Session["UserName"] != null) { using (JetstreamClient objMainServiceClient = new JetstreamClient()) { IEnumerable<TransactionModel> lstTransactionModel = objMainServiceClient.GetInventoryTransaction(transactionSearchMl.SearchString, transactionSearchMl.StartDateFrom, transactionSearchMl.StartDateTo); lstTransactionModel.ToList().ForEach(x => { x.Location = x.Latitude + (x.Longitude != null ? string.Format(":{0}", x.Longitude) : x.Longitude) + (x.Range != null ? string.Format(":{0}", x.Range) : x.Range); }); if (lstTransactionModel.Any()) { transactionSearchMl.TransactionModels = new List<TransactionModel>(lstTransactionModel); } } SortingPagingInfo info = new SortingPagingInfo { SortField = Enums.TransactionSortField.StateDate.ToString(), SortDirection = Constants.Ascending, }; if (transactionSearchMl.TransactionModels != null) transactionSearchMl.TransactionModels = ApplySorting(transactionSearchMl.TransactionModels, info).Take(Constants.PagingPageSize).ToList(); ViewBag.SortingPagingInfo = info; transactionSearchMl.StartDateFrom = string.Empty;// DateTime.Now.ToShortDateString(); transactionSearchMl.StartDateTo = string.Empty; //DateTime.Now.ToShortDateString(); return View("InventoryTransaction", transactionSearchMl); } else { return RedirectToAction("UserLogin", "Login"); } } catch (FaultException<ServiceData> fex) { objStringBuilderError.AppendLine("In method : InventoryTransaction() :: TransactionController"); objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine); objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails); SaveLogger.SaveLoggerError(objStringBuilderError.ToString()); return View("Error"); } catch (Exception ex) { objStringBuilderError.AppendLine("In method : InventoryTransaction() :: TransactionController"); objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine); objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString()); SaveLogger.SaveLoggerError(objStringBuilderError.ToString()); return View("Error"); } }
public void InventoryTransaction_OnPost_WithSessionIsNull_ExpectUserLogin() { //Arrange String expectedController = "Login"; String expectedAction = "UserLogin"; _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(null); _transactionController.ControllerContext = _controllerContext.Object; TransactionSearchModel transactionSearchMl = new TransactionSearchModel { StartDateFrom = "2015-08-04 11:01:17", StartDateTo = "2016-02-02 11:01:17" }; SortingPagingInfo info = new SortingPagingInfo { SortField = Enums.TransactionSortField.LogicalDeviceId.ToString(), SortDirection = Constants.Ascending, }; //Act var redirectToRouteResult = _transactionController.InventoryTransaction(transactionSearchMl, info, "Search") as RedirectToRouteResult; // Assert Assert.IsNotNull(redirectToRouteResult, "Not a redirect result"); Assert.IsFalse(redirectToRouteResult.Permanent); // Or IsTrue if you use RedirectToActionPermanent Assert.AreEqual(expectedAction, redirectToRouteResult.RouteValues["Action"]); Assert.AreEqual(expectedController, redirectToRouteResult.RouteValues["Controller"]); }