public ActionResult CreateExpense(ExpenseFormViewModel expenseForm)
        {
            if (ModelState.IsValid)
            {
                ExpenseReport expenseReport = new ExpenseReport();

                expenseForm.ExpenseItem.AudAmount = currencyService.CalcAud(expenseForm.ExpenseItem.Amount, expenseForm.ExpenseItem.Currency);

                expenseForm.ExpenseItem.ReceiptFileName = fileUploader.Upload(expenseForm.ReceiptFile);

                //check if the session is valid if valid add new items to existing session else create a new report session
                if (Session["_expenseReport"] != null)
                {
                    expenseReport = (ExpenseReport)Session["_expenseReport"];
                    expenseReport.ExpenseItems.Add(expenseForm.ExpenseItem);
                    Session["_expenseReport"] = expenseReport;
                }
                else
                {
                    expenseReport.ExpenseItems.Add(expenseForm.ExpenseItem);
                    Session["_expenseReport"] = expenseReport;
                }

                expenseForm.ExpenseReport = expenseReport;
                expenseForm.ExpenseItem = new ExpenseItem();
                ModelState.Clear();

                return View("CreateExpense", expenseForm);
            }
            else
            {
                return PartialView(expenseForm);
            }
        }
        /// <summary>
        /// This controllers initializes the expense form
        /// </summary>
        /// <returns>returns create expense view</returns>
        public ActionResult CreateExpense()
        {
            ExpenseFormViewModel expenseForm = new ExpenseFormViewModel();
            ExpenseReport expenseReport = new ExpenseReport();

            expenseReport.CreateDate = DateTime.Now;
            expenseReport.CreatedBy = employee;
            expenseReport.Department = employee.Department;

            Session["_expenseReport"] = expenseReport;

            expenseForm.ExpenseReport = expenseReport;
            TempData["msg"] = "There are currently no expense items";
            return View("CreateExpense", expenseForm);
        }
        public void Consultant_CreateExpense_ViewData_ExpenseFormViewModal()
        {
            //Arrange
            ConsultantController controller = new ConsultantController(mockEmployeeService, mockReportService, mockEmployee);
            MockHttpContext.SetFakeHttpContext(controller);

            ExpenseFormViewModel model = new ExpenseFormViewModel();
            model.ExpenseItem = new ExpenseItem();
            ExpenseReport expenseReport = new ExpenseReport();

            expenseReport.CreateDate = DateTime.Now;
            expenseReport.CreatedBy = mockEmployee;
            expenseReport.Department = mockEmployee.Department;

            model.ExpenseReport = expenseReport;

            //Act
            var result = controller.CreateExpense(model) as ViewResult;

            //Assert
            Assert.AreEqual(model, (ExpenseFormViewModel)result.ViewData.Model, "The view model sent is not the same as what was intialized");
            Assert.IsNotNull((ExpenseFormViewModel)result.ViewData.Model, "The resulting view modal is null");
        }
        public void Consultant_HttpPost_CreateExpense_Returns_View_CreateExpense()
        {
            //Arrange
            const string expectedViewName = "CreateExpense";
            ExpenseFormViewModel expenseForm = new ExpenseFormViewModel();
            ConsultantController controller = new ConsultantController(mockEmployeeService, mockReportService, mockEmployee);
            MockHttpContext.SetFakeHttpContext(controller);

            expenseForm.CreateDate = DateTime.Now;
            expenseForm.DepartmentName = mockEmployee.Department.DepartmentName;
            expenseForm.EmployeeName = mockEmployee.Fullname;
            expenseForm.ExpenseItem = new ExpenseItem();

            //Act
            var result = controller.CreateExpense(expenseForm) as ViewResult;

            //Assert
            Assert.AreEqual(expectedViewName, result.ViewName, "View name should have been {0}", expectedViewName);
        }
        public void Consultant_HttpPost_CreateExpense_Returns_ActionResult()
        {
            //Arrange
            ExpenseFormViewModel expenseForm = new ExpenseFormViewModel();
            ConsultantController controller = new ConsultantController(mockEmployeeService, mockReportService, mockEmployee);
            MockHttpContext.SetFakeHttpContext(controller);

            expenseForm.CreateDate = DateTime.Now;
            expenseForm.DepartmentName = mockEmployee.Department.DepartmentName;
            expenseForm.EmployeeName = mockEmployee.Fullname;
            expenseForm.ExpenseItem = new ExpenseItem();

            //Act
            var result = controller.CreateExpense(expenseForm);

            //Assert
            Assert.IsInstanceOfType(result, typeof(ActionResult), "The result was not a type of ActionResult");
        }
        public void Consultant_HttpPost_CreateExpense_AddExpenseItem()
        {
            //Arrange
            ExpenseFormViewModel expenseForm = new ExpenseFormViewModel();
            ConsultantController controller = new ConsultantController(mockEmployeeService, mockReportService, mockEmployee);
            MockHttpContext.SetFakeHttpContext(controller);

            expenseForm.CreateDate = DateTime.Now;
            expenseForm.DepartmentName = mockEmployee.Department.DepartmentName;
            expenseForm.EmployeeName = mockEmployee.Fullname;

            expenseForm.ExpenseItem = new ExpenseItem();
            expenseForm.ExpenseItem.Description = "Laptop";
            expenseForm.ExpenseItem.Location = "Sydney Airport";
            expenseForm.ExpenseItem.Amount = (decimal)1200.00;
            expenseForm.ExpenseItem.AudAmount = (decimal)1200.00;
            expenseForm.ExpenseItem.Currency = "AUD";

            //Act
            ViewResult result = controller.CreateExpense(expenseForm) as ViewResult;
            ExpenseFormViewModel model = (ExpenseFormViewModel)result.ViewData.Model;

            //Assert
            Assert.AreEqual(model.ExpenseItem, expenseForm.ExpenseItem, "Expense items in view are not equal to expense item in the response");
            Assert.IsNotNull((ExpenseFormViewModel)result.ViewData.Model, "The resulting view modal is null");
        }